Exemplo n.º 1
0
        public void ValidateServiceEncrption(Encryption accountEncryption,
                                             Constants.EncryptionSupportServiceEnum enableEncryptionService,
                                             bool StorageEncryption  = false,
                                             bool keyvaultEncryption = false,
                                             string keyName          = null,
                                             string keyVersion       = null,
                                             string keyVaultUri      = null)
        {
            Test.Assert(accountEncryption.Services.Blob.Enabled.Value == true, "The Blob Encrption should be enabled.");
            Test.Assert(accountEncryption.Services.File.Enabled.Value == true, "The File Encrption should be enabled.");
            //if (enableEncryptionService == Constants.EncryptionSupportServiceEnum.None)
            //{
            //    Test.Assert(accountEncryption == null
            //        || accountEncryption.Services == null
            //        || (accountEncryption.Services.Blob == null && accountEncryption.Services.File == null)
            //        || (accountEncryption.Services.Blob.Enabled == null && accountEncryption.Services.File.Enabled == null)
            //        || (accountEncryption.Services.Blob.Enabled.Value == false && accountEncryption.Services.File.Enabled.Value == false), "The Blob and File Encrption should both be disabled.");
            //}
            //else
            //{
            //    //Check Blob Encryption
            //    if ((enableEncryptionService & Constants.EncryptionSupportServiceEnum.Blob) == Constants.EncryptionSupportServiceEnum.Blob)
            //    {
            //        Test.Assert(accountEncryption.Services.Blob.Enabled.Value == true, "The Blob Encrption should be enabled.");
            //    }
            //    else
            //    {
            //        Test.Assert(accountEncryption.Services.Blob == null
            //            || accountEncryption.Services.Blob.Enabled == null
            //            || accountEncryption.Services.Blob.Enabled.Value == false, "The Blob Encrption should be disabled.");
            //    }

            //    //Check File Encryption
            //    if ((enableEncryptionService & Constants.EncryptionSupportServiceEnum.File) == Constants.EncryptionSupportServiceEnum.File)
            //    {
            //        Test.Assert(accountEncryption.Services.File.Enabled.Value == true, "The File Encrption should be enabled.");
            //    }
            //    else
            //    {
            //        Test.Assert(accountEncryption.Services.File == null
            //            || accountEncryption.Services.File.Enabled == null
            //            || accountEncryption.Services.File.Enabled.Value == false, "The File Encrption should be disabled.");
            //    }
            //}
            if (StorageEncryption || keyvaultEncryption || keyName != null)
            {
                if (StorageEncryption)
                {
                    Test.Assert(accountEncryption == null || accountEncryption.KeySource == "Microsoft.Storage", "{0} = {1}", accountEncryption == null? null : accountEncryption.KeySource, "Microsoft.Storage");
                }
                else
                {
                    Test.Assert(accountEncryption.KeySource == "Microsoft.Keyvault", "{0} = {1}", accountEncryption.KeySource, "Microsoft.Keyvault");
                    Test.Assert(accountEncryption.KeyVaultProperties.KeyName == keyName, "{0} = {1}", accountEncryption.KeyVaultProperties.KeyName, keyName);
                    Test.Assert(accountEncryption.KeyVaultProperties.KeyVersion == keyVersion, "{0} = {1}", accountEncryption.KeyVaultProperties.KeyVersion, keyVersion);
                    Test.Assert(accountEncryption.KeyVaultProperties.KeyVaultUri == keyVaultUri, "{0} = {1}", accountEncryption.KeyVaultProperties.KeyVaultUri, keyVaultUri);
                }
            }
        }
Exemplo n.º 2
0
        public void ValidateSRPAccount(string resourceGroupName,
                                       string accountName,
                                       string location       = null,
                                       string skuName        = null,
                                       Hashtable[] tags      = null,
                                       Kind kind             = Kind.Storage,
                                       AccessTier?accessTier = null,
                                       string customDomain   = null,
                                       bool?useSubdomain     = null,
                                       Constants.EncryptionSupportServiceEnum enableEncryptionService = Constants.EncryptionSupportServiceEnum.Blob | Constants.EncryptionSupportServiceEnum.File,
                                       bool?enableHttpsTrafficOnly = null,
                                       bool AssignIdentity         = false,
                                       bool StorageEncryption      = false,
                                       bool keyvaultEncryption     = false,
                                       string keyName     = null,
                                       string keyVersion  = null,
                                       string keyVaultUri = null)
        {
            AzureOperationResponse <SRPModel.StorageAccount> response = this.SRPStorageClient.StorageAccounts.GetPropertiesWithHttpMessagesAsync(resourceGroupName, accountName).Result;

            Test.Assert(response.Response.StatusCode == HttpStatusCode.OK, string.Format("Account {0} should be created successfully.", accountName));

            SRPModel.StorageAccount account = response.Body;
            Test.Assert(accountName == account.Name, string.Format("Expected account name is {0} and actually it is {1}", accountName, account.Name));
            if (!string.IsNullOrEmpty(skuName))
            {
                Test.Assert(this.mapAccountType(Constants.AccountTypes[(int)account.Sku.Name]).Equals(skuName),
                            string.Format("Expected account type is {0} and actually it is {1}", skuName, account.Sku.Name));
            }
            if (!string.IsNullOrEmpty(location))
            {
                Test.Assert(location.Replace(" ", "").ToLower() == account.Location, string.Format("Expected location is {0} and actually it is {1}", location, account.Location));
            }
            Test.Assert(kind == account.Kind, string.Format("Kind should match: {0} == {1}", kind, account.Kind));

            //for StorageV2 account, will have default accesstier as cool
            if (kind == Kind.StorageV2 && accessTier == null)
            {
                accessTier = AccessTier.Cool;
            }
            Test.Assert(accessTier == account.AccessTier || (account.Kind == Kind.StorageV2 && account.AccessTier == AccessTier.Hot), string.Format("AccessTier should match: {0} == {1}", accessTier, account.AccessTier));

            if (customDomain == null)
            {
                Test.Assert(account.CustomDomain == null, string.Format("CustomDomain should match: {0} == {1}", customDomain, account.CustomDomain));
            }
            else
            {
                Test.Assert(customDomain == account.CustomDomain.Name, string.Format("CustomDomain should match: {0} == {1}", customDomain, account.CustomDomain.Name));

                // UseSubDomain is only for set, and won't be return in get
                Test.Assert(account.CustomDomain.UseSubDomain == null, string.Format("UseSubDomain should match: {0} == {1}", null, account.CustomDomain.UseSubDomain));
            }
            if (enableHttpsTrafficOnly != null)
            {
                Test.Assert(enableHttpsTrafficOnly == account.EnableHttpsTrafficOnly, string.Format("EnableHttpsTrafficOnly should match: {0} == {1}", enableHttpsTrafficOnly, account.EnableHttpsTrafficOnly));
            }
            if (AssignIdentity)
            {
                Test.Assert(account.Identity != null, string.Format("IdentityType should not be null: {0}, {1}", account.Identity.PrincipalId, account.Identity.TenantId));
            }

            this.ValidateTags(tags, account.Tags);
            ValidateServiceEncrption(account.Encryption, enableEncryptionService,
                                     StorageEncryption,
                                     keyvaultEncryption,
                                     keyName,
                                     keyVersion,
                                     keyVaultUri);
        }