Skip to content

Commit

Permalink
add test for encryptiondata key casing (#37702)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaschrep-msft authored Jul 24, 2023
1 parent 32fe9a2 commit 14d9861
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/tests/ClientSideEncryptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,41 @@ static byte[] GetRandomBytes(int length)
CollectionAssert.AreEqual(plaintext.ToArray(), roundtrippedPlaintext);
}

[Test]
[Combinatorial]
[LiveOnly]
public async Task EncryptionDataCaseInsensitivity(
[Values("ENCRYPTIONDATA", "EncryptionData", "eNcRyPtIoNdAtA")] string newKey,
[ValueSource("GetEncryptionVersions")] ClientSideEncryptionVersion version)
{
// Arrange
ReadOnlyMemory<byte> data = GetRandomBuffer(Constants.KB);
Mock<IKeyEncryptionKey> mockKey1 = this.GetIKeyEncryptionKey(s_cancellationToken);
var encryptionOptions = new ClientSideEncryptionOptions(version)
{
KeyEncryptionKey = mockKey1.Object,
KeyWrapAlgorithm = s_algorithmName
};

await using var disposable = await GetTestContainerAsync();

BlobClient standardBlobClient = disposable.Container.GetBlobClient(GetNewBlobName());
BlobClient encryptedBlobClient = InstrumentClient(standardBlobClient.WithClientSideEncryptionOptions(encryptionOptions));

await encryptedBlobClient.UploadAsync(BinaryData.FromBytes(data), cancellationToken: s_cancellationToken);

// change casing of encryptiondata key
string rawEncryptiondata = (await standardBlobClient.GetPropertiesAsync()).Value.Metadata[EncryptionDataKey];
Assert.IsNotEmpty(rawEncryptiondata); // quick check we're testing the right thing
await standardBlobClient.SetMetadataAsync(new Dictionary<string, string> { { newKey, rawEncryptiondata } });

// Act
ReadOnlyMemory<byte> downloadedContent = (await encryptedBlobClient.DownloadContentAsync(s_cancellationToken)).Value.Content.ToMemory();

// Assert
Assert.IsTrue(data.Span.SequenceEqual(downloadedContent.Span));
}

/// <summary>
/// There's a few too many things to switch on for key updates. Separate method to determine the correct way to call it.
/// </summary>
Expand Down

0 comments on commit 14d9861

Please sign in to comment.