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 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 GetContainer_withLegalHoldAndImmutabilityPolicy() { if (isResourceMode) { string containerName = Utility.GenNameString("container"); //Creat container Test.Assert((CommandAgent as PowerShellAgent).InvokePSScript( string.Format("Get-AzureRMStorageAccount -ResourceGroupName {0} -Name {1} | New-AzureRmStorageContainer -ContainerName {2}", resourceGroupName, accountName, containerName)), string.Format("Create container for storage account {0} in the resource group {1} should success.", accountName, resourceGroupName)); PSContainer con = GetContainerFromServer(containerName); ValidateContainer(con, resourceGroupName, accountName, containerName, publicaccess: PSPublicAccess.None); //Set ImmutabilityPolicy int immutabilityPeriod = 5; Test.Assert((CommandAgent as PowerShellAgent).InvokePSScript( string.Format("Get-AzureRMStorageAccount -ResourceGroupName {0} -Name {1} | Set-AzureRmStorageContainerImmutabilityPolicy -ContainerName {2} -ImmutabilityPeriod {3}", resourceGroupName, accountName, containerName, immutabilityPeriod)), string.Format("Set Container ImmutabilityPolicy should success.")); Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success."); PSImmutabilityPolicy immuPolicy = GetImmutabilityPolicyFromOutput(); ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Unlocked"); //Lock ImmutabilityPolicy Test.Assert((CommandAgent as PowerShellAgent).InvokePSScript( string.Format("Get-AzureRmStorageContainer -ResourceGroupName {0} -StorageAccountName {1} -Name {2} | Lock-AzureRmStorageContainerImmutabilityPolicy -Etag '{3}' -Force", resourceGroupName, accountName, containerName, immuPolicy.Etag)), string.Format("Lock Container ImmutabilityPolicy should success.")); Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success."); immuPolicy = GetImmutabilityPolicyFromOutput(); ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod, "Locked"); //Extend ImmutabilityPolicy int immutabilityPeriod2 = 10; Test.Assert((CommandAgent as PowerShellAgent).InvokePSScript( string.Format("Get-AzureRmStorageContainerImmutabilityPolicy -ResourceGroupName {0} -StorageAccountName {1} -ContainerName {2} | Set-AzureRmStorageContainerImmutabilityPolicy -ImmutabilityPeriod {3} -ExtendPolicy", resourceGroupName, accountName, containerName, immutabilityPeriod2)), string.Format("Extend Container ImmutabilityPolicy should success.")); Test.Assert(CommandAgent.GetAzureRmStorageContainerImmutabilityPolicy(resourceGroupName, accountName, containerName), "Get Container ImmutabilityPolicy should success."); immuPolicy = GetImmutabilityPolicyFromOutput(); ValidateImmutabilityPolicy(immuPolicy, immutabilityPeriod2, "Locked"); //Add Container LegalHold string[] legalhold = new string[] { "legalholdtag1", "legalholdtag2" }; Test.Assert(CommandAgent.AddAzureRmStorageContainerLegalHold(resourceGroupName, accountName, containerName, legalhold), "Add Container LegalHold should success."); PSLegalHold outputLegalhold = GetLegalholdFromOutput(); CompareLegalhold(legalhold, outputLegalhold); //get Container and validate legalhold, ImmutabilityPolicy con = GetContainerFromServer(containerName); ValidateContainer(con, resourceGroupName, accountName, containerName, publicaccess: PSPublicAccess.None); Test.Assert(con.HasImmutabilityPolicy.Value, "Should has HasImmutabilityPolicy = true"); Test.Assert(con.HasLegalHold.Value, "Should has HasLegalHold = true"); Test.AssertEqual(immutabilityPeriod2, con.ImmutabilityPolicy.ImmutabilityPeriodSinceCreationInDays); Test.AssertEqual("Locked", con.ImmutabilityPolicy.State); Test.AssertEqual(3, con.ImmutabilityPolicy.UpdateHistory.Length); Test.AssertEqual("put", con.ImmutabilityPolicy.UpdateHistory[0].Update); Test.AssertEqual(immutabilityPeriod, con.ImmutabilityPolicy.UpdateHistory[0].ImmutabilityPeriodSinceCreationInDays.Value); Test.AssertEqual("lock", con.ImmutabilityPolicy.UpdateHistory[1].Update); Test.AssertEqual(immutabilityPeriod, con.ImmutabilityPolicy.UpdateHistory[1].ImmutabilityPeriodSinceCreationInDays.Value); Test.AssertEqual("extend", con.ImmutabilityPolicy.UpdateHistory[2].Update); Test.AssertEqual(immutabilityPeriod2, con.ImmutabilityPolicy.UpdateHistory[2].ImmutabilityPeriodSinceCreationInDays.Value); Test.AssertEqual(legalhold.Length, con.LegalHold.Tags.Length); if (legalhold.Length == con.LegalHold.Tags.Length) { for (int i = 0; i < legalhold.Length; i++) { Test.AssertEqual(legalhold[i], con.LegalHold.Tags[i].Tag); } } //Remove Legalhold and Container //Test.Assert(CommandAgent.RemoveAzureRmStorageContainerLegalHold(resourceGroupName, accountName, containerName, legalhold), "Remove Container LegalHold should success."); Test.Assert((CommandAgent as PowerShellAgent).InvokePSScript( string.Format("Get-AzureRMStorageAccount -ResourceGroupName {0} -Name {1} | Remove-AzureRmStorageContainerLegalHold -Name {2} -Tag {3}", resourceGroupName, accountName, containerName, legalhold[0] + "," + legalhold[1])), string.Format("Remove Container LegalHold should success.")); //outputLegalhold = GetLegalholdFromOutput(); //CompareLegalhold(null, outputLegalhold); //Test.Assert(CommandAgent.RemoveAzureRmStorageContainer(resourceGroupName, accountName, containerName), "Remove Container should success."); Test.Assert((CommandAgent as PowerShellAgent).InvokePSScript( string.Format("Get-AzureRmStorageContainer -ResourceGroupName {0} -StorageAccountName {1} -Name {2} | Remove-AzureRmStorageContainer -Force", resourceGroupName, accountName, containerName)), string.Format("Remove Container should success.")); } }