Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for encryptiondata key casing #37702

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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