public void ValidateSasCredentials() { // Create a SharedKeyCredential that we can use to sign the SAS token var credential = new TableSharedKeyCredential(TestEnvironment.AccountName, TestEnvironment.PrimaryStorageAccountKey); // Build a shared access signature with only Read permissions. TableSasBuilder sas = client.GetSasBuilder(TableSasPermissions.Read, new DateTime(2040, 1, 1, 1, 1, 0, DateTimeKind.Utc)); string token = sas.Sign(credential); // Build a SAS URI UriBuilder sasUri = new UriBuilder(TestEnvironment.StorageUri) { Query = token }; // Create the TableServiceClient using the SAS URI. var sasAuthedService = InstrumentClient(new TableServiceClient(sasUri.Uri, Recording.InstrumentClientOptions(new TableClientOptions()))); var sasTableclient = InstrumentClient(sasAuthedService.GetTableClient(tableName)); // Validate that we are able to query the table from the service. Assert.That(async() => await sasTableclient.QueryAsync().ToEnumerableAsync().ConfigureAwait(false), Throws.Nothing); // Validate that we are not able to upsert an entity to the table. Assert.That(async() => await sasTableclient.UpsertAsync(CreateTableEntities("partition", 1).First()), Throws.InstanceOf <RequestFailedException>().And.Property("Status").EqualTo((int)HttpStatusCode.Forbidden)); }
public void SetPermissions(string permissionsString, TableSasPermissions permissions) { var tableSasBuilder = new TableSasBuilder("table", permissionsString, DateTimeOffset.Now); Assert.That(tableSasBuilder.Permissions, Is.EqualTo(permissionsString)); tableSasBuilder.SetPermissions(permissions); Assert.That(tableSasBuilder.Permissions, Is.EqualTo(permissionsString)); }
public void SetPermissions(string tableName, string permissionsString, TableSasPermissions permissions) { var tableSasBuilder = new TableSasBuilder(tableName, permissionsString, DateTimeOffset.Now); Assert.AreEqual(permissionsString.ToLowerInvariant(), tableSasBuilder.Permissions); tableSasBuilder.SetPermissions(permissions); Assert.AreEqual(permissionsString.ToLowerInvariant(), tableSasBuilder.Permissions); Assert.AreEqual(tableName, tableSasBuilder.TableName); }
public void ParseUri(Uri uri) { // Act var tableSasBuilder = new TableSasBuilder(uri); // Assert Assert.AreEqual(TableSasProtocol.Https, tableSasBuilder.Protocol); Assert.AreEqual(new DateTimeOffset(2015, 4, 30, 2, 23, 26, TimeSpan.Zero), tableSasBuilder.ExpiresOn); Assert.AreEqual("", tableSasBuilder.Identifier); Assert.AreEqual(TableSasIPRange.Parse("168.1.5.60-168.1.5.70"), tableSasBuilder.IPRange); Assert.AreEqual("rw", tableSasBuilder.Permissions); Assert.AreEqual(TableSasProtocol.Https, tableSasBuilder.Protocol); Assert.AreEqual(new DateTimeOffset(2015, 4, 29, 22, 18, 26, TimeSpan.Zero), tableSasBuilder.StartsOn); Assert.AreEqual("2015-04-05", tableSasBuilder.Version); }