示例#1
0
        internal void CreateStoredAccessPolicyAndValidate(string policyName, string permission, DateTime?startTime, DateTime?expiryTime, string containerName = null, bool ifCleanUpContainer = true, bool ifCleanUpPolicy = true)
        {
            CloudBlobContainer container = blobUtil.CreateContainer(containerName);

            try
            {
                //create the policy
                CreateStoredAccessPolicy(policyName, permission, startTime, expiryTime, container, ifCleanUpPolicy);

                //get the policy and validate
                SharedAccessBlobPolicies expectedPolicies = new SharedAccessBlobPolicies();
                expectedPolicies.Add(policyName, Utility.SetupSharedAccessPolicy <SharedAccessBlobPolicy>(startTime, expiryTime, permission));

                Utility.RawStoredAccessPolicy policy = new Utility.RawStoredAccessPolicy(policyName, startTime, expiryTime, permission);
                Utility.WaitForPolicyBecomeValid <CloudBlobContainer>(container, policy);
                Utility.ValidateStoredAccessPolicies <SharedAccessBlobPolicy>(container.GetPermissions().SharedAccessPolicies, expectedPolicies);
            }
            finally
            {
                if (ifCleanUpPolicy)
                {
                    Utility.ClearStoredAccessPolicy <CloudBlobContainer>(container);
                }
                if (ifCleanUpContainer)
                {
                    blobUtil.RemoveContainer(container);
                }
            }
        }
示例#2
0
        public void SetPolicyDifferentNames()
        {
            DateTime?expiryTime1 = DateTime.Today.AddDays(10);
            DateTime?startTime1  = DateTime.Today.AddDays(-2);
            DateTime?expiryTime2 = DateTime.Today.AddDays(11);
            DateTime?startTime2  = DateTime.Today.AddDays(-1);
            string   permission  = Utility.GenFullPermissions(Constants.ResourceType.Container);
            string   policyName  = Utility.GenNameString("p", 0);

            Utility.RawStoredAccessPolicy policy1 = new Utility.RawStoredAccessPolicy(policyName, startTime1, expiryTime1, permission);
            Utility.RawStoredAccessPolicy policy2 = new Utility.RawStoredAccessPolicy(policyName, startTime2, expiryTime2, permission);
            SetStoredAccessPolicyAndValidate(policy1, policy2);

            policy1.PolicyName = policy2.PolicyName = Utility.GenNameString("p", 4);
            SetStoredAccessPolicyAndValidate(policy1, policy2);

            policy1.PolicyName = policy2.PolicyName = FileNamingGenerator.GenerateValidASCIIOptionValue(64);
            SetStoredAccessPolicyAndValidate(policy1, policy2);

            foreach (var samplePolicyName in FileNamingGenerator.GenerateValidateUnicodeName(40))
            {
                policy1.PolicyName = policy2.PolicyName = samplePolicyName;
                SetStoredAccessPolicyAndValidate(policy1, policy2);
            }

            SetStoredAccessPolicyAndValidate(policy1, policy2, "$root", true, false);
        }
示例#3
0
        public void RemovePolicyFromRoot()
        {
            CloudBlobContainer container = blobUtil.CreateContainer("$root");

            Utility.ClearStoredAccessPolicy <CloudBlobContainer>(container);
            Utility.RawStoredAccessPolicy samplePolicy = Utility.SetUpStoredAccessPolicyData <SharedAccessBlobPolicy>()[0];

            try
            {
                CreateStoredAccessPolicy(samplePolicy.PolicyName, samplePolicy.Permission, samplePolicy.StartTime, samplePolicy.ExpiryTime, container);

                Test.Assert(CommandAgent.RemoveAzureStorageContainerStoredAccessPolicy(container.Name, samplePolicy.PolicyName),
                            "Remove stored access policy in container should succeed");
                Test.Info("Remove stored access policy:{0}", samplePolicy.PolicyName);

                Utility.WaitForPolicyBecomeValid <CloudBlobContainer>(container, expectedCount: 0);

                int count = container.GetPermissions().SharedAccessPolicies.Count;
                Test.Assert(count == 0, string.Format("Policy should be removed. Current policy count is {0}", count));
            }
            finally
            {
                Utility.ClearStoredAccessPolicy <CloudBlobContainer>(container);
            }
        }
