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

Client Encryption : Fixes issue when passing null parameter value in AddParameterAsync. #2507

Merged
merged 2 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
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 @@ -64,9 +64,11 @@ public static async Task<QueryDefinition> AddParameterAsync(
throw new ArgumentNullException(nameof(name));
}

// if null use as-is
if (value == null)
{
throw new ArgumentNullException(nameof(value));
queryDefinition.WithParameter(name, value);
kr-santosh marked this conversation as resolved.
Show resolved Hide resolved
return queryDefinition;
}

QueryDefinition queryDefinitionwithEncryptedValues = queryDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ public async Task EncryptionCreateItemWithNullProperty()

testDoc.Sensitive_ArrayFormat = null;
testDoc.Sensitive_StringFormat = null;
testDoc.Sensitive_NestedObjectFormatL1.Sensitive_NestedObjectFormatL2.Sensitive_StringFormatL2 = null;

ItemResponse<TestDoc> createResponse = await encryptionContainer.CreateItemAsync(
testDoc,
Expand All @@ -356,6 +357,44 @@ public async Task EncryptionCreateItemWithNullProperty()

VerifyExpectedDocResponse(testDoc, createResponse.Resource);

// run query on document with null property value.
QueryDefinition withEncryptedParameter = encryptionContainer.CreateQueryDefinition(
"SELECT * FROM c where c.Sensitive_StringFormat = @Sensitive_StringFormat AND c.Sensitive_ArrayFormat = @Sensitive_ArrayFormat" +
" AND c.Sensitive_IntFormat = @Sensitive_IntFormat" +
" AND c.Sensitive_NestedObjectFormatL1.Sensitive_NestedObjectFormatL2.Sensitive_StringFormatL2 = @Sensitive_StringFormatL2" +
" AND c.Sensitive_NestedObjectFormatL1.Sensitive_NestedObjectFormatL2.Sensitive_DecimalFormatL2 = @Sensitive_DecimalFormatL2");

await withEncryptedParameter.AddParameterAsync(
"@Sensitive_StringFormat",
testDoc.Sensitive_StringFormat,
"/Sensitive_StringFormat");

await withEncryptedParameter.AddParameterAsync(
"@Sensitive_ArrayFormat",
testDoc.Sensitive_ArrayFormat,
"/Sensitive_ArrayFormat");

await withEncryptedParameter.AddParameterAsync(
"@Sensitive_IntFormat",
testDoc.Sensitive_IntFormat,
"/Sensitive_IntFormat");

await withEncryptedParameter.AddParameterAsync(
"@Sensitive_StringFormatL2",
testDoc.Sensitive_NestedObjectFormatL1.Sensitive_NestedObjectFormatL2.Sensitive_StringFormatL2,
"/Sensitive_NestedObjectFormatL1");

await withEncryptedParameter.AddParameterAsync(
"@Sensitive_DecimalFormatL2",
testDoc.Sensitive_NestedObjectFormatL1.Sensitive_NestedObjectFormatL2.Sensitive_DecimalFormatL2,
"/Sensitive_NestedObjectFormatL1");

TestDoc expectedDoc = new TestDoc(testDoc);
await MdeEncryptionTests.ValidateQueryResultsAsync(
encryptionContainer,
queryDefinition: withEncryptedParameter,
expectedDoc: expectedDoc);

// no access to key.
testEncryptionKeyStoreProvider.RevokeAccessSet = true;

Expand Down Expand Up @@ -521,7 +560,7 @@ public async Task QueryOnEncryptedProperties()
TestDoc testDoc1 = await MdeEncryptionTests.MdeCreateItemAsync(MdeEncryptionTests.encryptionContainer);

// string/int
string[] arrayofStringValues = new string[] { testDoc1.Sensitive_StringFormat, "randomValue" };
string[] arrayofStringValues = new string[] { testDoc1.Sensitive_StringFormat, "randomValue", null };

QueryDefinition withEncryptedParameter = MdeEncryptionTests.encryptionContainer.CreateQueryDefinition(
"SELECT * FROM c where array_contains(@Sensitive_StringFormat, c.Sensitive_StringFormat) " +
Expand Down Expand Up @@ -2369,8 +2408,8 @@ private static void VerifyExpectedDocResponse(TestDoc expectedDoc, TestDoc verif
else
{
Assert.AreEqual(
expectedDoc.Sensitive_NestedObjectFormatL1.Sensitive_NestedObjectFormatL2.Sensitive_IntFormatL2,
verifyDoc.Sensitive_NestedObjectFormatL1.Sensitive_NestedObjectFormatL2.Sensitive_IntFormatL2);
expectedDoc.Sensitive_NestedObjectFormatL1.Sensitive_NestedObjectFormatL2.Sensitive_StringFormatL2,
verifyDoc.Sensitive_NestedObjectFormatL1.Sensitive_NestedObjectFormatL2.Sensitive_StringFormatL2);

Assert.AreEqual(
expectedDoc.Sensitive_NestedObjectFormatL1.Sensitive_NestedObjectFormatL2.Sensitive_NestedObjectFormatL3.Sensitive_IntFormatL3,
Expand Down Expand Up @@ -2497,7 +2536,7 @@ public class Sensitive_NestedObjectL1

public class Sensitive_NestedObjectL2
{
public int Sensitive_IntFormatL2 { get; set; }
public string Sensitive_StringFormatL2 { get; set; }
public decimal Sensitive_DecimalFormatL2 { get; set; }
public Sensitive_ArrayData[] Sensitive_ArrayFormatL2 { get; set; }
public Sensitive_NestedObjectL3 Sensitive_NestedObjectFormatL3 { get; set; }
Expand Down Expand Up @@ -2622,7 +2661,7 @@ public static TestDoc Create(string partitionKey = null)
Sensitive_IntFormatL0 = 888,
Sensitive_DecimalFormatL0 = 888.1m,
},
Sensitive_StringArrayMultiType = new string[2] { "sensitivedata1a", "verysensitivedata1a"},
Sensitive_StringArrayMultiType = new string[3] { "sensitivedata1a", "verysensitivedata1a", null},
Sensitive_ArrayMultiTypeDecimalFormat = 10.2m,
Sensitive_IntArrayMultiType = new int[2] { 999, 1000 }
},
Expand Down Expand Up @@ -2683,7 +2722,7 @@ public static TestDoc Create(string partitionKey = null)
},
Sensitive_NestedObjectFormatL2 = new Sensitive_NestedObjectL2()
{
Sensitive_IntFormatL2 = 2000,
Sensitive_StringFormatL2 = "sensitiveData",
Sensitive_DecimalFormatL2 = 2000.1m,
Sensitive_ArrayFormatL2 = new Sensitive_ArrayData[]
{
Expand Down