Esempio n. 1
0
        internal void CreateStoredAccessPolicy(string policyName, string permission, DateTime?startTime, DateTime?expiryTime, CloudTable table, bool ifCleanUpPolicy = true)
        {
            if (ifCleanUpPolicy)
            {
                Utility.ClearStoredAccessPolicy <CloudTable>(table);
            }

            Test.Assert(CommandAgent.NewAzureStorageTableStoredAccessPolicy(table.Name, policyName, permission, startTime, expiryTime),
                        "Create stored access policy in table should succeed");
            Test.Info("Created stored access policy:{0}", policyName);
        }
Esempio n. 2
0
        internal void SetStoredAccessPolicyAndValidate(Utility.RawStoredAccessPolicy policy1, Utility.RawStoredAccessPolicy policy2, string tableName = null, bool ifCleanupPolicy = true, bool ifCleanupTable = true)
        {
            CloudTable table = tableUtil.CreateTable(tableName);

            if (ifCleanupPolicy)
            {
                Utility.ClearStoredAccessPolicy <CloudTable>(table);
            }

            policy2.PolicyName = policy1.PolicyName;

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

                //get the policy and validate
                SharedAccessTablePolicies expectedPolicies = new SharedAccessTablePolicies();
                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 <SharedAccessTablePolicy>(policy2.StartTime, policy2.ExpiryTime, policy2.Permission));
                Utility.WaitForPolicyBecomeValid <CloudTable>(table, policy2);
                Utility.ValidateStoredAccessPolicies <SharedAccessTablePolicy>(table.GetPermissions().SharedAccessPolicies, expectedPolicies);

                //validate the output
                SharedAccessTablePolicy policy = Utility.SetupSharedAccessPolicy <SharedAccessTablePolicy>(policy2.StartTime, policy2.ExpiryTime, policy2.Permission);
                Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> >();
                comp.Add(Utility.ConstructGetPolicyOutput <SharedAccessTablePolicy>(policy, policy2.PolicyName));
                CommandAgent.OutputValidation(comp);
            }
            finally
            {
                if (ifCleanupTable)
                {
                    tableUtil.RemoveTable(table);
                }
            }
        }
Esempio n. 3
0
        public void NewPolicyInvalidParameter()
        {
            DateTime?  startTime  = DateTime.Today.AddDays(1);
            DateTime?  expiryTime = DateTime.Today.AddDays(-1);
            CloudTable table      = tableUtil.CreateTable();

            Utility.ClearStoredAccessPolicy <CloudTable>(table);

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

                Test.Assert(!CommandAgent.NewAzureStorageTableStoredAccessPolicy(table.Name, Utility.GenNameString("p", 5), null, startTime, expiryTime), "Create 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.NewAzureStorageTableStoredAccessPolicy(table.Name, Utility.GenNameString("p", 5), null, startTime, startTime), "Create 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.NewAzureStorageTableStoredAccessPolicy(table.Name, Utility.GenNameString("p", 5), "x", null, null), "Create 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");
                }

                Test.Assert(!CommandAgent.NewAzureStorageTableStoredAccessPolicy(table.Name, FileNamingGenerator.GenerateValidASCIIOptionValue(65), null, null, null), "Create stored access policy with invalid name length should fail");
                if (lang == Language.PowerShell)
                {
                    ExpectedContainErrorMessage("Valid names should be 1 through 64 characters long.");
                }
                else
                {
                    ExpectedContainErrorMessage("XML specified is not syntactically valid");
                }

                for (int i = 1; i <= 5; i++)
                {
                    CommandAgent.NewAzureStorageTableStoredAccessPolicy(table.Name, Utility.GenNameString("p", i), null, null, null);
                }

                Test.Assert(!CommandAgent.NewAzureStorageTableStoredAccessPolicy(table.Name, Utility.GenNameString("p", 6), null, null, null), "Create more than 5 stored access policies should fail");
                if (lang == Language.PowerShell)
                {
                    ExpectedContainErrorMessage("Too many '6' shared access policy identifiers provided");
                }
                else
                {
                    ExpectedContainErrorMessage("A maximum of 5 access policies may be set");
                }

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