Skip to content

Commit 9318348

Browse files
Code review,
1 parent 71e171e commit 9318348

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

src/MongoDB.Driver.Core/Core/Encryption/EncryptedCollectionHelper.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,14 @@ public static IEnumerable<BsonDocument> IterateEmptyKeyIds(CollectionNamespace c
8585

8686
if (storedEncryptedFields.TryGetValue("fields", out var fields) && fields is BsonArray fieldsArray)
8787
{
88-
foreach (var field in fieldsArray)
88+
foreach (var field in fieldsArray.OfType<BsonDocument>()) // If `F` is not a document element, skip it.
8989
{
90-
if (field is BsonDocument fieldDocument)
90+
if (field.TryGetElement("keyId", out var keyId) && keyId.Value == BsonNull.Value)
9191
{
92-
if (fieldDocument.TryGetElement("keyId", out var keyId) && keyId.Value == BsonNull.Value)
93-
{
94-
yield return fieldDocument;
95-
}
96-
}
97-
else
98-
{
99-
// If `F` is not a document element, skip it.
100-
continue;
92+
yield return field;
10193
}
10294
}
10395
}
104-
105-
yield break;
10696
}
10797

10898
public static void ModifyEndryptedFields(BsonDocument fieldDocument, Guid dataKey)

tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/prose-tests/ClientEncryptionProseTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,9 @@ void RunTestCase(int testCase)
133133
case 3: // Case 3: Invalid ``keyId``
134134
{
135135
var effectiveEncryptedFields = encryptedFields.DeepClone();
136-
effectiveEncryptedFields["fields"].AsBsonArray[0].AsBsonDocument["keyId"] = true;
137-
var collection = CreateEncryptedCollection(client, clientEncryption, __collCollectionNamespace, encryptedFields, kmsProvider, async).Collection;
138-
139-
var exception = Record.Exception(() => Insert(collection, async, new BsonDocument("ssn", "123-45-6789")));
140-
exception.Should().BeOfType<MongoBulkWriteException<BsonDocument>>().Which.Message.Should().Contain("Document failed validation");
136+
effectiveEncryptedFields["fields"].AsBsonArray[0].AsBsonDocument["keyId"] = false;
137+
var exception = Record.Exception(() => CreateEncryptedCollection(client, clientEncryption, __collCollectionNamespace, effectiveEncryptedFields.AsBsonDocument, kmsProvider, async));
138+
exception.Should().BeOfType<MongoCommandException>().Which.Message.Should().Contain("BSON field 'create.encryptedFields.fields.keyId' is the wrong type 'bool', expected type 'binData'");
141139
}
142140
break;
143141
default: throw new Exception($"Unexpected test case {testCase}.");

0 commit comments

Comments
 (0)