public void VisualStudioCodeCredentialOptionsNullTenantId() { var options = new VisualStudioCodeCredentialOptions(); // validate no exception is thrown when setting TenantId to null options.TenantId = null; }
public void VisualStudioCodeCredentialOptionsInvalidTenantId([Values("", "invalid?character")] string tenantId) { var options = new VisualStudioCodeCredentialOptions(); var ex = Assert.Catch <ArgumentException>(() => options.TenantId = tenantId); ValidateTenantIdArgumentException(tenantId, null, ex); }
public void AdfsTenantThrowsCredentialUnavailable() { var options = new VisualStudioCodeCredentialOptions { TenantId = "adfs", Transport = new MockTransport() }; VisualStudioCodeCredential credential = InstrumentClient(new VisualStudioCodeCredential(options)); Assert.ThrowsAsync <CredentialUnavailableException>(async() => await credential.GetTokenAsync(new TokenRequestContext(new[] { "https://vault.azure.net/.default" }), CancellationToken.None)); }
public void AdfsTenantThrowsCredentialUnavailable() { var options = new VisualStudioCodeCredentialOptions { TenantId = "adfs", Transport = new MockTransport() }; var context = new TokenRequestContext(new[] { Scope }); string expectedTenantId = TenantIdResolver.Resolve(null, context, options.AllowMultiTenantAuthentication); VisualStudioCodeCredential credential = InstrumentClient(new VisualStudioCodeCredential(options)); Assert.ThrowsAsync <CredentialUnavailableException>( async() => await credential.GetTokenAsync(new TokenRequestContext(new[] { "https://vault.azure.net/.default" }), CancellationToken.None)); }
public override TokenCredential GetTokenCredential(TokenCredentialOptions options) { using var env = new TestEnvVar(new Dictionary <string, string> { { "TENANT_ID", TenantId } }); var environment = new IdentityTestEnvironment(); var vscOptions = new VisualStudioCodeCredentialOptions { Diagnostics = { IsAccountIdentifierLoggingEnabled = options.Diagnostics.IsAccountIdentifierLoggingEnabled }, TenantId = environment.TenantId, Transport = new MockTransport() }; return(InstrumentClient( new VisualStudioCodeCredential( vscOptions, null, mockPublicMsalClient, CredentialTestHelpers.CreateFileSystemForVisualStudioCode(environment), new TestVscAdapter("VS Code Azure", "AzureCloud", expectedToken)))); }
public async Task AuthenticateWithVsCodeCredential([Values(null, TenantIdHint)] string tenantId, [Values(true)] bool allowMultiTenantAuthentication) { using var env = new TestEnvVar(new Dictionary<string, string> {{"TENANT_ID", TenantId}}); var environment = new IdentityTestEnvironment(); var options = new VisualStudioCodeCredentialOptions { TenantId = environment.TenantId, Transport = new MockTransport() }; var context = new TokenRequestContext(new[] { Scope }, tenantId: tenantId); expectedTenantId = TenantIdResolver.Resolve(environment.TenantId, context); VisualStudioCodeCredential credential = InstrumentClient( new VisualStudioCodeCredential( options, null, mockPublicMsalClient, CredentialTestHelpers.CreateFileSystemForVisualStudioCode(environment), new TestVscAdapter("VS Code Azure", "AzureCloud", expectedToken))); var actualToken = await credential.GetTokenAsync(context, CancellationToken.None); Assert.AreEqual(expectedToken, actualToken.Token, "Token should match"); Assert.AreEqual(expiresOn, actualToken.ExpiresOn, "expiresOn should match"); }