示例#4
0
        public void GetPolicyFromRoot()
        {
            CloudBlobContainer container = blobUtil.CreateContainer("$root");

            Utility.ClearStoredAccessPolicy <CloudBlobContainer>(container);
            Utility.RawStoredAccessPolicy samplePolicy = Utility.SetUpStoredAccessPolicyData <SharedAccessBlobPolicy>()[0];

            try
            {
                CreateStoredAccessPolicy(samplePolicy.PolicyName, samplePolicy.Permission, samplePolicy.StartTime, samplePolicy.ExpiryTime, container);

                Test.Assert(CommandAgent.GetAzureStorageContainerStoredAccessPolicy(container.Name, samplePolicy.PolicyName),
                            "Get stored access policy in container should succeed");
                Test.Info("Get stored access policy:{0}", samplePolicy.PolicyName);

                SharedAccessBlobPolicy policy = Utility.SetupSharedAccessPolicy <SharedAccessBlobPolicy>(samplePolicy.StartTime, samplePolicy.ExpiryTime, samplePolicy.Permission);
                Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> >();
                comp.Add(Utility.ConstructGetPolicyOutput <SharedAccessBlobPolicy>(policy, samplePolicy.PolicyName));
                CommandAgent.OutputValidation(comp);
            }
            finally
            {
                Utility.ClearStoredAccessPolicy <CloudBlobContainer>(container);
            }
        }
示例#5
0
        internal void CreateStoredAccessPolicyAndValidate(string policyName, string permission, DateTime?startTime, DateTime?expiryTime, string tableName = null, bool ifCleanUpTable = true, bool ifCleanUpPolicy = true)
        {
            CloudTable table = tableUtil.CreateTable(tableName);

            try
            {
                //create the policy
                CreateStoredAccessPolicy(policyName, permission, startTime, expiryTime, table, ifCleanUpPolicy);

                //get the policy and validate
                SharedAccessTablePolicies expectedPolicies = new SharedAccessTablePolicies();
                expectedPolicies.Add(policyName, Utility.SetupSharedAccessPolicy <SharedAccessTablePolicy>(startTime, expiryTime, permission));

                Utility.RawStoredAccessPolicy policy = new Utility.RawStoredAccessPolicy(policyName, startTime, expiryTime, permission);
                Utility.WaitForPolicyBecomeValid <CloudTable>(table, policy);
                Utility.ValidateStoredAccessPolicies <SharedAccessTablePolicy>(table.GetPermissions().SharedAccessPolicies, expectedPolicies);
            }
            finally
            {
                if (ifCleanUpPolicy)
                {
                    Utility.ClearStoredAccessPolicy <CloudTable>(table);
                }
                if (ifCleanUpTable)
                {
                    tableUtil.RemoveTable(table);
                }
            }
        }
