Skip to content

Commit 9999a8d

Browse files
authored
[Storage] Added RequestConditions validation to DataLakeLeaseClient (Azure#22196)
1 parent 0307922 commit 9999a8d

21 files changed

+293
-0
lines changed

sdk/storage/Azure.Storage.Files.DataLake/tests/FileSystemClientTests.cs

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,42 @@ public async Task AquireLeaseAsync()
12631263
});
12641264
}
12651265

1266+
[RecordedTest]
1267+
[TestCase(nameof(RequestConditions.IfMatch))]
1268+
[TestCase(nameof(RequestConditions.IfNoneMatch))]
1269+
public async Task AcquireLeaseAsync_InvalidRequestConditions(string invalidCondition)
1270+
{
1271+
// Arrange
1272+
Uri uri = new Uri("https://www.doesntmatter.com");
1273+
DataLakeFileSystemClient fileSystemClient = new DataLakeFileSystemClient(uri, GetOptions());
1274+
string id = Recording.Random.NewGuid().ToString();
1275+
TimeSpan duration = TimeSpan.FromSeconds(15);
1276+
DataLakeLeaseClient leaseClient = InstrumentClient(fileSystemClient.GetDataLakeLeaseClient(id));
1277+
1278+
RequestConditions conditions = new RequestConditions();
1279+
1280+
switch (invalidCondition)
1281+
{
1282+
case nameof(RequestConditions.IfMatch):
1283+
conditions.IfMatch = new ETag();
1284+
break;
1285+
case nameof(RequestConditions.IfNoneMatch):
1286+
conditions.IfNoneMatch = new ETag();
1287+
break;
1288+
}
1289+
1290+
// Act
1291+
await TestHelper.AssertExpectedExceptionAsync<ArgumentException>(
1292+
leaseClient.AcquireAsync(
1293+
duration,
1294+
conditions),
1295+
e =>
1296+
{
1297+
Assert.IsTrue(e.Message.Contains($"Acquire does not support the {invalidCondition} condition(s)."));
1298+
Assert.IsTrue(e.Message.Contains("conditions"));
1299+
});
1300+
}
1301+
12661302
[RecordedTest]
12671303
public async Task AcquireLeaseAsync_Error()
12681304
{
@@ -1363,6 +1399,40 @@ public async Task RenewLeaseAsync()
13631399
});
13641400
}
13651401

1402+
[RecordedTest]
1403+
[TestCase(nameof(RequestConditions.IfMatch))]
1404+
[TestCase(nameof(RequestConditions.IfNoneMatch))]
1405+
public async Task RenewLeaseAsync_InvalidRequestConditions(string invalidCondition)
1406+
{
1407+
// Arrange
1408+
Uri uri = new Uri("https://www.doesntmatter.com");
1409+
DataLakeFileSystemClient fileSystemClient = new DataLakeFileSystemClient(uri, GetOptions());
1410+
string id = Recording.Random.NewGuid().ToString();
1411+
DataLakeLeaseClient leaseClient = InstrumentClient(fileSystemClient.GetDataLakeLeaseClient(id));
1412+
1413+
RequestConditions conditions = new RequestConditions();
1414+
1415+
switch (invalidCondition)
1416+
{
1417+
case nameof(RequestConditions.IfMatch):
1418+
conditions.IfMatch = new ETag();
1419+
break;
1420+
case nameof(RequestConditions.IfNoneMatch):
1421+
conditions.IfNoneMatch = new ETag();
1422+
break;
1423+
}
1424+
1425+
// Act
1426+
await TestHelper.AssertExpectedExceptionAsync<ArgumentException>(
1427+
leaseClient.RenewAsync(
1428+
conditions: conditions),
1429+
e =>
1430+
{
1431+
Assert.IsTrue(e.Message.Contains($"Release does not support the {invalidCondition} condition(s)."));
1432+
Assert.IsTrue(e.Message.Contains("conditions"));
1433+
});
1434+
}
1435+
13661436
[RecordedTest]
13671437
public async Task RenewLeaseAsync_Error()
13681438
{
@@ -1463,6 +1533,40 @@ public async Task ReleaseLeaseAsync()
14631533
Assert.AreEqual(DataLakeLeaseState.Available, response.Value.LeaseState);
14641534
}
14651535

1536+
[RecordedTest]
1537+
[TestCase(nameof(RequestConditions.IfMatch))]
1538+
[TestCase(nameof(RequestConditions.IfNoneMatch))]
1539+
public async Task ReleaseLeaseAsync_InvalidRequestConditions(string invalidCondition)
1540+
{
1541+
// Arrange
1542+
Uri uri = new Uri("https://www.doesntmatter.com");
1543+
DataLakeFileSystemClient fileSystemClient = new DataLakeFileSystemClient(uri, GetOptions());
1544+
string id = Recording.Random.NewGuid().ToString();
1545+
DataLakeLeaseClient leaseClient = InstrumentClient(fileSystemClient.GetDataLakeLeaseClient(id));
1546+
1547+
RequestConditions conditions = new RequestConditions();
1548+
1549+
switch (invalidCondition)
1550+
{
1551+
case nameof(RequestConditions.IfMatch):
1552+
conditions.IfMatch = new ETag();
1553+
break;
1554+
case nameof(RequestConditions.IfNoneMatch):
1555+
conditions.IfNoneMatch = new ETag();
1556+
break;
1557+
}
1558+
1559+
// Act
1560+
await TestHelper.AssertExpectedExceptionAsync<ArgumentException>(
1561+
leaseClient.ReleaseAsync(
1562+
conditions: conditions),
1563+
e =>
1564+
{
1565+
Assert.IsTrue(e.Message.Contains($"Release does not support the {invalidCondition} condition(s)."));
1566+
Assert.IsTrue(e.Message.Contains("conditions"));
1567+
});
1568+
}
1569+
14661570
[RecordedTest]
14671571
public async Task ReleaseLeaseAsync_Error()
14681572
{
@@ -1558,6 +1662,41 @@ public async Task ChangeLeaseAsync()
15581662
await InstrumentClient(test.FileSystem.GetDataLakeLeaseClient(changeResponse.Value.LeaseId)).ReleaseAsync();
15591663
}
15601664

