Skip to content

Commit ad4d05e

Browse files
fix test construction (#29700)
* fix test construction augmented blob test fixture to accept additional parameters reorder test constructor args * fix test
1 parent 4586797 commit ad4d05e

File tree

5 files changed

+44
-60
lines changed

5 files changed

+44
-60
lines changed

sdk/storage/Azure.Storage.Blobs/tests/BlobsClientTestFixtureAttribute.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,28 @@ namespace Azure.Storage.Blobs.Tests
77
{
88
public class BlobsClientTestFixtureAttribute : ClientTestFixtureAttribute
99
{
10-
public BlobsClientTestFixtureAttribute()
10+
public BlobsClientTestFixtureAttribute(params object[] additionalParameters)
1111
: base(
12-
BlobClientOptions.ServiceVersion.V2019_02_02,
13-
BlobClientOptions.ServiceVersion.V2019_07_07,
14-
BlobClientOptions.ServiceVersion.V2019_12_12,
15-
BlobClientOptions.ServiceVersion.V2020_02_10,
16-
BlobClientOptions.ServiceVersion.V2020_04_08,
17-
BlobClientOptions.ServiceVersion.V2020_06_12,
18-
BlobClientOptions.ServiceVersion.V2020_08_04,
19-
BlobClientOptions.ServiceVersion.V2020_10_02,
20-
BlobClientOptions.ServiceVersion.V2020_12_06,
21-
BlobClientOptions.ServiceVersion.V2021_02_12,
22-
BlobClientOptions.ServiceVersion.V2021_04_10,
23-
BlobClientOptions.ServiceVersion.V2021_06_08,
24-
BlobClientOptions.ServiceVersion.V2021_08_06,
25-
StorageVersionExtensions.LatestVersion,
26-
StorageVersionExtensions.MaxVersion)
12+
serviceVersions: new object[]
13+
{
14+
BlobClientOptions.ServiceVersion.V2019_02_02,
15+
BlobClientOptions.ServiceVersion.V2019_07_07,
16+
BlobClientOptions.ServiceVersion.V2019_12_12,
17+
BlobClientOptions.ServiceVersion.V2020_02_10,
18+
BlobClientOptions.ServiceVersion.V2020_04_08,
19+
BlobClientOptions.ServiceVersion.V2020_06_12,
20+
BlobClientOptions.ServiceVersion.V2020_08_04,
21+
BlobClientOptions.ServiceVersion.V2020_10_02,
22+
BlobClientOptions.ServiceVersion.V2020_12_06,
23+
BlobClientOptions.ServiceVersion.V2021_02_12,
24+
BlobClientOptions.ServiceVersion.V2021_04_10,
25+
BlobClientOptions.ServiceVersion.V2021_06_08,
26+
BlobClientOptions.ServiceVersion.V2021_08_06,
27+
StorageVersionExtensions.LatestVersion,
28+
StorageVersionExtensions.MaxVersion
29+
},
30+
additionalParameters: additionalParameters
31+
)
2732
{
2833
RecordingServiceVersion = StorageVersionExtensions.MaxVersion;
2934
LiveServiceVersions = new object[] { StorageVersionExtensions.LatestVersion };

sdk/storage/Azure.Storage.Blobs/tests/ClientSideEncryptedBlobClientOpenWriteTests.cs

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Threading.Tasks;
77
using Azure.Core.TestFramework;
8+
using Azure.Storage.Cryptography;
89
using Azure.Storage.Test;
910
using Azure.Storage.Test.Shared;
1011
using NUnit.Framework;
@@ -19,17 +20,16 @@ namespace Azure.Storage.Blobs.Tests
1920
/// </summary>
2021
[LiveOnly]
2122
#pragma warning disable CS0618 // obsolete
22-
[TestFixture(ClientSideEncryptionVersion.V1_0)]
23-
[TestFixture(ClientSideEncryptionVersion.V2_0)]
23+
[BlobsClientTestFixture(ClientSideEncryptionVersion.V1_0, ClientSideEncryptionVersion.V2_0)]
2424
#pragma warning restore CS0618 // obsolete
2525
public class ClientSideEncryptedBlobClientOpenWriteTests : BlobClientOpenWriteTests
2626
{
2727
private readonly ClientSideEncryptionVersion _version;
2828

2929
public ClientSideEncryptedBlobClientOpenWriteTests(
30-
ClientSideEncryptionVersion version,
3130
bool async,
32-
BlobClientOptions.ServiceVersion serviceVersion)
31+
BlobClientOptions.ServiceVersion serviceVersion,
32+
ClientSideEncryptionVersion version)
3333
: base(async, serviceVersion, null /* RecordedTestMode.Record /* to re-record */)
3434
{
3535
_version = version;
@@ -53,6 +53,15 @@ protected override BlobClient GetResourceClient(BlobContainerClient container, s
5353
return base.GetResourceClient(container, resourceName, options);
5454
}
5555

56+
protected override long GetExpectedDataLength(long dataLength) => _version switch
57+
{
58+
#pragma warning disable CS0618 // obsolete
59+
ClientSideEncryptionVersion.V1_0 => ClientSideEncryptorV1_0.CalculateExpectedOutputContentLength(dataLength),
60+
#pragma warning restore CS0618 // obsolete
61+
ClientSideEncryptionVersion.V2_0 => ClientSideEncryptorV2_0.CalculateExpectedOutputContentLength(dataLength),
62+
_ => dataLength
63+
};
64+
5665
#region Test Overrides
5766
/// <summary>
5867
/// Need to change assertions for a metadata test.
@@ -122,43 +131,6 @@ public override async Task OpenWriteAsync_NewBlob_WithMetadata()
122131

123132
await (AdditionalAssertions?.Invoke(client) ?? Task.CompletedTask);
124133
}
125-
126-
/// <summary>
127-
/// Need to change assertions for a progress reporting test.
128-
/// Client-side encryption alters data length.
129-
/// </summary>
130-
[Test]
131-
public override async Task OpenWriteAsync_ProgressReporting()
132-
{
133-
const int bufferSize = 256;
134-
135-
// Arrange
136-
await using IDisposingContainer<BlobContainerClient> disposingContainer = await GetDisposingContainerAsync();
137-
BlobClient client = GetResourceClient(disposingContainer.Container);
138-
139-
byte[] data = GetRandomBuffer(Constants.KB);
140-
using Stream stream = new MemoryStream(data);
141-
142-
TestProgress progress = new TestProgress();
143-
144-
// Act
145-
using (Stream openWriteStream = await OpenWriteAsync(
146-
client,
147-
overwrite: true,
148-
maxDataSize: Constants.KB,
149-
bufferSize: bufferSize,
150-
progressHandler: progress))
151-
{
152-
await stream.CopyToAsync(openWriteStream);
153-
await openWriteStream.FlushAsync();
154-
}
155-
156-
// Assert
157-
Assert.IsTrue(progress.List.Count > 0);
158-
Assert.AreEqual(data.Length - (data.Length % 16) + 16, progress.List[progress.List.Count - 1]);
159-
160-
await (AdditionalAssertions?.Invoke(client) ?? Task.CompletedTask);
161-
}
162134
#endregion
163135
}
164136
}

sdk/storage/Azure.Storage.Common/src/Shared/ClientsideEncryption/ClientSideEncryptorV1_0.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ private void ValidateMembers()
3939
}
4040
}
4141