示例#6
0
        public void SetPolicyNoStartTimeNoExpiryTime()
        {
            CloudBlobContainer container = blobUtil.CreateContainer();

            Utility.ClearStoredAccessPolicy <CloudBlobContainer>(container);
            Utility.RawStoredAccessPolicy samplePolicy = Utility.SetUpStoredAccessPolicyData <SharedAccessBlobPolicy>()[0];
            double effectiveTime = 30;

            try
            {
                CreateStoredAccessPolicy(samplePolicy.PolicyName, samplePolicy.Permission, samplePolicy.StartTime, samplePolicy.ExpiryTime, container);

                //NoStartTime
                Test.Assert(CommandAgent.SetAzureStorageContainerStoredAccessPolicy(container.Name, samplePolicy.PolicyName, null, null, null, true, false),
                            "Set stored access policy with -NoStartTime should succeed");
                Thread.Sleep(TimeSpan.FromSeconds(effectiveTime));
                SharedAccessBlobPolicies expectedPolicies = new SharedAccessBlobPolicies();
                expectedPolicies.Add(samplePolicy.PolicyName, Utility.SetupSharedAccessPolicy <SharedAccessBlobPolicy>(null, samplePolicy.ExpiryTime, samplePolicy.Permission));
                Utility.ValidateStoredAccessPolicies <SharedAccessBlobPolicy>(container.GetPermissions().SharedAccessPolicies, expectedPolicies);
                SharedAccessBlobPolicy policy = Utility.SetupSharedAccessPolicy <SharedAccessBlobPolicy>(null, samplePolicy.ExpiryTime, samplePolicy.Permission);
                Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> >();
                comp.Add(Utility.ConstructGetPolicyOutput <SharedAccessBlobPolicy>(policy, samplePolicy.PolicyName));
                CommandAgent.OutputValidation(comp);

                //NoExpiryTime
                Test.Assert(CommandAgent.SetAzureStorageContainerStoredAccessPolicy(container.Name, samplePolicy.PolicyName, null, null, null, false, true),
                            "Set stored access policy with -NoExpiryTime should succeed");
                Thread.Sleep(TimeSpan.FromSeconds(effectiveTime));
                expectedPolicies = new SharedAccessBlobPolicies();
                expectedPolicies.Add(samplePolicy.PolicyName, Utility.SetupSharedAccessPolicy <SharedAccessBlobPolicy>(null, null, samplePolicy.Permission));
                Utility.ValidateStoredAccessPolicies <SharedAccessBlobPolicy>(container.GetPermissions().SharedAccessPolicies, expectedPolicies);
                policy = Utility.SetupSharedAccessPolicy <SharedAccessBlobPolicy>(null, null, samplePolicy.Permission);
                comp   = new Collection <Dictionary <string, object> >();
                comp.Add(Utility.ConstructGetPolicyOutput <SharedAccessBlobPolicy>(policy, samplePolicy.PolicyName));
                CommandAgent.OutputValidation(comp);

                //both
                Utility.ClearStoredAccessPolicy <CloudBlobContainer>(container);
                CreateStoredAccessPolicy(samplePolicy.PolicyName, samplePolicy.Permission, samplePolicy.StartTime, samplePolicy.ExpiryTime, container);

                Test.Assert(CommandAgent.SetAzureStorageContainerStoredAccessPolicy(container.Name, samplePolicy.PolicyName, null, null, null, true, true),
                            "Set stored access policy with both -NoStartTime and -NoExpiryTime should succeed");
                Thread.Sleep(TimeSpan.FromSeconds(effectiveTime));
                expectedPolicies = new SharedAccessBlobPolicies();
                expectedPolicies.Add(samplePolicy.PolicyName, Utility.SetupSharedAccessPolicy <SharedAccessBlobPolicy>(null, null, samplePolicy.Permission));
                Utility.ValidateStoredAccessPolicies <SharedAccessBlobPolicy>(container.GetPermissions().SharedAccessPolicies, expectedPolicies);
                policy = Utility.SetupSharedAccessPolicy <SharedAccessBlobPolicy>(null, null, samplePolicy.Permission);
                comp   = new Collection <Dictionary <string, object> >();
                comp.Add(Utility.ConstructGetPolicyOutput <SharedAccessBlobPolicy>(policy, samplePolicy.PolicyName));
                CommandAgent.OutputValidation(comp);
            }
            finally
            {
                blobUtil.RemoveContainer(container);
            }
        }
