public AdalConfiguration(WindowsAzureEnvironment environment)
     : this()
 {
     AdEndpoint = environment.ActiveDirectoryEndpoint != null ? environment.ActiveDirectoryEndpoint.TrimEnd('/') + '/' : null;
     AdDomain = environment.ActiveDirectoryCommonTenantId;
     ResourceClientUri = environment.ActiveDirectoryServiceEndpointResourceId;
 }
示例#2
0
        public void AddsAzureEnvironment()
        {
            Mock <ICommandRuntime>     commandRuntimeMock = new Mock <ICommandRuntime>();
            AddAzureEnvironmentCommand cmdlet             = new AddAzureEnvironmentCommand()
            {
                CommandRuntime         = commandRuntimeMock.Object,
                Name                   = "Katal",
                PublishSettingsFileUrl = "http://microsoft.com",
                ServiceEndpoint        = "endpoint.net",
                ManagementPortalUrl    = "management portal url",
                StorageEndpoint        = "endpoint.net"
            };

            cmdlet.ExecuteCmdlet();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <WindowsAzureEnvironment>()), Times.Once());
            WindowsAzureEnvironment env = GlobalSettingsManager.Instance.GetEnvironment("KaTaL");

            Assert.AreEqual(env.Name, cmdlet.Name);
            Assert.AreEqual(env.PublishSettingsFileUrl, cmdlet.PublishSettingsFileUrl);
            Assert.AreEqual(env.ServiceEndpoint, cmdlet.ServiceEndpoint);
            Assert.AreEqual(env.ManagementPortalUrl, cmdlet.ManagementPortalUrl);
            Assert.AreEqual(env.StorageBlobEndpointFormat, "{0}://{1}.blob.endpoint.net/");
            Assert.AreEqual(env.StorageQueueEndpointFormat, "{0}://{1}.queue.endpoint.net/");
            Assert.AreEqual(env.StorageTableEndpointFormat, "{0}://{1}.table.endpoint.net/");
        }
示例#3
0
        public void AddsEnvironmentWithStorageEndpoint()
        {
            Mock <ICommandRuntime>  commandRuntimeMock = new Mock <ICommandRuntime>();
            WindowsAzureEnvironment actual             = null;

            commandRuntimeMock.Setup(f => f.WriteObject(It.IsAny <object>()))
            .Callback((object output) => actual = (WindowsAzureEnvironment)output);
            AddAzureEnvironmentCommand cmdlet = new AddAzureEnvironmentCommand()
            {
                CommandRuntime         = commandRuntimeMock.Object,
                Name                   = "Katal",
                PublishSettingsFileUrl = "http://microsoft.com",
                StorageEndpoint        = "core.windows.net"
            };

            cmdlet.ExecuteCmdlet();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <WindowsAzureEnvironment>()), Times.Once());
            WindowsAzureEnvironment env = GlobalSettingsManager.Instance.GetEnvironment("KaTaL");

            Assert.AreEqual(env.Name, cmdlet.Name);
            Assert.AreEqual(env.PublishSettingsFileUrl, actual.PublishSettingsFileUrl);
            Assert.AreEqual(
                WindowsAzureEnvironmentConstants.AzureStorageBlobEndpointFormat,
                actual.StorageBlobEndpointFormat);
            Assert.AreEqual(
                WindowsAzureEnvironmentConstants.AzureStorageQueueEndpointFormat,
                actual.StorageQueueEndpointFormat);
            Assert.AreEqual(
                WindowsAzureEnvironmentConstants.AzureStorageTableEndpointFormat,
                actual.StorageTableEndpointFormat);
        }
