상속: IAuthenticationFactory
        public void VerifySubscriptionTokenCacheRemove()
        {
            var authFactory = new AuthenticationFactory
            {
                TokenProvider = new MockAccessTokenProvider("testtoken", "testuser")
            };

            var subscriptionId = Guid.NewGuid();

            var credential = authFactory.GetSubscriptionCloudCredentials(new AzureContext(
                new AzureSubscription
                {
                    Id = subscriptionId,
                    Properties = new Dictionary<AzureSubscription.Property, string>
                    {
                        { AzureSubscription.Property.Tenants, "123"}
                    }
                },
                new AzureAccount
                {
                    Id = "testuser",
                    Type = AzureAccount.AccountType.User,
                    Properties = new Dictionary<AzureAccount.Property, string>
                    {
                        { AzureAccount.Property.Tenants, "123" }
                    }
                },
                AzureEnvironment.PublicEnvironments["AzureCloud"]
                
            ));

            Assert.True(credential is AccessTokenCredential);
            Assert.Equal(subscriptionId, new Guid(((AccessTokenCredential)credential).SubscriptionId));

        }
예제 #2
0
        public void VerifyUserAgentValuesAreTransmitted()
        {
            var storedClientFactory = AzureSession.ClientFactory;
            var storedAuthFactory = AzureSession.AuthenticationFactory;
            try
            {
                var authFactory = new AuthenticationFactory();
                authFactory.TokenProvider = new MockAccessTokenProvider(Guid.NewGuid().ToString(), "*****@*****.**");
                AzureSession.AuthenticationFactory = authFactory;
                var factory = new ClientFactory();
                AzureSession.ClientFactory = factory;
                factory.UserAgents.Clear();
                factory.AddUserAgent("agent1");
                factory.AddUserAgent("agent1", "1.0.0");
                factory.AddUserAgent("agent1", "1.0.0");
                factory.AddUserAgent("agent1", "1.9.8");
                factory.AddUserAgent("agent2");
                Assert.Equal(4, factory.UserAgents.Count);
                var client = factory.CreateClient<NullClient>(new AzureContext(
                    new AzureSubscription
                    {
                        Id = Guid.NewGuid(),
                        Properties = new Dictionary<AzureSubscription.Property, string>
                        {
                            {AzureSubscription.Property.Tenants, "123"}
                        }
                    },
                    new AzureAccount
                    {
                        Id = "*****@*****.**",
                        Type = AzureAccount.AccountType.User,
                        Properties = new Dictionary<AzureAccount.Property, string>
                        {
                            {AzureAccount.Property.Tenants, "123"}
                        }
                    },
                    AzureEnvironment.PublicEnvironments["AzureCloud"]

                    ), AzureEnvironment.Endpoint.ResourceManager);
                Assert.Equal(5, client.HttpClient.DefaultRequestHeaders.UserAgent.Count);
                Assert.True(client.HttpClient.DefaultRequestHeaders.UserAgent.Contains(new ProductInfoHeaderValue("agent1", "")));
                Assert.True(client.HttpClient.DefaultRequestHeaders.UserAgent.Contains(new ProductInfoHeaderValue("agent1", "1.0.0")));
                Assert.True(client.HttpClient.DefaultRequestHeaders.UserAgent.Contains(new ProductInfoHeaderValue("agent1", "1.9.8")));
                Assert.True(client.HttpClient.DefaultRequestHeaders.UserAgent.Contains(new ProductInfoHeaderValue("agent2", "")));
            }
            finally
            {
                AzureSession.ClientFactory = storedClientFactory;
                AzureSession.AuthenticationFactory = storedAuthFactory;
            }
        }
예제 #3
0
 static AzureSession()
 {
     ClientFactory = new ClientFactory();
     AuthenticationFactory = new AuthenticationFactory();
     DataStore = new MemoryDataStore();
     TokenCache = new TokenCache();
     OldProfileFile = "WindowsAzureProfile.xml";
     OldProfileFileBackup = "WindowsAzureProfile.xml.bak";
     ProfileDirectory = Path.Combine(
         Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
         Resources.AzureDirectoryName); ;
     ProfileFile = "AzureProfile.json";
     TokenCacheFile = "TokenCache.dat";
 }
       public void VerifyValidateAuthorityFalseForOnPremise()
        {
            var authFactory = new AuthenticationFactory
            {
                TokenProvider = new MockAccessTokenProvider("testtoken", "testuser")
            };

            var subscriptionId = Guid.NewGuid();
            var context = new AzureContext
            (
                new AzureSubscription
                {
                    Id = subscriptionId,
                    Properties = new Dictionary<AzureSubscription.Property, string>
                    {
                        { AzureSubscription.Property.Tenants, "123"}
                    }
                },
                new AzureAccount
                {
                    Id = "testuser",
                    Type = AzureAccount.AccountType.User,
                    Properties = new Dictionary<AzureAccount.Property, string>
                    {
                        { AzureAccount.Property.Tenants, "123" }
                    }
                },
                new AzureEnvironment
                {
                    Name = "Katal",
                    OnPremise = true,
                    Endpoints = new Dictionary<AzureEnvironment.Endpoint, string>
                    {
                        { AzureEnvironment.Endpoint.ActiveDirectory, "http://ad.com" },
                        { AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId, "http://adresource.com" }
                    }
                }
            );

            var credential = authFactory.Authenticate(context.Account, context.Environment, "common", null, ShowDialog.Always);
           
            Assert.False(((MockAccessTokenProvider)authFactory.TokenProvider).AdalConfiguration.ValidateAuthority);            
        }