public void CloudBlobContainerPolicy() { CloudBlockBlob testBlockBlob = this.testContainer.GetBlockBlobReference("blockblob"); CloudPageBlob testPageBlob = this.testContainer.GetPageBlobReference("pageblob"); CloudAppendBlob testAppendBlob = this.testContainer.GetAppendBlobReference("appendblob"); SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy() { SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5), SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30), Permissions = SharedAccessBlobPermissions.Read, }; BlobContainerPermissions permissions = new BlobContainerPermissions(); permissions.SharedAccessPolicies.Add("testpolicy", policy); this.testContainer.SetPermissions(permissions); string sasToken = testBlockBlob.GetSharedAccessSignature(null, "testpolicy"); TestHelper.SpinUpTo30SecondsIgnoringFailures(() => SASTests.TestAccess(sasToken, policy.Permissions, null, null, testBlockBlob)); sasToken = testPageBlob.GetSharedAccessSignature(null, "testpolicy"); TestHelper.SpinUpTo30SecondsIgnoringFailures(() => SASTests.TestAccess(sasToken, policy.Permissions, null, null, testPageBlob)); sasToken = testAppendBlob.GetSharedAccessSignature(null, "testpolicy"); TestHelper.SpinUpTo30SecondsIgnoringFailures(() => SASTests.TestAccess(sasToken, policy.Permissions, null, null, testAppendBlob)); sasToken = this.testContainer.GetSharedAccessSignature(null, "testpolicy"); TestHelper.SpinUpTo30SecondsIgnoringFailures(() => SASTests.TestAccess(sasToken, policy.Permissions, null, this.testContainer, testBlockBlob)); TestHelper.SpinUpTo30SecondsIgnoringFailures(() => SASTests.TestAccess(sasToken, policy.Permissions, null, this.testContainer, testPageBlob)); TestHelper.SpinUpTo30SecondsIgnoringFailures(() => SASTests.TestAccess(sasToken, policy.Permissions, null, this.testContainer, testAppendBlob)); }
public void CloudBlobContainerPolicy() { CloudBlockBlob testBlockBlob = this.testContainer.GetBlockBlobReference("blockblob"); UploadText(testBlockBlob, "blob", Encoding.UTF8); CloudPageBlob testPageBlob = this.testContainer.GetPageBlobReference("pageblob"); UploadText(testPageBlob, "blob", Encoding.UTF8); SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy() { SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5), SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30), Permissions = SharedAccessBlobPermissions.Read, }; BlobContainerPermissions permissions = new BlobContainerPermissions(); permissions.SharedAccessPolicies.Add("testpolicy", policy); this.testContainer.SetPermissions(permissions); Thread.Sleep(35 * 1000); string sasToken = testBlockBlob.GetSharedAccessSignature(null, "testpolicy"); SASTests.TestAccess(sasToken, policy.Permissions, null, null, testBlockBlob); sasToken = testPageBlob.GetSharedAccessSignature(null, "testpolicy"); SASTests.TestAccess(sasToken, policy.Permissions, null, null, testPageBlob); sasToken = this.testContainer.GetSharedAccessSignature(null, "testpolicy"); SASTests.TestAccess(sasToken, policy.Permissions, null, this.testContainer, testBlockBlob); SASTests.TestAccess(sasToken, policy.Permissions, null, this.testContainer, testPageBlob); }
public async Task CloudBlobContainerSASCombinations() { List <Task> tasks = new List <Task>(); for (int i = 1; i < 0x40; i++) { SharedAccessBlobPermissions permissions = (SharedAccessBlobPermissions)i; SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy() { SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5), SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30), Permissions = permissions, }; string sasToken = this.testContainer.GetSharedAccessSignature(policy); CloudBlockBlob testBlockBlob = this.testContainer.GetBlockBlobReference("blockblob" + i); tasks.Add(Task.Run(() => SASTests.TestAccess(sasToken, permissions, null, this.testContainer, testBlockBlob))); CloudPageBlob testPageBlob = this.testContainer.GetPageBlobReference("pageblob" + i); tasks.Add(Task.Run(() => SASTests.TestAccess(sasToken, permissions, null, this.testContainer, testPageBlob))); CloudAppendBlob testAppendBlob = this.testContainer.GetAppendBlobReference("appendblob" + i); tasks.Add(Task.Run(() => SASTests.TestAccess(sasToken, permissions, null, this.testContainer, testAppendBlob))); // Limit the number of parallel tasks to 90 while (tasks.Count > 50) { Task t = await Task.WhenAny(tasks); await t; tasks.Remove(t); } } Task.WaitAll(tasks.ToArray()); }
public void CloudBlobContainerPublicAccess() { CloudBlockBlob testBlockBlob = this.testContainer.GetBlockBlobReference("blockblob"); UploadText(testBlockBlob, "blob", Encoding.UTF8); CloudPageBlob testPageBlob = this.testContainer.GetPageBlobReference("pageblob"); UploadText(testPageBlob, "blob", Encoding.UTF8); CloudAppendBlob testAppendBlob = this.testContainer.GetAppendBlobReference("appendblob"); UploadText(testAppendBlob, "blob", Encoding.UTF8); BlobContainerPermissions permissions = new BlobContainerPermissions(); permissions.PublicAccess = BlobContainerPublicAccessType.Container; this.testContainer.SetPermissions(permissions); Thread.Sleep(35 * 1000); SASTests.TestAccess(null, SharedAccessBlobPermissions.List | SharedAccessBlobPermissions.Read, null, this.testContainer, testBlockBlob); SASTests.TestAccess(null, SharedAccessBlobPermissions.List | SharedAccessBlobPermissions.Read, null, this.testContainer, testPageBlob); SASTests.TestAccess(null, SharedAccessBlobPermissions.List | SharedAccessBlobPermissions.Read, null, this.testContainer, testAppendBlob); permissions.PublicAccess = BlobContainerPublicAccessType.Blob; this.testContainer.SetPermissions(permissions); Thread.Sleep(35 * 1000); SASTests.TestAccess(null, SharedAccessBlobPermissions.Read, null, this.testContainer, testBlockBlob); SASTests.TestAccess(null, SharedAccessBlobPermissions.Read, null, this.testContainer, testPageBlob); SASTests.TestAccess(null, SharedAccessBlobPermissions.Read, null, this.testContainer, testAppendBlob); }
public void CloudBlobContainerSASCombinations() { for (int i = 1; i < 16; i++) { SharedAccessBlobPermissions permissions = (SharedAccessBlobPermissions)i; SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy() { SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5), SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30), Permissions = permissions, }; string sasToken = this.testContainer.GetSharedAccessSignature(policy); CloudBlockBlob testBlockBlob = this.testContainer.GetBlockBlobReference("blockblob" + i); UploadText(testBlockBlob, "blob", Encoding.UTF8); SASTests.TestAccess(sasToken, permissions, null, this.testContainer, testBlockBlob); CloudPageBlob testPageBlob = this.testContainer.GetPageBlobReference("pageblob" + i); UploadText(testPageBlob, "blob", Encoding.UTF8); SASTests.TestAccess(sasToken, permissions, null, this.testContainer, testPageBlob); CloudAppendBlob testAppendBlob = this.testContainer.GetAppendBlobReference("appendblob" + i); UploadText(testAppendBlob, "blob", Encoding.UTF8); SASTests.TestAccess(sasToken, permissions, null, this.testContainer, testAppendBlob); } }
private static void TestBlobSAS(ICloudBlob testBlob, SharedAccessBlobPermissions permissions) { UploadText(testBlob, "blob", Encoding.UTF8); SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy() { SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5), SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30), Permissions = permissions, }; string sasToken = testBlob.GetSharedAccessSignature(policy); SASTests.TestAccess(sasToken, permissions, null, testBlob); }
public void CloudBlobContainerPublicAccess() { CloudBlockBlob testBlockBlob = this.testContainer.GetBlockBlobReference("blockblob"); CloudPageBlob testPageBlob = this.testContainer.GetPageBlobReference("pageblob"); CloudAppendBlob testAppendBlob = this.testContainer.GetAppendBlobReference("appendblob"); BlobContainerPermissions permissions = new BlobContainerPermissions(); permissions.PublicAccess = BlobContainerPublicAccessType.Container; this.testContainer.SetPermissions(permissions); TestHelper.SpinUpTo30SecondsIgnoringFailures(() => SASTests.TestAccess(null, SharedAccessBlobPermissions.List | SharedAccessBlobPermissions.Read, null, this.testContainer, testBlockBlob)); TestHelper.SpinUpTo30SecondsIgnoringFailures(() => SASTests.TestAccess(null, SharedAccessBlobPermissions.List | SharedAccessBlobPermissions.Read, null, this.testContainer, testPageBlob)); TestHelper.SpinUpTo30SecondsIgnoringFailures(() => SASTests.TestAccess(null, SharedAccessBlobPermissions.List | SharedAccessBlobPermissions.Read, null, this.testContainer, testAppendBlob)); permissions.PublicAccess = BlobContainerPublicAccessType.Blob; this.testContainer.SetPermissions(permissions); TestHelper.SpinUpTo30SecondsIgnoringFailures(() => SASTests.TestAccess(null, SharedAccessBlobPermissions.Read, null, this.testContainer, testBlockBlob)); TestHelper.SpinUpTo30SecondsIgnoringFailures(() => SASTests.TestAccess(null, SharedAccessBlobPermissions.Read, null, this.testContainer, testPageBlob)); TestHelper.SpinUpTo30SecondsIgnoringFailures(() => SASTests.TestAccess(null, SharedAccessBlobPermissions.Read, null, this.testContainer, testAppendBlob)); }