示例#4
0
        public void SetsAzureEnvironment()
        {
            Mock <ICommandRuntime> commandRuntimeMock = new Mock <ICommandRuntime>();
            string name = "Katal";

            testProfile.AddEnvironment(new WindowsAzureEnvironment {
                Name = name, PublishSettingsFileUrl = "publish file url"
            });

            SetAzureEnvironmentCommand cmdlet = new SetAzureEnvironmentCommand()
            {
                CommandRuntime         = commandRuntimeMock.Object,
                Name                   = "KATaL",
                PublishSettingsFileUrl = "http://microsoft.com",
                ServiceEndpoint        = "endpoint.net",
                ManagementPortalUrl    = "management portal url",
                StorageEndpoint        = "endpoint.net",
                GalleryEndpoint        = "galleryendpoint"
            };

            cmdlet.ExecuteCmdlet();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <WindowsAzureEnvironment>()), Times.Once());
            WindowsAzureEnvironment env = WindowsAzureProfile.Instance.Environments["KaTaL"];

            Assert.AreEqual(env.Name.ToLower(), cmdlet.Name.ToLower());
            Assert.AreEqual(env.PublishSettingsFileUrl, cmdlet.PublishSettingsFileUrl);
            Assert.AreEqual(env.ServiceEndpoint, cmdlet.ServiceEndpoint);
            Assert.AreEqual(env.ManagementPortalUrl, cmdlet.ManagementPortalUrl);
            Assert.AreEqual(env.StorageBlobEndpointFormat, "{0}://{1}.blob.endpoint.net/");
            Assert.AreEqual(env.StorageQueueEndpointFormat, "{0}://{1}.queue.endpoint.net/");
            Assert.AreEqual(env.StorageTableEndpointFormat, "{0}://{1}.table.endpoint.net/");
            Assert.AreEqual(env.GalleryEndpoint, "galleryendpoint");
        }
        public AdalConfiguration(WindowsAzureEnvironment environment)
            : this()
        {
            AdEndpoint = environment.ActiveDirectoryEndpoint != null?environment.ActiveDirectoryEndpoint.TrimEnd('/') + '/' : null;

            AdDomain = environment.ActiveDirectoryCommonTenantId;
        }
示例#6
0
        public void AddsEnvironmentWithEmptyStorageEndpoint()
        {
            Mock <ICommandRuntime>  commandRuntimeMock = new Mock <ICommandRuntime>();
            WindowsAzureEnvironment actual             = null;

            commandRuntimeMock.Setup(f => f.WriteObject(It.IsAny <object>()))
            .Callback((object output) => actual = (WindowsAzureEnvironment)output);
            AddAzureEnvironmentCommand cmdlet = new AddAzureEnvironmentCommand()
            {
                CommandRuntime         = commandRuntimeMock.Object,
                Name                   = "Katal",
                PublishSettingsFileUrl = "http://microsoft.com",
                StorageEndpoint        = null
            };

            cmdlet.ExecuteCmdlet();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <WindowsAzureEnvironment>()), Times.Once());
            WindowsAzureEnvironment env = WindowsAzureProfile.Instance.Environments["KaTaL"];

            Assert.AreEqual(env.Name, cmdlet.Name);
            Assert.AreEqual(env.PublishSettingsFileUrl, actual.PublishSettingsFileUrl);
            Assert.IsTrue(string.IsNullOrEmpty(actual.StorageBlobEndpointFormat));
            Assert.IsTrue(string.IsNullOrEmpty(actual.StorageQueueEndpointFormat));
            Assert.IsTrue(string.IsNullOrEmpty(actual.StorageTableEndpointFormat));
        }
示例#7
0
        public override void ExecuteCmdlet()
        {
            WindowsAzureEnvironment env = ChosenEnvironment() ?? Profile.CurrentEnvironment;
            string accountName          = Profile.AddAccounts(env);

            WriteVerbose(string.Format(Resources.AddAccountAdded, accountName));
            WriteVerbose(string.Format(Resources.AddAccountShowDefaultSubscription, Profile.DefaultSubscription.SubscriptionName));
            WriteVerbose(Resources.AddAccountViewSubscriptions);
            WriteVerbose(Resources.AddAccountChangeSubscription);
        }
        public void GetsHttpsEndpointByDefault()
        {
            // Setup
            string accountName = "myaccount";
            string expected    = string.Format(
                WindowsAzureEnvironmentConstants.AzureStorageBlobEndpointFormat,
                "https",
                accountName);
            WindowsAzureEnvironment environment = WindowsAzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud];

            // Test
            Uri actual = environment.GetStorageBlobEndpoint(accountName);

            // Assert
            Assert.AreEqual(expected, actual.ToString());
        }
