Ejemplo n.º 1
0
        public void RespectsIsPIILoggingEnabled([Values(true, false)] bool isLoggingPIIEnabled)
        {
            var credential = new VisualStudioCodeCredential(new VisualStudioCodeCredentialOptions{ IsLoggingPIIEnabled = isLoggingPIIEnabled});

            Assert.NotNull(credential.Client);
            Assert.AreEqual(isLoggingPIIEnabled, credential.Client.IsPiiLoggingEnabled);
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        public async Task AuthenticateWithVscCredential_EmptySettingsFile()
        {
            var tenantId = GetTenantId();

            var refreshToken = await GetRefreshTokenAsync(tenantId);

            var fileSystemService = CreateTestFileSystemService();
            var vscAdapter        = new TestVscAdapter(ExpectedServiceName, "Azure", refreshToken);

            TokenCredentialOptions     options    = Recording.InstrumentClientOptions(new TokenCredentialOptions());
            VisualStudioCodeCredential credential = InstrumentClient(new VisualStudioCodeCredential(default, CredentialPipeline.GetInstance(options), fileSystemService, vscAdapter));
        public async Task AuthenticateWithVscCredential()
        {
            var cloudName = Guid.NewGuid().ToString();

            var fileSystem = CredentialTestHelpers.CreateFileSystemForVisualStudioCode(TestEnvironment, cloudName);

            using IDisposable fixture = await CredentialTestHelpers.CreateRefreshTokenFixtureAsync(TestEnvironment, Mode, ExpectedServiceName, cloudName);

            var options = InstrumentClientOptions(new VisualStudioCodeCredentialOptions {
                TenantId = TestEnvironment.TestTenantId
            });
            VisualStudioCodeCredential credential = InstrumentClient(new VisualStudioCodeCredential(options, default, default, fileSystem, default));
Ejemplo n.º 5
0
        [RunOnlyOnPlatforms(Windows = true, OSX = true)] // Comment this attribute to run this tests on Linux with Libsecret enabled
        public async Task AuthenticateWithVscCredential()
        {
            var tenantId  = GetTenantId();
            var cloudName = Guid.NewGuid().ToString();

            var fileSystem = CreateTestFileSystemService(cloudName: cloudName);

            using IDisposable fixture = await CreateRefreshTokenFixtureAsync(tenantId, cloudName);

            var options = Recording.InstrumentClientOptions(new VisualStudioCodeCredentialOptions {
                TenantId = tenantId
            });
            VisualStudioCodeCredential credential = InstrumentClient(new VisualStudioCodeCredential(options, default, default, fileSystem, default));
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        [RunOnlyOnPlatforms(Windows = true, OSX = true)] // Comment this attribute to run this tests on Linux with Libsecret enabled
        public async Task AuthenticateWithVscCredential()
        {
            var tenantId  = GetTenantId();
            var cloudName = Guid.NewGuid().ToString();

            var fileSystem = CreateTestFileSystemService(cloudName: cloudName);

            using IDisposable fixture = await CreateRefreshTokenFixtureAsync(tenantId, cloudName);

            TokenCredentialOptions     options    = Recording.InstrumentClientOptions(new TokenCredentialOptions());
            VisualStudioCodeCredential credential = InstrumentClient(new VisualStudioCodeCredential(tenantId, CredentialPipeline.GetInstance(options), fileSystem, default));
            AccessToken token = await credential.GetTokenAsync(new TokenRequestContext(new[] { ".default" }), CancellationToken.None);

            Assert.IsNotNull(token.Token);
        }
Ejemplo n.º 8
0
        public async Task AuthenticateWithVscCredential_BrokenSettingsFile()
        {
            var tenantId     = GetTenantId();
            var refreshToken = await GetRefreshTokenAsync(tenantId);

            var fileSystemService = new TestFileSystemService {
                ReadAllHandler = s => "{a,}"
            };
            var vscAdapter = new TestVscAdapter(ExpectedServiceName, "Azure", refreshToken);

            TokenCredentialOptions     options    = Recording.InstrumentClientOptions(new TokenCredentialOptions());
            VisualStudioCodeCredential credential = InstrumentClient(new VisualStudioCodeCredential(tenantId, CredentialPipeline.GetInstance(options), fileSystemService, vscAdapter));
            AccessToken token = await credential.GetTokenAsync(new TokenRequestContext(new[] { ".default" }), CancellationToken.None);

            Assert.IsNotNull(token.Token);
        }
Ejemplo n.º 9
0
        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");
        }