Skip to content

Commit

Permalink
[Client Encryption]: Removes Plaintext encryption type support. (#2453)
Browse files Browse the repository at this point in the history
The PR removes the support for Plaintext encryption type.
  • Loading branch information
kr-santosh authored May 13, 2021
1 parent 33e6d9e commit a0a646c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
5 changes: 0 additions & 5 deletions Microsoft.Azure.Cosmos.Encryption/src/CosmosEncryptionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ namespace Microsoft.Azure.Cosmos.Encryption
/// </summary>
internal static class CosmosEncryptionType
{
/// <summary>
/// Plaintext, unencrypted data.
/// </summary>
public const string Plaintext = "Plaintext";

/// <summary>
/// Deterministic encryption always generates the same encrypted value for any given plain text value.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ private static EncryptionType GetEncryptionTypeForProperty(ClientEncryptionInclu
{
CosmosEncryptionType.Deterministic => EncryptionType.Deterministic,
CosmosEncryptionType.Randomized => EncryptionType.Randomized,
CosmosEncryptionType.Plaintext => EncryptionType.Plaintext,
_ => throw new ArgumentException($"Invalid encryption type {clientEncryptionIncludedPath.EncryptionType}. Please refer to https://aka.ms/CosmosClientEncryption for more details. "),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ private void ValidateClientEncryptionIncludedPath(ClientEncryptionIncludedPath c
}

if (!string.Equals(clientEncryptionIncludedPath.EncryptionType, "Deterministic") &&
!string.Equals(clientEncryptionIncludedPath.EncryptionType, "Randomized") &&
!string.Equals(clientEncryptionIncludedPath.EncryptionType, "Plaintext"))
!string.Equals(clientEncryptionIncludedPath.EncryptionType, "Randomized"))
{
throw new ArgumentException("EncryptionType should be either 'Deterministic' or 'Randomized' or 'Plaintext'.", nameof(clientEncryptionIncludedPath));
throw new ArgumentException("EncryptionType should be either 'Deterministic' or 'Randomized'. ", nameof(clientEncryptionIncludedPath));
}

if (string.IsNullOrWhiteSpace(clientEncryptionIncludedPath.EncryptionAlgorithm))
Expand All @@ -99,7 +98,7 @@ private void ValidateClientEncryptionIncludedPath(ClientEncryptionIncludedPath c

if (!string.Equals(clientEncryptionIncludedPath.EncryptionAlgorithm, "AEAD_AES_256_CBC_HMAC_SHA256"))
{
throw new ArgumentException("EncryptionAlgorithm should be 'AEAD_AES_256_CBC_HMAC_SHA256'.", nameof(clientEncryptionIncludedPath));
throw new ArgumentException("EncryptionAlgorithm should be 'AEAD_AES_256_CBC_HMAC_SHA256'. ", nameof(clientEncryptionIncludedPath));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,25 @@ public async Task WithClientEncryptionPolicyFailureTest()
}
catch (ArgumentException ex)
{
Assert.IsTrue(ex.Message.Contains("EncryptionType should be either 'Deterministic' or 'Randomized' or 'Plaintext'."));
Assert.IsTrue(ex.Message.Contains("EncryptionType should be either 'Deterministic' or 'Randomized'. "));
}

path1.EncryptionType = "Plaintext";

// Invalid EncryptionType
try
{
ContainerResponse containerResponse = await this.database.DefineContainer(containerName, partitionKeyPath)
.WithClientEncryptionPolicy()
.WithIncludedPath(path1)
.Attach()
.CreateAsync();

Assert.Fail("CreateCollection with invalid ClientEncryptionPolicy should have failed.");
}
catch (ArgumentException ex)
{
Assert.IsTrue(ex.Message.Contains("EncryptionType should be either 'Deterministic' or 'Randomized'. "));
}

path1.EncryptionType = "Deterministic";
Expand All @@ -717,7 +735,7 @@ public async Task WithClientEncryptionPolicyFailureTest()
}
catch (ArgumentException ex)
{
Assert.IsTrue(ex.Message.Contains("EncryptionAlgorithm should be 'AEAD_AES_256_CBC_HMAC_SHA256'."));
Assert.IsTrue(ex.Message.Contains("EncryptionAlgorithm should be 'AEAD_AES_256_CBC_HMAC_SHA256'. "));
}
}

Expand Down

0 comments on commit a0a646c

Please sign in to comment.