Exemplo n.º 1
0
        public void NewPolicyDifferentValues()
        {
            List <Utility.RawStoredAccessPolicy> samplePolicies = Utility.SetUpStoredAccessPolicyData <SharedAccessQueuePolicy>();

            string     queueName = Utility.GenNameString("table");
            CloudQueue queue     = queueUtil.CreateQueue(queueName);

            Utility.ClearStoredAccessPolicy <CloudQueue>(queue);

            try
            {
                foreach (Utility.RawStoredAccessPolicy rawPolicy in samplePolicies)
                {
                    CreateStoredAccessPolicy(rawPolicy.PolicyName, rawPolicy.Permission, rawPolicy.StartTime, rawPolicy.ExpiryTime, queue, false);
                }

                Utility.WaitForPolicyBecomeValid <CloudQueue>(queue, expectedCount: samplePolicies.Count);

                SharedAccessQueuePolicies expectedPolicies = new SharedAccessQueuePolicies();
                foreach (Utility.RawStoredAccessPolicy rawPolicy in samplePolicies)
                {
                    expectedPolicies.Add(rawPolicy.PolicyName, Utility.SetupSharedAccessPolicy <SharedAccessQueuePolicy>(rawPolicy.StartTime, rawPolicy.ExpiryTime, rawPolicy.Permission));
                }

                Utility.ValidateStoredAccessPolicies <SharedAccessQueuePolicy>(queue.GetPermissions().SharedAccessPolicies, expectedPolicies);
            }
            finally
            {
                queueUtil.RemoveQueue(queueName);
            }
        }
Exemplo n.º 2
0
        internal void CreateStoredAccessPolicyAndValidate(string policyName, string permission, DateTime?startTime, DateTime?expiryTime, string queueName = null, bool ifCleanUpQueue = true, bool ifCleanUpPolicy = true)
        {
            CloudQueue queue = queueUtil.CreateQueue(queueName);

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

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

                Utility.RawStoredAccessPolicy policy = new Utility.RawStoredAccessPolicy(policyName, startTime, expiryTime, permission);
                Utility.WaitForPolicyBecomeValid <CloudQueue>(queue, policy);
                Utility.ValidateStoredAccessPolicies <SharedAccessQueuePolicy>(queue.GetPermissions().SharedAccessPolicies, expectedPolicies);
            }
            finally
            {
                if (ifCleanUpPolicy)
                {
                    Utility.ClearStoredAccessPolicy <CloudQueue>(queue);
                }
                if (ifCleanUpQueue)
                {
                    queueUtil.RemoveQueue(queue);
                }
            }
        }
Exemplo n.º 3
0
        public void SetPolicyNoStartTimeNoExpiryTime()
        {
            CloudQueue queue = queueUtil.CreateQueue();

            Utility.ClearStoredAccessPolicy <CloudQueue>(queue);
            Utility.RawStoredAccessPolicy samplePolicy = Utility.SetUpStoredAccessPolicyData <SharedAccessQueuePolicy>()[0];
            double effectiveTime = 30;

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

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

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

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

                Test.Assert(CommandAgent.SetAzureStorageQueueStoredAccessPolicy(queue.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 SharedAccessQueuePolicies();
                expectedPolicies.Add(samplePolicy.PolicyName, Utility.SetupSharedAccessPolicy <SharedAccessQueuePolicy>(null, null, samplePolicy.Permission));
                Utility.ValidateStoredAccessPolicies <SharedAccessQueuePolicy>(queue.GetPermissions().SharedAccessPolicies, expectedPolicies);
                policy = Utility.SetupSharedAccessPolicy <SharedAccessQueuePolicy>(null, null, samplePolicy.Permission);
                comp   = new Collection <Dictionary <string, object> >();
                comp.Add(Utility.ConstructGetPolicyOutput <SharedAccessQueuePolicy>(policy, samplePolicy.PolicyName));
                CommandAgent.OutputValidation(comp);
            }
            finally
            {
                queueUtil.RemoveQueue(queue);
            }
        }
Exemplo n.º 4
0
        internal void SetStoredAccessPolicyAndValidate(Utility.RawStoredAccessPolicy policy1, Utility.RawStoredAccessPolicy policy2, string queueName = null, bool ifCleanupPolicy = true, bool ifCleanupQueue = true)
        {
            CloudQueue queue = queueUtil.CreateQueue(queueName);

            if (ifCleanupPolicy)
            {
                Utility.ClearStoredAccessPolicy <CloudQueue>(queue);
            }

            policy2.PolicyName = policy1.PolicyName;

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

                //get the policy and validate
                SharedAccessQueuePolicies expectedPolicies = new SharedAccessQueuePolicies();
                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 <SharedAccessQueuePolicy>(policy2.StartTime, policy2.ExpiryTime, policy2.Permission));
                Utility.WaitForPolicyBecomeValid <CloudQueue>(queue, policy2);
                Utility.ValidateStoredAccessPolicies <SharedAccessQueuePolicy>(queue.GetPermissions().SharedAccessPolicies, expectedPolicies);

                //validate the output
                SharedAccessQueuePolicy policy = Utility.SetupSharedAccessPolicy <SharedAccessQueuePolicy>(policy2.StartTime, policy2.ExpiryTime, policy2.Permission);
                Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> >();
                comp.Add(Utility.ConstructGetPolicyOutput <SharedAccessQueuePolicy>(policy, policy2.PolicyName));
                CommandAgent.OutputValidation(comp);
            }
            finally
            {
                if (ifCleanupQueue)
                {
                    queueUtil.RemoveQueue(queue);
                }
            }
        }