示例#9
0
        public override void ExecuteCmdlet()
        {
            var newEnvironment = new WindowsAzureEnvironment
            {
                Name = Name,
                PublishSettingsFileUrl        = PublishSettingsFileUrl,
                ServiceEndpoint               = ServiceEndpoint,
                ManagementPortalUrl           = ManagementPortalUrl,
                StorageEndpointSuffix         = StorageEndpoint,
                ActiveDirectoryEndpoint       = ActiveDirectoryEndpoint,
                ActiveDirectoryCommonTenantId = "Common"
            };

            WindowsAzureProfile.Instance.AddEnvironment(newEnvironment);
            WriteObject(newEnvironment);
        }
        public override void ExecuteCmdlet()
        {
            var newEnvironment = new WindowsAzureEnvironment
            {
                Name = Name,
                PublishSettingsFileUrl = PublishSettingsFileUrl,
                ServiceEndpoint = ServiceEndpoint,
                ManagementPortalUrl = ManagementPortalUrl,
                StorageEndpointSuffix = StorageEndpoint,
                ActiveDirectoryEndpoint = ActiveDirectoryEndpoint,
                ActiveDirectoryCommonTenantId = "Common"
            };

            WindowsAzureProfile.Instance.AddEnvironment(newEnvironment);
            WriteObject(newEnvironment);
        }
示例#11
0
        public void AddsEnvironmentWithMinimumInformation()
        {
            Mock <ICommandRuntime>     commandRuntimeMock = new Mock <ICommandRuntime>();
            AddAzureEnvironmentCommand cmdlet             = new AddAzureEnvironmentCommand()
            {
                CommandRuntime         = commandRuntimeMock.Object,
                Name                   = "Katal",
                PublishSettingsFileUrl = "http://microsoft.com"
            };

            cmdlet.ExecuteCmdlet();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <WindowsAzureEnvironment>()), Times.Once());
            WindowsAzureEnvironment env = WindowsAzureProfile.Instance.Environments["KaTaL"];

            Assert.AreEqual(env.Name, cmdlet.Name);
            Assert.AreEqual(env.PublishSettingsFileUrl, cmdlet.PublishSettingsFileUrl);
        }
        public void DefaultActiveDirectoryResourceUriIsSameWithServiceEndpoint()
        {
            WindowsAzureEnvironment environment = WindowsAzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud];

            //Assert
            Assert.AreEqual(true,
                            environment.ServiceEndpoint == environment.ActiveDirectoryServiceEndpointResourceId);

            //do same test for china cloud
            WindowsAzureEnvironment chinaEnvironment = WindowsAzureEnvironment.PublicEnvironments[EnvironmentName.AzureChinaCloud];

            Assert.AreEqual(true,
                            chinaEnvironment.ServiceEndpoint == chinaEnvironment.ActiveDirectoryServiceEndpointResourceId);

            //verify the resource uri are different between 2 environments
            Assert.AreNotEqual(environment.ActiveDirectoryServiceEndpointResourceId,
                               chinaEnvironment.ActiveDirectoryServiceEndpointResourceId);
        }