示例#7
0
        internal void SetStoredAccessPolicyAndValidate(Utility.RawStoredAccessPolicy policy1, Utility.RawStoredAccessPolicy policy2, string containerName = null, bool ifCleanupPolicy = true, bool ifCleanupContainer = true)
        {
            CloudBlobContainer container = blobUtil.CreateContainer(containerName);

            if (ifCleanupPolicy)
            {
                Utility.ClearStoredAccessPolicy <CloudBlobContainer>(container);
            }

            policy2.PolicyName = policy1.PolicyName;

            try
            {
                CommandAgent.NewAzureStorageContainerStoredAccessPolicy(container.Name, policy1.PolicyName, policy1.Permission, policy1.StartTime, policy1.ExpiryTime);
                Test.Assert(CommandAgent.SetAzureStorageContainerStoredAccessPolicy(container.Name, policy2.PolicyName, policy2.Permission, policy2.StartTime, policy2.ExpiryTime),
                            "Set stored access policy in container should succeed");
                Test.Info("Set stored access policy:{0}", policy2.PolicyName);

                //get the policy and validate
                SharedAccessBlobPolicies expectedPolicies = new SharedAccessBlobPolicies();
                if (policy2.StartTime == null)
                {
                    policy2.StartTime = policy1.StartTime;
                }
                if (policy2.ExpiryTime == null)
                {
                    policy2.ExpiryTime = policy1.ExpiryTime;
                }
                if (policy2.Permission == null)
                {
                    policy2.Permission = policy1.Permission;
                }

                expectedPolicies.Add(policy2.PolicyName, Utility.SetupSharedAccessPolicy <SharedAccessBlobPolicy>(policy2.StartTime, policy2.ExpiryTime, policy2.Permission));
                Utility.WaitForPolicyBecomeValid <CloudBlobContainer>(container, policy2);
                Utility.ValidateStoredAccessPolicies <SharedAccessBlobPolicy>(container.GetPermissions().SharedAccessPolicies, expectedPolicies);

                //validate the output
                SharedAccessBlobPolicy policy = Utility.SetupSharedAccessPolicy <SharedAccessBlobPolicy>(policy2.StartTime, policy2.ExpiryTime, policy2.Permission);
                Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> >();
                comp.Add(Utility.ConstructGetPolicyOutput <SharedAccessBlobPolicy>(policy, policy2.PolicyName));
                CommandAgent.OutputValidation(comp);
            }
            finally
            {
                if (ifCleanupContainer)
                {
                    blobUtil.RemoveContainer(container);
                }
            }
        }
