public StorageBlob.CloudBlobContainer CreateContainer(string containerName, StorageBlob.BlobContainerPublicAccessType permission)
 {
     StorageBlob.CloudBlobContainer       container           = CreateContainer(containerName);
     StorageBlob.BlobContainerPermissions containerPermission = new StorageBlob.BlobContainerPermissions();
     containerPermission.PublicAccess = permission;
     container.SetPermissions(containerPermission);
     return(container);
 }
        protected void AssertContainerAccess(string containerName, Microsoft.WindowsAzure.Storage.Blob.BlobContainerPublicAccessType containerAccessType)
        {
            var client    = StorageAccount.CreateCloudBlobClient();
            var container = client.GetContainerReference(containerName);

            if (!container.Exists())
            {
                Assert.Fail(String.Format("AssertContainerAccess: The container '{0}' does not exist", containerName));
            }

            var permissions = container.GetPermissions();

            Assert.AreEqual(containerAccessType, permissions.PublicAccess, String.Format("AssertContainerAccess: Container access was expected to be {0}, but it is actually {1}", containerAccessType, permissions.PublicAccess));
        }
        protected void AddContainerAccessPolicy(string containerName, Microsoft.WindowsAzure.Storage.Blob.BlobContainerPublicAccessType publicAccess, string id = null, DateTime?startDate = null, DateTime?expiry = null)
        {
            var client      = StorageAccount.CreateCloudBlobClient();
            var container   = client.GetContainerReference(containerName);
            var permissions = container.GetPermissions();

            permissions.PublicAccess = publicAccess;
            if (!string.IsNullOrEmpty(id) && startDate.HasValue && expiry.HasValue)
            {
                permissions.SharedAccessPolicies.Add(id, new Microsoft.WindowsAzure.Storage.Blob.SharedAccessBlobPolicy()
                {
                    Permissions            = Microsoft.WindowsAzure.Storage.Blob.SharedAccessBlobPermissions.Read,
                    SharedAccessStartTime  = startDate,
                    SharedAccessExpiryTime = expiry
                });
            }
            container.SetPermissions(permissions);
        }
Example #4
0
        internal void SetContainerACLTest(Agent agent)
        {
            string NEW_CONTAINER_NAME = Utility.GenNameString("astoria-");

            Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> >();
            Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Container, NEW_CONTAINER_NAME);

            comp.Add(dic);

            // create container if it does not exist
            StorageBlob.CloudBlobContainer container = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME);
            container.CreateIfNotExists();

            try
            {
                StorageBlob.BlobContainerPublicAccessType[] accessTypes = new StorageBlob.BlobContainerPublicAccessType[] {
                    StorageBlob.BlobContainerPublicAccessType.Blob,
                    StorageBlob.BlobContainerPublicAccessType.Container,
                    StorageBlob.BlobContainerPublicAccessType.Off
                };

                // set PublicAccess as one value respetively
                foreach (var accessType in accessTypes)
                {
                    //--------------Set operation--------------
                    Test.Assert(agent.SetAzureStorageContainerACL(NEW_CONTAINER_NAME, accessType),
                                "SetAzureStorageContainerACL operation should succeed");
                    // Verification for returned values
                    dic["PublicAccess"] = accessType;
                    CloudBlobUtil.PackContainerCompareData(container, dic);
                    agent.OutputValidation(comp);

                    Test.Assert(container.GetPermissions().PublicAccess == accessType,
                                "PublicAccess should be equal: {0} = {1}", container.GetPermissions().PublicAccess, accessType);
                }
            }
            finally
            {
                // clean up
                container.DeleteIfExists();
            }
        }
        internal void SetContainerACLTest(Agent agent)
        {
            string NEW_CONTAINER_NAME = Utility.GenNameString("astoria-");

            Collection<Dictionary<string, object>> comp = new Collection<Dictionary<string, object>>();
            Dictionary<string, object> dic = Utility.GenComparisonData(StorageObjectType.Container, NEW_CONTAINER_NAME);
            comp.Add(dic);

            // create container if it does not exist
            StorageBlob.CloudBlobContainer container = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME);
            container.CreateIfNotExists();

            try
            {
                StorageBlob.BlobContainerPublicAccessType[] accessTypes = new StorageBlob.BlobContainerPublicAccessType[] { 
                    StorageBlob.BlobContainerPublicAccessType.Blob,
                    StorageBlob.BlobContainerPublicAccessType.Container,
                    StorageBlob.BlobContainerPublicAccessType.Off
                };

                // set PublicAccess as one value respetively
                foreach (var accessType in accessTypes)
                {
                    //--------------Set operation-------------- 
                    Test.Assert(agent.SetAzureStorageContainerACL(NEW_CONTAINER_NAME, accessType),
                        "SetAzureStorageContainerACL operation should succeed");
                    // Verification for returned values
                    dic["PublicAccess"] = accessType;
                    CloudBlobUtil.PackContainerCompareData(container, dic);
                    agent.OutputValidation(comp);

                    Test.Assert(container.GetPermissions().PublicAccess == accessType,
                        "PublicAccess should be equal: {0} = {1}", container.GetPermissions().PublicAccess, accessType);
                }
            }
            finally
            {
                // clean up
                container.DeleteIfExists();
            }
        }