示例#13
0
        public void AddUserAgentTest()
        {
            WindowsAzureSubscription subscription = new WindowsAzureSubscription
            {
                Certificate      = It.IsAny <X509Certificate2>(),
                IsDefault        = true,
                ServiceEndpoint  = new Uri("https://www.azure.com"),
                SubscriptionId   = Guid.NewGuid().ToString(),
                SubscriptionName = Data.Subscription1,
            };

            WindowsAzureEnvironment environment        = WindowsAzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud];
            ClientMocks             clientMocks        = new ClientMocks(subscription.SubscriptionId);
            SubscriptionClient      subscriptionClient = clientMocks.SubscriptionClientMock.Object;
            SubscriptionClient      actual             = environment.AddUserAgent(subscriptionClient);

            // verify the UserAgent is set in the subscription client
            Assert.IsTrue(actual.UserAgent.Contains(ApiConstants.UserAgentValue), "Missing proper UserAgent string.");
        }
        /// <summary>
        /// Get storage account and use specific azure environment
        /// </summary>
        /// <param name="credential">Storage credentail</param>
        /// <param name="storageAccountName">Storage account name, it's used for build end point</param>
        /// <returns>A storage account</returns>
        internal CloudStorageAccount GetStorageAccountWithAzureEnvironment(StorageCredentials credential,
                                                                           string storageAccountName, bool useHttps, string azureEnvironmentName = "")
        {
            WindowsAzureEnvironment azureEnvironment = null;

            if (string.IsNullOrEmpty(azureEnvironmentName))
            {
                azureEnvironment = WindowsAzureProfile.Instance.CurrentEnvironment;
            }
            else
            {
                azureEnvironment = WindowsAzureProfile.Instance.Environments[azureEnvironmentName];
            }

            Uri blobEndPoint  = azureEnvironment.GetStorageBlobEndpoint(storageAccountName, useHttps);
            Uri queueEndPoint = azureEnvironment.GetStorageQueueEndpoint(storageAccountName, useHttps);
            Uri tableEndPoint = azureEnvironment.GetStorageTableEndpoint(storageAccountName, useHttps);

            return(new CloudStorageAccount(credential, blobEndPoint, queueEndPoint, tableEndPoint));
        }
 public IAccessToken GetNewToken(WindowsAzureEnvironment environment)
 {
     var config = new AdalConfiguration(environment);
     return new AdalAccessToken(AcquireToken(config), this, config);
 }
示例#16
0
        public IAccessToken GetNewToken(WindowsAzureEnvironment environment)
        {
            var config = new AdalConfiguration(environment);

            return(new AdalAccessToken(AcquireToken(config), this, config));
        }
 public IAccessToken GetNewToken(WindowsAzureEnvironment environment, string userId, SecureString password)
 {
     return this.accessToken;
 }
 public IAccessToken GetNewToken(WindowsAzureEnvironment environment)
 {
     return this.accessToken;
 }
 public IAccessToken GetNewToken(WindowsAzureEnvironment environment, string userId, SecureString password)
 {
     var config = new AdalConfiguration(environment);
     return new AdalAccessToken(AcquireToken(config, false, userId, password), this, config);
 }
 public AdalConfiguration(WindowsAzureEnvironment environment)
     : this()
 {
     AdEndpoint = environment.ActiveDirectoryEndpoint;
     AdDomain   = environment.ActiveDirectoryCommonTenantId;
 }
 public AdalConfiguration(WindowsAzureEnvironment environment)
     : this()
 {
     AdEndpoint = environment.ActiveDirectoryEndpoint;
     AdDomain = environment.ActiveDirectoryCommonTenantId;
 }
        public IAccessToken GetNewToken(WindowsAzureEnvironment environment, string userId, SecureString password)
        {
            var config = new AdalConfiguration(environment);

            return(new AdalAccessToken(AcquireToken(config, false, userId, password), this, config));
        }
示例#23
0
 public IAccessToken GetNewToken(WindowsAzureEnvironment environment)
 {
     return(this.accessToken);
 }
示例#24
0
 public IAccessToken GetNewToken(WindowsAzureEnvironment environment, string userId, SecureString password)
 {
     return(this.accessToken);
 }