示例#8
0
        public void SetPolicyInvalidParameter()
        {
            DateTime?          startTime  = DateTime.Today.AddDays(1);
            DateTime?          expiryTime = DateTime.Today.AddDays(-1);
            CloudBlobContainer container  = blobUtil.CreateContainer();

            Utility.ClearStoredAccessPolicy <CloudBlobContainer>(container);

            try
            {
                Test.Assert(!CommandAgent.SetAzureStorageContainerStoredAccessPolicy("$logs", Utility.GenNameString("p", 5), null, null, null), "Set stored acess policy $logs container should fail");
                if (lang == Language.PowerShell)
                {
                    ExpectedContainErrorMessage("Can not find policy");
                }
                else
                {
                    ExpectedContainErrorMessage("doesn't exist");
                }

                Test.Assert(!CommandAgent.SetAzureStorageContainerStoredAccessPolicy("CONTAINER", Utility.GenNameString("p", 5), null, null, null), "Set stored acess policy for invalid container name CONTAINER should fail");
                if (lang == Language.PowerShell)
                {
                    ExpectedContainErrorMessage("The specifed resource name contains invalid characters.");
                }
                else
                {
                    ExpectedContainErrorMessage("Container name format is incorrect");
                }

                Utility.RawStoredAccessPolicy samplePolicy = Utility.SetUpStoredAccessPolicyData <SharedAccessBlobPolicy>()[0];
                CreateStoredAccessPolicy(samplePolicy.PolicyName, samplePolicy.Permission, samplePolicy.StartTime, samplePolicy.ExpiryTime, container);
                Test.Assert(!CommandAgent.SetAzureStorageContainerStoredAccessPolicy(container.Name, samplePolicy.PolicyName, null, startTime, expiryTime), "Set stored access policy for ExpiryTime earlier than StartTime should fail");
                ExpectedContainErrorMessage("The expiry time of the specified access policy should be greater than start time");

                Test.Assert(!CommandAgent.SetAzureStorageContainerStoredAccessPolicy(container.Name, samplePolicy.PolicyName, null, startTime, startTime), "Set stored access policy for ExpiryTime same as StartTime should fail");
                ExpectedContainErrorMessage("The expiry time of the specified access policy should be greater than start time");

                Test.Assert(!CommandAgent.SetAzureStorageContainerStoredAccessPolicy(container.Name, samplePolicy.PolicyName, "x", null, null), "Set stored access policy with invalid permission should fail");
                if (lang == Language.PowerShell)
                {
                    ExpectedContainErrorMessage("Invalid access permission");
                }
                else
                {
                    ExpectedContainErrorMessage("Given  \"x\" is invalid, supported values are: r, a, c, w, d, l");
                }

                string invalidName = FileNamingGenerator.GenerateValidASCIIOptionValue(65);
                Test.Assert(!CommandAgent.SetAzureStorageContainerStoredAccessPolicy(container.Name, invalidName, null, null, null), "Create stored access policy with invalid name length should fail");
                if (lang == Language.PowerShell)
                {
                    ExpectedContainErrorMessage("Can not find policy");
                }
                else
                {
                    ExpectedContainErrorMessage(string.Format("The policy {0} doesn't exist", invalidName));
                }

                if (lang == Language.PowerShell)
                {
                    Test.Assert(!CommandAgent.SetAzureStorageContainerStoredAccessPolicy(container.Name, samplePolicy.PolicyName, samplePolicy.Permission, samplePolicy.StartTime, null, true, false), "Setting both -StartTime and -NoStartTime should fail");
                    ExpectedContainErrorMessage("Parameter -StartTime and -NoStartTime are mutually exclusive");
                }
                else
                {
                    Test.Assert(CommandAgent.SetAzureStorageContainerStoredAccessPolicy(container.Name, samplePolicy.PolicyName, samplePolicy.Permission, samplePolicy.StartTime, null, true, false), "Setting both -StartTime and -NoStartTime should succeed");
                }

                if (lang == Language.PowerShell)
                {
                    Test.Assert(!CommandAgent.SetAzureStorageContainerStoredAccessPolicy(container.Name, samplePolicy.PolicyName, samplePolicy.Permission, null, samplePolicy.ExpiryTime, false, true), "Setting both -ExpiryTime and -NoExpiryTime should fail");
                    ExpectedContainErrorMessage("Parameter -ExpiryTime and -NoExpiryTime are mutually exclusive");
                }
                else
                {
                    Test.Assert(CommandAgent.SetAzureStorageContainerStoredAccessPolicy(container.Name, samplePolicy.PolicyName, samplePolicy.Permission, null, samplePolicy.ExpiryTime, false, true), "Setting both -ExpiryTime and -NoExpiryTime should succeed");
                }

                blobUtil.RemoveContainer(container);
                Test.Assert(!CommandAgent.SetAzureStorageContainerStoredAccessPolicy(container.Name, Utility.GenNameString("p", 5), null, null, null), "Set stored access policy against non-existing container should fail");
                if (lang == Language.PowerShell)
                {
                    ExpectedContainErrorMessage("does not exist");
                }
                else
                {
                    ExpectedContainErrorMessage("The specified container does not exist");
                }
            }
            finally
            {
                blobUtil.RemoveContainer(container);
            }
        }
