Exemplo n.º 1
0
        public void GetPolicyVariations()
        {
            CloudTable table = tableUtil.CreateTable();

            Utility.ClearStoredAccessPolicy <CloudTable>(table);

            try
            {
                //empty policies
                Test.Assert(CommandAgent.GetAzureStorageTableStoredAccessPolicy(table.Name, null),
                            "Get stored access policy in table should succeed");
                Test.Info("Get stored access policy");
                if (lang == Language.PowerShell)
                {
                    Assert.IsTrue(CommandAgent.Output.Count == 0);
                }
                else
                {
                    Assert.IsTrue(CommandAgent.Output[0].Count == 0);
                }

                //get all policies
                List <Utility.RawStoredAccessPolicy>      samplePolicies = Utility.SetUpStoredAccessPolicyData <SharedAccessTablePolicy>(lang == Language.NodeJS);
                Collection <Dictionary <string, object> > comp           = new Collection <Dictionary <string, object> >();
                foreach (Utility.RawStoredAccessPolicy samplePolicy in samplePolicies)
                {
                    CreateStoredAccessPolicy(samplePolicy.PolicyName, samplePolicy.Permission, samplePolicy.StartTime, samplePolicy.ExpiryTime, table, false);
                    SharedAccessTablePolicy policy = Utility.SetupSharedAccessPolicy <SharedAccessTablePolicy>(samplePolicy.StartTime, samplePolicy.ExpiryTime, samplePolicy.Permission);
                    comp.Add(Utility.ConstructGetPolicyOutput <SharedAccessTablePolicy>(policy, samplePolicy.PolicyName));
                }

                Test.Assert(CommandAgent.GetAzureStorageTableStoredAccessPolicy(table.Name, null),
                            "Get stored access policy in table should succeed");
                Test.Info("Get stored access policy");
                if (lang == Language.PowerShell)
                {
                    CommandAgent.OutputValidation(comp);
                }
                else
                {
                    Test.Assert(comp.Count == CommandAgent.Output[0].Count, "Comparison size: {0} = {1} Output size", comp.Count, CommandAgent.Output[0].Count);
                }
            }
            finally
            {
                tableUtil.RemoveTable(table);
            }
        }
Exemplo n.º 2
0
        public void GetPolicyInvalid()
        {
            CloudTable table = tableUtil.CreateTable();

            Utility.ClearStoredAccessPolicy <CloudTable>(table);

            try
            {
                string policyName = "policy";
                Test.Assert(!CommandAgent.GetAzureStorageTableStoredAccessPolicy(table.Name, policyName),
                            "Get non-existing stored access policy should fail");
                if (lang == Language.PowerShell)
                {
                    ExpectedContainErrorMessage("Can not find policy");
                }
                else
                {
                    ExpectedContainErrorMessage(string.Format("The policy {0} doesn't exist", policyName));
                }

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

                Test.Assert(!CommandAgent.GetAzureStorageTableStoredAccessPolicy("CONTAINER", policyName),
                            "Get stored access policy from invalid table name should fail");
                ExpectedContainErrorMessage("The table specified does not exist.");

                string nonexistTableName = Utility.GenNameString("table");
                tableUtil.RemoveTable(nonexistTableName);
                Test.Assert(!CommandAgent.GetAzureStorageTableStoredAccessPolicy(nonexistTableName, policyName),
                            "Get stored access policy from invalid table name should fail");
                ExpectedContainErrorMessage("The table specified does not exist.");
            }
            finally
            {
                tableUtil.RemoveTable(table);
            }
        }