42-
public long ExpectedOutputContentLength(long plaintextLength)
42+
public long ExpectedOutputContentLength(long plaintextLength) => CalculateExpectedOutputContentLength(plaintextLength);
43+
44+
public static long CalculateExpectedOutputContentLength(long plaintextLength)
4345
{
4446
const int aesBlockSizeBytes = 16;
4547

sdk/storage/Azure.Storage.Common/src/Shared/ClientsideEncryption/ClientSideEncryptorV2_0.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public ClientSideEncryptorV2_0(ClientSideEncryptionOptions options)
3333
_keyWrapAlgorithm = options.KeyWrapAlgorithm;
3434
}
3535

36-
public long ExpectedOutputContentLength(long plaintextLength)
36+
public long ExpectedOutputContentLength(long plaintextLength) => CalculateExpectedOutputContentLength(plaintextLength);
37+
38+
public static long CalculateExpectedOutputContentLength(long plaintextLength)
3739
{
3840
long numBlocks = plaintextLength / EncryptionRegionDataSize;
3941
// partial block check

sdk/storage/Azure.Storage.Common/tests/Shared/OpenWriteTestBase.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ protected string GetNewResourceName()
149149
private string GetGarbageLeaseId()
150150
=> ClientBuilder.Recording.Random.NewGuid().ToString();
151151

152+
// hook for clientside encryption to adjust some test assertions
153+
protected virtual long GetExpectedDataLength(long dataLength) => dataLength;
154+
152155
#region Tests
153156
[RecordedTest]
154157
public async Task OpenWriteAsync_NewBlob()
@@ -527,7 +530,7 @@ public virtual async Task OpenWriteAsync_ProgressReporting()
527530

528531
// Assert
529532
Assert.IsTrue(progress.List.Count > 0);
530-
Assert.AreEqual(dataSize, progress.List[progress.List.Count - 1]);
533+
Assert.AreEqual(GetExpectedDataLength(dataSize), progress.List[progress.List.Count - 1]);
531534

532535
await (AdditionalAssertions?.Invoke(client) ?? Task.CompletedTask);
533536
}

0 commit comments

Comments
 (0)