示例#9
0
        public void SetPolicyInvalidParameter()
        {
            DateTime?  startTime  = DateTime.Today.AddDays(1);
            DateTime?  expiryTime = DateTime.Today.AddDays(-1);
            CloudTable table      = tableUtil.CreateTable();

            Utility.ClearStoredAccessPolicy <CloudTable>(table);

            try
            {
                Test.Assert(!CommandAgent.SetAzureStorageTableStoredAccessPolicy("CONTAINER", Utility.GenNameString("p", 5), null, null, null), "Set stored acess policy for invalid table name CONTAINER should fail");
                ExpectedContainErrorMessage("The table specified does not exist.");

                Utility.RawStoredAccessPolicy samplePolicy = Utility.SetUpStoredAccessPolicyData <SharedAccessTablePolicy>(lang == Language.NodeJS)[0];
                CreateStoredAccessPolicy(samplePolicy.PolicyName, samplePolicy.Permission, samplePolicy.StartTime, samplePolicy.ExpiryTime, table);
                Test.Assert(!CommandAgent.SetAzureStorageTableStoredAccessPolicy(table.Name, samplePolicy.PolicyName, null, startTime, expiryTime), "Set stored access policy for ExpiryTime earlier than StartTime should fail");
                ExpectedContainErrorMessage("The expiry time of the specified access policy should be greater than start time");

                Test.Assert(!CommandAgent.SetAzureStorageTableStoredAccessPolicy(table.Name, samplePolicy.PolicyName, null, startTime, startTime), "Set stored access policy for ExpiryTime same as StartTime should fail");
                ExpectedContainErrorMessage("The expiry time of the specified access policy should be greater than start time");

                Test.Assert(!CommandAgent.SetAzureStorageTableStoredAccessPolicy(table.Name, samplePolicy.PolicyName, "x", null, null), "Set stored access policy with invalid permission should fail");
                if (lang == Language.PowerShell)
                {
                    ExpectedContainErrorMessage("Invalid access permission");
                }
                else
                {
                    ExpectedContainErrorMessage("Given  \"x\" is invalid, supported values are: r, a, u, d");
                }

                string invalidName = FileNamingGenerator.GenerateValidASCIIOptionValue(65);
                Test.Assert(!CommandAgent.SetAzureStorageTableStoredAccessPolicy(table.Name, invalidName, null, null, null), "Create stored access policy with invalid name length should fail");
                if (lang == Language.PowerShell)
                {
                    ExpectedContainErrorMessage("Can not find policy");
                }
                else
                {
                    ExpectedContainErrorMessage(string.Format("The policy {0} doesn't exist", invalidName));
                }

                if (lang == Language.PowerShell)
                {
                    Test.Assert(!CommandAgent.SetAzureStorageTableStoredAccessPolicy(table.Name, samplePolicy.PolicyName, samplePolicy.Permission, samplePolicy.StartTime, null, true, false), "Setting both -StartTime and -NoStartTime should fail");
                    ExpectedContainErrorMessage("Parameter -StartTime and -NoStartTime are mutually exclusive");
                }
                else
                {
                    Test.Assert(CommandAgent.SetAzureStorageTableStoredAccessPolicy(table.Name, samplePolicy.PolicyName, samplePolicy.Permission, samplePolicy.StartTime, null, true, false), "Setting stored access policy without empty start time should succeed");
                }

                if (lang == Language.PowerShell)
                {
                    Test.Assert(!CommandAgent.SetAzureStorageTableStoredAccessPolicy(table.Name, samplePolicy.PolicyName, samplePolicy.Permission, null, samplePolicy.ExpiryTime, false, true), "Setting both -ExpiryTime and -NoExpiryTime should fail");
                    ExpectedContainErrorMessage("Parameter -ExpiryTime and -NoExpiryTime are mutually exclusive");
                }
                else
                {
                    Test.Assert(CommandAgent.SetAzureStorageTableStoredAccessPolicy(table.Name, samplePolicy.PolicyName, samplePolicy.Permission, null, samplePolicy.ExpiryTime, false, true), "Setting stored access policy without empty expiry time should succeed");
                }

                string nonexistTableName = Utility.GenNameString("table");
                tableUtil.RemoveTable(nonexistTableName);
                Test.Assert(!CommandAgent.SetAzureStorageTableStoredAccessPolicy(nonexistTableName, Utility.GenNameString("p", 5), null, null, null), "Set stored access policy against non-existing table should fail");
                ExpectedContainErrorMessage("does not exist");
            }
            finally
            {
                tableUtil.RemoveTable(table);
            }
        }