@@ -25,17 +25,16 @@ namespace MongoDB.Driver.Tests.Encryption
25
25
{
26
26
public class CsfleSchemaBuilderTests
27
27
{
28
+ private readonly CollectionNamespace _collectionNamespace = CollectionNamespace . FromFullName ( "medicalRecords.patients" ) ;
28
29
private const string _keyIdString = "6f4af470-00d1-401f-ac39-f45902a0c0c8" ;
29
30
private static Guid _keyId = Guid . Parse ( _keyIdString ) ;
30
31
31
32
[ Fact ]
32
33
public void CsfleSchemaBuilder_works_as_expected ( )
33
34
{
34
- const string collectionName = "medicalRecords.patients" ;
35
-
36
35
var builder = CsfleSchemaBuilder . Create ( schemaBuilder =>
37
36
{
38
- schemaBuilder . Encrypt < Patient > ( collectionName , builder =>
37
+ schemaBuilder . Encrypt < Patient > ( _collectionNamespace , builder =>
39
38
{
40
39
builder
41
40
. EncryptMetadata ( keyId : _keyId )
@@ -67,7 +66,7 @@ public void CsfleSchemaBuilder_works_as_expected()
67
66
68
67
var expected = new Dictionary < string , string >
69
68
{
70
- [ collectionName ] = """
69
+ [ _collectionNamespace . FullName ] = """
71
70
{
72
71
"bsonType": "object",
73
72
"encryptMetadata": {
@@ -145,55 +144,54 @@ public void CsfleSchemaBuilder_works_as_expected()
145
144
[ Fact ]
146
145
public void CsfleSchemaBuilder_with_multiple_types_works_as_expected ( )
147
146
{
148
- const string patientCollectionName = "medicalRecords.patients" ;
149
- const string testClassCollectionName = "test.class" ;
147
+ var testCollectionNamespace = CollectionNamespace . FromFullName ( "test.class" ) ;
150
148
151
149
var builder = CsfleSchemaBuilder . Create ( schemaBuilder =>
152
150
{
153
- schemaBuilder . Encrypt < Patient > ( patientCollectionName , builder =>
151
+ schemaBuilder . Encrypt < Patient > ( _collectionNamespace , builder =>
154
152
{
155
153
builder
156
154
. EncryptMetadata ( keyId : _keyId )
157
155
. Property ( p => p . MedicalRecords , BsonType . Array ,
158
156
EncryptionAlgorithm . AEAD_AES_256_CBC_HMAC_SHA_512_Random ) ;
159
157
} ) ;
160
158
161
- schemaBuilder . Encrypt < TestClass > ( testClassCollectionName , builder =>
159
+ schemaBuilder . Encrypt < TestClass > ( _collectionNamespace , builder =>
162
160
{
163
161
builder . Property ( t => t . TestString , BsonType . String ) ;
164
162
} ) ;
165
163
} ) ;
166
164
167
165
var expected = new Dictionary < string , string >
168
166
{
169
- [ patientCollectionName ] = """
170
- {
171
- "bsonType": "object",
172
- "encryptMetadata": {
173
- "keyId": [{ "$binary" : { "base64" : "b0r0cADRQB+sOfRZAqDAyA==", "subType" : "04" } }]
174
- },
175
- "properties": {
176
- "medicalRecords": {
177
- "encrypt": {
178
- "bsonType": "array",
179
- "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
180
- }
181
- },
182
- },
183
- }
184
- """ ,
185
- [ testClassCollectionName ] = """
186
- {
187
- "bsonType": "object",
188
- "properties": {
189
- "TestString": {
190
- "encrypt": {
191
- "bsonType": "string",
192
- }
193
- },
167
+ [ _collectionNamespace . FullName ] = """
168
+ {
169
+ "bsonType": "object",
170
+ "encryptMetadata": {
171
+ "keyId": [{ "$binary" : { "base64" : "b0r0cADRQB+sOfRZAqDAyA==", "subType" : "04" } }]
172
+ },
173
+ "properties": {
174
+ "medicalRecords": {
175
+ "encrypt": {
176
+ "bsonType": "array",
177
+ "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
178
+ }
179
+ },
180
+ },
181
+ }
182
+ """ ,
183
+ [ testCollectionNamespace . FullName ] = """
184
+ {
185
+ "bsonType": "object",
186
+ "properties": {
187
+ "TestString": {
188
+ "encrypt": {
189
+ "bsonType": "string",
190
+ }
191
+ },
192
+ }
194
193
}
195
- }
196
- """
194
+ """
197
195
} ;
198
196
199
197
AssertOutcomeCsfleSchemaBuilder ( builder , expected ) ;
@@ -277,6 +275,8 @@ public void EncryptedCollection_PatternProperty_works_as_expected(BsonType bsonT
277
275
AssertOutcomeCollectionBuilder ( builder , expected ) ;
278
276
}
279
277
278
+ //TODO Remember about using the same algorithm...
279
+
280
280
[ Theory ]
281
281
[ InlineData ( null ,
282
282
null ,
0 commit comments