Ejemplo n.º 1
0
        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.");
            }
        }