1665+
[RecordedTest]
1666+
[TestCase(nameof(RequestConditions.IfMatch))]
1667+
[TestCase(nameof(RequestConditions.IfNoneMatch))]
1668+
public async Task ChangeLeaseAsync_InvalidRequestConditions(string invalidCondition)
1669+
{
1670+
// Arrange
1671+
Uri uri = new Uri("https://www.doesntmatter.com");
1672+
DataLakeFileSystemClient fileSystemClient = new DataLakeFileSystemClient(uri, GetOptions());
1673+
string id = Recording.Random.NewGuid().ToString();
1674+
DataLakeLeaseClient leaseClient = InstrumentClient(fileSystemClient.GetDataLakeLeaseClient(id));
1675+
1676+
RequestConditions conditions = new RequestConditions();
1677+
1678+
switch (invalidCondition)
1679+
{
1680+
case nameof(RequestConditions.IfMatch):
1681+
conditions.IfMatch = new ETag();
1682+
break;
1683+
case nameof(RequestConditions.IfNoneMatch):
1684+
conditions.IfNoneMatch = new ETag();
1685+
break;
1686+
}
1687+
1688+
// Act
1689+
await TestHelper.AssertExpectedExceptionAsync<ArgumentException>(
1690+
leaseClient.ChangeAsync(
1691+
id,
1692+
conditions: conditions),
1693+
e =>
1694+
{
1695+
Assert.IsTrue(e.Message.Contains($"Change does not support the {invalidCondition} condition(s)."));
1696+
Assert.IsTrue(e.Message.Contains("conditions"));
1697+
});
1698+
}
1699+
15611700
[RecordedTest]
15621701
public async Task ChangeLeaseAsync_Error()
15631702
{
@@ -1664,6 +1803,40 @@ public async Task BreakLeaseAsync()
16641803
Assert.AreEqual(DataLakeLeaseState.Broken, response.Value.LeaseState);
16651804
}
16661805

1806+
[RecordedTest]
1807+
[TestCase(nameof(RequestConditions.IfMatch))]
1808+
[TestCase(nameof(RequestConditions.IfNoneMatch))]
1809+
public async Task BreakLeaseAsync_InvalidRequestConditions(string invalidCondition)
1810+
{
1811+
// Arrange
1812+
Uri uri = new Uri("https://www.doesntmatter.com");
1813+
DataLakeFileSystemClient containerClient = new DataLakeFileSystemClient(uri, GetOptions());
1814+
string id = Recording.Random.NewGuid().ToString();
1815+
DataLakeLeaseClient leaseClient = InstrumentClient(containerClient.GetDataLakeLeaseClient(id));
1816+
1817+
RequestConditions conditions = new RequestConditions();
1818+
1819+
switch (invalidCondition)
1820+
{
1821+
case nameof(RequestConditions.IfMatch):
1822+
conditions.IfMatch = new ETag();
1823+
break;
1824+
case nameof(RequestConditions.IfNoneMatch):
1825+
conditions.IfNoneMatch = new ETag();
1826+
break;
1827+
}
1828+
1829+
// Act
1830+
await TestHelper.AssertExpectedExceptionAsync<ArgumentException>(
1831+
leaseClient.BreakAsync(
1832+
conditions: conditions),
1833+
e =>
1834+
{
1835+
Assert.IsTrue(e.Message.Contains($"Break does not support the {invalidCondition} condition(s)."));
1836+
Assert.IsTrue(e.Message.Contains("conditions"));
1837+
});
1838+
}
1839+
16671840
[RecordedTest]
16681841
public async Task BreakLeaseAsync_Error()
16691842
{

sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/AcquireLeaseAsync_InvalidRequestConditions(%IfMatch%).json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/AcquireLeaseAsync_InvalidRequestConditions(%IfMatch%)Async.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/AcquireLeaseAsync_InvalidRequestConditions(%IfNoneMatch%).json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/AcquireLeaseAsync_InvalidRequestConditions(%IfNoneMatch%)Async.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/BreakLeaseAsync_InvalidRequestConditions(%IfMatch%).json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/BreakLeaseAsync_InvalidRequestConditions(%IfMatch%)Async.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/BreakLeaseAsync_InvalidRequestConditions(%IfNoneMatch%).json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/BreakLeaseAsync_InvalidRequestConditions(%IfNoneMatch%)Async.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/storage/Azure.Storage.Files.DataLake/tests/SessionRecords/FileSystemClientTests/ChangeLeaseAsync_InvalidRequestConditions(%IfMatch%).json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)