public void ListContainer() { if (isResourceMode) { string containerName = Utility.GenNameString("container"); PSContainer[] cons1 = ListContainersFromServer(); //Creat container Test.Assert(CommandAgent.NewAzureRmStorageContainer(resourceGroupName, accountName, containerName, PublicAccess: PSPublicAccess.Container), "Create Container should success."); PSContainer con = GetContainer(containerName); ValidateContainer(con, resourceGroupName, accountName, containerName, publicaccess: PSPublicAccess.Container); //get Container PSContainer[] cons2 = ListContainersFromServer(); Test.AssertEqual(cons1.Length + 1, cons2.Length); //Remove Container Test.Assert(CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Remove Container should success."); //get Container cons2 = ListContainersFromServer(); Test.AssertEqual(cons1.Length, cons2.Length); } }
public void UpdateContainer_allParameter() { if (isResourceMode) { string containerName = Utility.GenNameString("container"); Hashtable metadata = new Hashtable(2); metadata.Add("key1", "value1"); metadata.Add("key2", "value2"); // metadata.Add("key3", "value3"); //Creat container Test.Assert(CommandAgent.NewAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Create Container should success."); PSContainer con = GetContainer(containerName); ValidateContainer(con, resourceGroupName, accountName, containerName); //Set Container Test.Assert(CommandAgent.UpdateAzureRmStorageContainer(resourceGroupName, accountName, containerName, metadata, PSPublicAccess.Blob), "Update Container should success."); con = GetContainer(containerName); ValidateContainer(con, resourceGroupName, accountName, containerName, metadata, PSPublicAccess.Blob); //Set Container Test.Assert(CommandAgent.UpdateAzureRmStorageContainer(resourceGroupName, accountName, containerName, new Hashtable(), PSPublicAccess.None), "Update Container should success."); con = GetContainer(containerName); ValidateContainer(con, resourceGroupName, accountName, containerName); //Remove Container Test.Assert(CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Remove Container should success."); } }
public void ImmutabilityPolicy_LockExtend() { if (isResourceMode) { string containerName = Utility.GenNameString("container"); int immutabilityPeriod = 5; //Creat container Test.Assert(CommandAgent.NewAzureRmStorageContainer(resourceGroupName, accountName, containerName, PublicAccess: PSPublicAccess.None), "Create Container should success."); PSContainer con = GetContainer(containerName); ValidateContainer(con, resourceGroupName, accountName, containerName, publicaccess: PSPublicAccess.None); //Set ImmutabilityPolicy Test.Assert(CommandAgent.SetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName, immutabilityPeriod), "Set Container ImmutabilityPolicy should success."); PSImmutabilityPolicy immuPolicy = GetImmutabilityPolicyFromOutput(); ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Unlocked"); //Lock ImmutabilityPolicy Test.Assert(CommandAgent.LockAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName, immuPolicy.Etag), "Lock Container ImmutabilityPolicy should success."); immuPolicy = GetImmutabilityPolicyFromOutput(); ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Locked"); //Get ImmutabilityPolicy Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success."); immuPolicy = GetImmutabilityPolicyFromOutput(); ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Locked"); //Set ImmutabilityPolicy fail Test.Assert(!CommandAgent.SetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName, 2, Etag: immuPolicy.Etag), "Set Container ImmutabilityPolicy should fail."); ExpectedContainErrorMessage(string.Format("Operation not allowed on immutability policy with current state.")); //Extend ImmutabilityPolicy immutabilityPeriod = 10; Test.Assert(CommandAgent.SetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName, immutabilityPeriod, extendPolicy: true, Etag: immuPolicy.Etag), "Extend Container ImmutabilityPolicy should success."); immuPolicy = GetImmutabilityPolicyFromOutput(); ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Locked"); //Get ImmutabilityPolicy Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success."); immuPolicy = GetImmutabilityPolicyFromOutput(); ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Locked"); //Remove ImmutabilityPolicy fail Test.Assert(!CommandAgent.RemoveAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName, immuPolicy.Etag), "Remove Container ImmutabilityPolicy should fail."); ExpectedContainErrorMessage(string.Format("Operation not allowed on immutability policy with current state.")); //Remove Container Test.Assert(CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Remove Container should success."); } }
public void CreateContainer_allParameter() { if (isResourceMode) { string containerName = Utility.GenNameString("container"); //Hashtable[] metadata = StorageAccountTest.GetUnicodeTags(); Hashtable metadata = new Hashtable(2); metadata.Add("key1", "value1"); metadata.Add("key2", "value2"); //metadata.Add("key3", "value3"); Test.Assert(CommandAgent.NewAzureRmStorageContainer(resourceGroupName, accountName, containerName, metadata, PublicAccess: PSPublicAccess.Container), "Create Container should success."); PSContainer con = GetContainer(containerName); ValidateContainer(con, resourceGroupName, accountName, containerName, metadata, PSPublicAccess.Container); CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName); } }
public void ImmutabilityPolicy_SetGetDelete() { if (isResourceMode) { string containerName = Utility.GenNameString("container"); int immutabilityPeriod = 3; //Creat container Test.Assert(CommandAgent.NewAzureRmStorageContainer(resourceGroupName, accountName, containerName, PublicAccess: PSPublicAccess.Blob), "Create Container should success."); PSContainer con = GetContainer(containerName); ValidateContainer(con, resourceGroupName, accountName, containerName, publicaccess: PSPublicAccess.Blob); //Get ImmutabilityPolicy Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success."); PSImmutabilityPolicy immuPolicy = GetImmutabilityPolicyFromOutput(); ValidateImmutabilityPolicy(immuPolicy, 0, "Unlocked"); //Set ImmutabilityPolicy Test.Assert(CommandAgent.SetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName, immutabilityPeriod), "Set Container ImmutabilityPolicy should success."); immuPolicy = GetImmutabilityPolicyFromOutput(); ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Unlocked"); //Get ImmutabilityPolicy Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success."); immuPolicy = GetImmutabilityPolicyFromOutput(); ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Unlocked"); //Remove ImmutabilityPolicy Test.Assert(CommandAgent.RemoveAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName, immuPolicy.Etag), "Remove Container ImmutabilityPolicy should success."); Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success."); immuPolicy = GetImmutabilityPolicyFromOutput(); ValidateImmutabilityPolicy(immuPolicy, 0, "Deleted"); //Remove Container Test.Assert(CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Remove Container should success."); } }
public void LegalHoldTest() { if (isResourceMode) { string containerName = Utility.GenNameString("container"); string[] legalhold = new string[] { "tag1", "tag2", "tag3", "tag4" }; string[] legalhold2Remove = new string[] { "tag2", "tag3" }; string[] legalholdLeft = new string[] { "tag1", "tag4" }; //Creat container Test.Assert(CommandAgent.NewAzureRmStorageContainer(resourceGroupName, accountName, containerName, PublicAccess: PSPublicAccess.Container), "Create Container should success."); PSContainer con = GetContainer(containerName); ValidateContainer(con, resourceGroupName, accountName, containerName, publicaccess: PSPublicAccess.Container); //Add Container LegalHold Test.Assert(CommandAgent.AddAzureRmStorageContainerLegalHold(resourceGroupName, accountName, containerName, legalhold), "Add Container LegalHold should success."); PSLegalHold outputLegalhold = GetLegalholdFromOutput(); CompareLegalhold(legalhold, outputLegalhold); //Remove Container LegalHold Test.Assert(CommandAgent.RemoveAzureRmStorageContainerLegalHold(resourceGroupName, accountName, containerName, legalhold2Remove), "Remove Container LegalHold should success."); outputLegalhold = GetLegalholdFromOutput(); CompareLegalhold(legalholdLeft, outputLegalhold); //Remove Container fail when legalhold exist Test.Assert(!CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Remove Container with legalhold should fail."); ExpectedContainErrorMessage(string.Format("The storage account {0} container {1} is protected from deletion due to LegalHold.", accountName, containerName)); //Remove Container LegalHold Test.Assert(CommandAgent.RemoveAzureRmStorageContainerLegalHold(resourceGroupName, accountName, containerName, legalholdLeft), "Remove Container LegalHold should success."); outputLegalhold = GetLegalholdFromOutput(); CompareLegalhold(null, outputLegalhold); //Remove container Test.Assert(CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Remove Container should success."); } }