-
Notifications
You must be signed in to change notification settings - Fork 896
/
Copy pathclient_side_encryption_prose_test.go
2172 lines (1951 loc) · 90.3 KB
/
client_side_encryption_prose_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (C) MongoDB, Inc. 2017-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
//go:build cse
// +build cse
package integration
import (
"context"
"crypto/tls"
"encoding/base64"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/bsontype"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/event"
"go.mongodb.org/mongo-driver/internal"
"go.mongodb.org/mongo-driver/internal/testutil"
"go.mongodb.org/mongo-driver/internal/testutil/assert"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/integration/mtest"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/writeconcern"
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
)
var (
localMasterKey = []byte("2x44+xduTaBBkY16Er5DuADaghvS4vwdkg8tpPp3tz6gV01A1CwbD9itQ2HFDgPWOp8eMaC1Oi766JzXZBdBdbdMurdonJ1d")
)
const (
clientEncryptionProseDir = "../../testdata/client-side-encryption-prose"
deterministicAlgorithm = "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
randomAlgorithm = "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
kvNamespace = "keyvault.datakeys" // default namespace for the key vault collection
keySubtype byte = 4 // expected subtype for data keys
encryptedValueSubtype byte = 6 // expected subtypes for encrypted values
cryptMaxBatchSizeBytes = 2097152 // max bytes in write batch when auto encryption is enabled
maxBsonObjSize = 16777216 // max bytes in BSON object
)
func TestClientSideEncryptionProse(t *testing.T) {
verifyClientSideEncryptionVarsSet(t)
mt := mtest.New(t, mtest.NewOptions().MinServerVersion("4.2").Enterprise(true).CreateClient(false))
defer mt.Close()
defaultKvClientOptions := options.Client().ApplyURI(mtest.ClusterURI())
testutil.AddTestServerAPIVersion(defaultKvClientOptions)
fullKmsProvidersMap := map[string]map[string]interface{}{
"aws": {
"accessKeyId": awsAccessKeyID,
"secretAccessKey": awsSecretAccessKey,
},
"azure": {
"tenantId": azureTenantID,
"clientId": azureClientID,
"clientSecret": azureClientSecret,
},
"gcp": {
"email": gcpEmail,
"privateKey": gcpPrivateKey,
},
"local": {"key": localMasterKey},
"kmip": {
"endpoint": "localhost:5698",
},
}
runOpts := mtest.NewOptions().MinServerVersion("6.0").Topologies(mtest.ReplicaSet, mtest.LoadBalanced, mtest.ShardedReplicaSet)
mt.Run("1. custom key material test", func(mt *mtest.T) {
const (
dkCollection = "datakeys"
idKey = "_id"
kvDatabase = "keyvault"
)
// Create a ClientEncryption object (referred to as client_encryption) with client set as the keyVaultClient.
// Using client, drop the collection keyvault.datakeys.
cse := setup(mt, nil, defaultKvClientOptions, options.ClientEncryption().
SetKmsProviders(fullKmsProvidersMap).
SetKeyVaultNamespace(kvNamespace))
err := cse.kvClient.Database(kvDatabase).Collection(dkCollection).Drop(context.Background())
assert.Nil(mt, err, "error dropping %q namespace: %v", kvNamespace, err)
// Using client_encryption, create a data key with a local KMS provider and the declared b64 custom key material
// (given as base64).
const b641 = `xPTAjBRG5JiPm+d3fj6XLi2q5DMXUS/f1f+SMAlhhwkhDRL0kr8r9GDLIGTAGlvC+HVjSIgdL+RKwZCvpXSyxTICWSXT` +
`UYsWYPyu3IoHbuBZdmw2faM3WhcRIgbMReU5`
// Decode the base64-encoded keyMaterial string.
km, err := base64.StdEncoding.DecodeString(b641)
assert.Nil(mt, err, "error decoding b64: %v", err)
_, err = cse.clientEnc.CreateDataKey(context.Background(), "local", options.DataKey().SetKeyMaterial(km))
assert.Nil(mt, err, "error creating data key: %v", err)
// Find the resulting key document in keyvault.datakeys, save a copy of the key document, then remove the key
// document from the collection.
coll := cse.kvClient.Database(kvDatabase).Collection(dkCollection)
keydoc, err := coll.FindOne(context.Background(), bson.D{}).DecodeBytes()
assert.Nil(mt, err, "error in decoding bytes: %v", err)
// Remove the key document from the collection.
id, err := keydoc.LookupErr(idKey)
assert.Nil(mt, err, "error looking up %s: %v", idKey, err)
_, err = coll.DeleteOne(context.Background(), bson.D{{idKey, id}})
assert.Nil(mt, err, "error deleting key document: %v", err)
// Replace the _id field in the copied key document with a UUID with base64 value AAAAAAAAAAAAAAAAAAAAAA== (16
// bytes all equal to 0x00) and insert the modified key document into keyvault.datakeys with majority write
// concern.
cidx, alteredKeydoc := bsoncore.AppendDocumentStart(nil)
docElems, _ := keydoc.Elements()
for _, element := range docElems {
if key := element.Key(); key != idKey {
alteredKeydoc = bsoncore.AppendValueElement(alteredKeydoc, key, rawValueToCoreValue(element.Value()))
}
}
empty := [16]byte{}
uuidSubtype, _ := keydoc.Lookup(idKey).Binary()
alteredKeydoc = bsoncore.AppendBinaryElement(alteredKeydoc, idKey, uuidSubtype, empty[:])
alteredKeydoc, _ = bsoncore.AppendDocumentEnd(alteredKeydoc, cidx)
// Insert the copied key document into keyvault.datakeys with majority write concern.
wcMajority := writeconcern.New(writeconcern.WMajority(), writeconcern.WTimeout(1*time.Second))
wcMajorityCollectionOpts := options.Collection().SetWriteConcern(wcMajority)
wcmColl := cse.kvClient.Database(kvDatabase).Collection(dkCollection, wcMajorityCollectionOpts)
_, err = wcmColl.InsertOne(context.Background(), alteredKeydoc)
assert.Nil(mt, err, "error inserting altered key document: %v", err)
// Using client_encryption, encrypt the string "test" with the modified data key using the
// AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic algorithm and assert the resulting value is equal to the
// declared b64 constant.
const b642 = `AQAAAAAAAAAAAAAAAAAAAAACz0ZOLuuhEYi807ZXTdhbqhLaS2/t9wLifJnnNYwiw79d75QYIZ6M/aYC1h9nCzCjZ7pG` +
`UpAuNnkUhnIXM3PjrA==`
empty = [16]byte{}
keyid := primitive.Binary{Subtype: 0x04, Data: empty[:]}
encOpts := options.Encrypt().SetAlgorithm(deterministicAlgorithm).SetKeyID(keyid)
testVal := bson.RawValue{
Type: bson.TypeString,
Value: bsoncore.AppendString(nil, "test"),
}
actual, err := cse.clientEnc.Encrypt(context.Background(), testVal, encOpts)
assert.Nil(mt, err, "error encrypting data: %v", err)
expected := primitive.Binary{Subtype: 0x06}
expected.Data, _ = base64.StdEncoding.DecodeString(b642)
assert.Equal(t, actual, expected, "expected: %v, got: %v", actual, expected)
})
mt.RunOpts("2. data key and double encryption", noClientOpts, func(mt *mtest.T) {
// set up options structs
schema := bson.D{
{"bsonType", "object"},
{"properties", bson.D{
{"encrypted_placeholder", bson.D{
{"encrypt", bson.D{
{"keyId", "/placeholder"},
{"bsonType", "string"},
{"algorithm", "AEAD_AES_256_CBC_HMAC_SHA_512-Random"},
}},
}},
}},
}
schemaMap := map[string]interface{}{"db.coll": schema}
tlsConfig := make(map[string]*tls.Config)
if tlsCAFileKMIP != "" && tlsClientCertificateKeyFileKMIP != "" {
tlsOpts := map[string]interface{}{
"tlsCertificateKeyFile": tlsClientCertificateKeyFileKMIP,
"tlsCAFile": tlsCAFileKMIP,
}
kmipConfig, err := options.BuildTLSConfig(tlsOpts)
assert.Nil(mt, err, "BuildTLSConfig error: %v", err)
tlsConfig["kmip"] = kmipConfig
}
aeo := options.AutoEncryption().
SetKmsProviders(fullKmsProvidersMap).
SetKeyVaultNamespace(kvNamespace).
SetSchemaMap(schemaMap).
SetTLSConfig(tlsConfig).
SetExtraOptions(getCryptSharedLibExtraOptions())
ceo := options.ClientEncryption().
SetKmsProviders(fullKmsProvidersMap).
SetKeyVaultNamespace(kvNamespace).
SetTLSConfig(tlsConfig)
awsMasterKey := bson.D{
{"region", "us-east-1"},
{"key", "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0"},
}
azureMasterKey := bson.D{
{"keyVaultEndpoint", "key-vault-csfle.vault.azure.net"},
{"keyName", "key-name-csfle"},
}
gcpMasterKey := bson.D{
{"projectId", "devprod-drivers"},
{"location", "global"},
{"keyRing", "key-ring-csfle"},
{"keyName", "key-name-csfle"},
}
kmipMasterKey := bson.D{}
testCases := []struct {
provider string
masterKey interface{}
}{
{"local", nil},
{"aws", awsMasterKey},
{"azure", azureMasterKey},
{"gcp", gcpMasterKey},
{"kmip", kmipMasterKey},
}
for _, tc := range testCases {
mt.Run(tc.provider, func(mt *mtest.T) {
if tc.provider == "kmip" && "" == os.Getenv("KMS_MOCK_SERVERS_RUNNING") {
mt.Skipf("Skipping test as KMS_MOCK_SERVERS_RUNNING is not set")
}
var startedEvents []*event.CommandStartedEvent
monitor := &event.CommandMonitor{
Started: func(_ context.Context, evt *event.CommandStartedEvent) {
startedEvents = append(startedEvents, evt)
},
}
kvClientOpts := options.Client().ApplyURI(mtest.ClusterURI()).SetMonitor(monitor)
testutil.AddTestServerAPIVersion(kvClientOpts)
cpt := setup(mt, aeo, kvClientOpts, ceo)
defer cpt.teardown(mt)
// create data key
keyAltName := fmt.Sprintf("%s_altname", tc.provider)
dataKeyOpts := options.DataKey().SetKeyAltNames([]string{keyAltName})
if tc.masterKey != nil {
dataKeyOpts.SetMasterKey(tc.masterKey)
}
dataKeyID, err := cpt.clientEnc.CreateDataKey(context.Background(), tc.provider, dataKeyOpts)
assert.Nil(mt, err, "CreateDataKey error: %v", err)
assert.Equal(mt, keySubtype, dataKeyID.Subtype,
"expected data key subtype %v, got %v", keySubtype, dataKeyID.Subtype)
// assert that the key exists in the key vault
cursor, err := cpt.keyVaultColl.Find(context.Background(), bson.D{{"_id", dataKeyID}})
assert.Nil(mt, err, "key vault Find error: %v", err)
assert.True(mt, cursor.Next(context.Background()), "no keys found in key vault")
provider := cursor.Current.Lookup("masterKey", "provider").StringValue()
assert.Equal(mt, tc.provider, provider, "expected provider %v, got %v", tc.provider, provider)
assert.False(mt, cursor.Next(context.Background()), "unexpected document in key vault: %v", cursor.Current)
// verify that the key was inserted using write concern majority
assert.Equal(mt, 1, len(startedEvents), "expected 1 CommandStartedEvent, got %v", len(startedEvents))
evt := startedEvents[0]
assert.Equal(mt, "insert", evt.CommandName, "expected command 'insert', got '%v'", evt.CommandName)
writeConcernVal, err := evt.Command.LookupErr("writeConcern")
assert.Nil(mt, err, "expected writeConcern in command %s", evt.Command)
wString := writeConcernVal.Document().Lookup("w").StringValue()
assert.Equal(mt, "majority", wString, "expected write concern 'majority', got %v", wString)
// encrypt a value with the new key by ID
valueToEncrypt := fmt.Sprintf("hello %s", tc.provider)
rawVal := bson.RawValue{Type: bson.TypeString, Value: bsoncore.AppendString(nil, valueToEncrypt)}
encrypted, err := cpt.clientEnc.Encrypt(context.Background(), rawVal,
options.Encrypt().SetAlgorithm(deterministicAlgorithm).SetKeyID(dataKeyID))
assert.Nil(mt, err, "Encrypt error while encrypting value by ID: %v", err)
assert.Equal(mt, encryptedValueSubtype, encrypted.Subtype,
"expected encrypted value subtype %v, got %v", encryptedValueSubtype, encrypted.Subtype)
// insert an encrypted value. the value shouldn't be encrypted again because it's not in the schema.
_, err = cpt.cseColl.InsertOne(context.Background(), bson.D{{"_id", tc.provider}, {"value", encrypted}})
assert.Nil(mt, err, "InsertOne error: %v", err)
// find the inserted document. the value should be decrypted automatically
resBytes, err := cpt.cseColl.FindOne(context.Background(), bson.D{{"_id", tc.provider}}).DecodeBytes()
assert.Nil(mt, err, "Find error: %v", err)
foundVal := resBytes.Lookup("value").StringValue()
assert.Equal(mt, valueToEncrypt, foundVal, "expected value %v, got %v", valueToEncrypt, foundVal)
// encrypt a value with an alternate name for the new key
altEncrypted, err := cpt.clientEnc.Encrypt(context.Background(), rawVal,
options.Encrypt().SetAlgorithm(deterministicAlgorithm).SetKeyAltName(keyAltName))
assert.Nil(mt, err, "Encrypt error while encrypting value by alt key name: %v", err)
assert.Equal(mt, encryptedValueSubtype, altEncrypted.Subtype,
"expected encrypted value subtype %v, got %v", encryptedValueSubtype, altEncrypted.Subtype)
assert.Equal(mt, encrypted.Data, altEncrypted.Data,
"expected data %v, got %v", encrypted.Data, altEncrypted.Data)
// insert an encrypted value for an auto-encrypted field
_, err = cpt.cseColl.InsertOne(context.Background(), bson.D{{"encrypted_placeholder", encrypted}})
assert.NotNil(mt, err, "expected InsertOne error, got nil")
})
}
})
mt.RunOpts("3. external key vault", noClientOpts, func(mt *mtest.T) {
testCases := []struct {
name string
externalVault bool
}{
{"with external vault", true},
{"without external vault", false},
}
for _, tc := range testCases {
mt.Run(tc.name, func(mt *mtest.T) {
// setup options structs
kmsProviders := map[string]map[string]interface{}{
"local": {
"key": localMasterKey,
},
}
schemaMap := map[string]interface{}{"db.coll": readJSONFile(mt, "external-schema.json")}
aeo := options.AutoEncryption().
SetKmsProviders(kmsProviders).
SetKeyVaultNamespace(kvNamespace).
SetSchemaMap(schemaMap).
SetExtraOptions(getCryptSharedLibExtraOptions())
ceo := options.ClientEncryption().
SetKmsProviders(kmsProviders).
SetKeyVaultNamespace(kvNamespace)
kvClientOpts := defaultKvClientOptions
if tc.externalVault {
externalKvOpts := options.Client().ApplyURI(mtest.ClusterURI()).SetAuth(options.Credential{
Username: "fake-user",
Password: "fake-password",
})
testutil.AddTestServerAPIVersion(externalKvOpts)
aeo.SetKeyVaultClientOptions(externalKvOpts)
kvClientOpts = externalKvOpts
}
cpt := setup(mt, aeo, kvClientOpts, ceo)
defer cpt.teardown(mt)
// manually insert data key
key := readJSONFile(mt, "external-key.json")
_, err := cpt.keyVaultColl.InsertOne(context.Background(), key)
assert.Nil(mt, err, "InsertOne error for data key: %v", err)
subtype, data := key.Lookup("_id").Binary()
dataKeyID := primitive.Binary{Subtype: subtype, Data: data}
doc := bson.D{{"encrypted", "test"}}
_, insertErr := cpt.cseClient.Database("db").Collection("coll").InsertOne(context.Background(), doc)
rawVal := bson.RawValue{Type: bson.TypeString, Value: bsoncore.AppendString(nil, "test")}
_, encErr := cpt.clientEnc.Encrypt(context.Background(), rawVal,
options.Encrypt().SetKeyID(dataKeyID).SetAlgorithm(deterministicAlgorithm))
if tc.externalVault {
assert.NotNil(mt, insertErr, "expected InsertOne auth error, got nil")
assert.NotNil(mt, encErr, "expected Encrypt auth error, got nil")
assert.True(mt, strings.Contains(insertErr.Error(), "auth error"),
"expected InsertOne auth error, got %v", insertErr)
assert.True(mt, strings.Contains(encErr.Error(), "auth error"),
"expected Encrypt auth error, got %v", insertErr)
return
}
assert.Nil(mt, insertErr, "InsertOne error: %v", insertErr)
assert.Nil(mt, encErr, "Encrypt error: %v", err)
})
}
})
mt.Run("4. bson size limits", func(mt *mtest.T) {
kmsProviders := map[string]map[string]interface{}{
"local": {
"key": localMasterKey,
},
}
aeo := options.AutoEncryption().
SetKmsProviders(kmsProviders).
SetKeyVaultNamespace(kvNamespace).
SetExtraOptions(getCryptSharedLibExtraOptions())
cpt := setup(mt, aeo, nil, nil)
defer cpt.teardown(mt)
// create coll with JSON schema
err := mt.Client.Database("db").RunCommand(context.Background(), bson.D{
{"create", "coll"},
{"validator", bson.D{
{"$jsonSchema", readJSONFile(mt, "limits-schema.json")},
}},
}).Err()
assert.Nil(mt, err, "create error with validator: %v", err)
// insert key
key := readJSONFile(mt, "limits-key.json")
_, err = cpt.keyVaultColl.InsertOne(context.Background(), key)
assert.Nil(mt, err, "InsertOne error for key: %v", err)
var builder2mb, builder16mb strings.Builder
for i := 0; i < cryptMaxBatchSizeBytes; i++ {
builder2mb.WriteByte('a')
}
for i := 0; i < maxBsonObjSize; i++ {
builder16mb.WriteByte('a')
}
complete2mbStr := builder2mb.String()
complete16mbStr := builder16mb.String()
// insert a document over 2MiB
doc := bson.D{{"over_2mib_under_16mib", complete2mbStr}}
_, err = cpt.cseColl.InsertOne(context.Background(), doc)
assert.Nil(mt, err, "InsertOne error for 2MiB document: %v", err)
str := complete2mbStr[:cryptMaxBatchSizeBytes-2000] // remove last 2000 bytes
limitsDoc := readJSONFile(mt, "limits-doc.json")
// insert a doc smaller than 2MiB that is bigger than 2MiB after encryption
var extendedLimitsDoc []byte
extendedLimitsDoc = append(extendedLimitsDoc, limitsDoc...)
extendedLimitsDoc = extendedLimitsDoc[:len(extendedLimitsDoc)-1] // remove last byte to add new fields
extendedLimitsDoc = bsoncore.AppendStringElement(extendedLimitsDoc, "_id", "encryption_exceeds_2mib")
extendedLimitsDoc = bsoncore.AppendStringElement(extendedLimitsDoc, "unencrypted", str)
extendedLimitsDoc, _ = bsoncore.AppendDocumentEnd(extendedLimitsDoc, 0)
_, err = cpt.cseColl.InsertOne(context.Background(), extendedLimitsDoc)
assert.Nil(mt, err, "error inserting extended limits document: %v", err)
// bulk insert two 2MiB documents, each over 2 MiB
// each document should be split into its own batch because the documents are bigger than 2MiB but smaller
// than 16MiB
cpt.cseStarted = cpt.cseStarted[:0]
firstDoc := bson.D{{"_id", "over_2mib_1"}, {"unencrypted", complete2mbStr}}
secondDoc := bson.D{{"_id", "over_2mib_2"}, {"unencrypted", complete2mbStr}}
_, err = cpt.cseColl.InsertMany(context.Background(), []interface{}{firstDoc, secondDoc})
assert.Nil(mt, err, "InsertMany error for small documents: %v", err)
assert.Equal(mt, 2, len(cpt.cseStarted), "expected 2 insert events, got %d", len(cpt.cseStarted))
// bulk insert two documents
str = complete2mbStr[:cryptMaxBatchSizeBytes-20000]
firstBulkDoc := make([]byte, len(limitsDoc))
copy(firstBulkDoc, limitsDoc)
firstBulkDoc = firstBulkDoc[:len(firstBulkDoc)-1] // remove last byte to append new fields
firstBulkDoc = bsoncore.AppendStringElement(firstBulkDoc, "_id", "encryption_exceeds_2mib_1")
firstBulkDoc = bsoncore.AppendStringElement(firstBulkDoc, "unencrypted", string(str))
firstBulkDoc, _ = bsoncore.AppendDocumentEnd(firstBulkDoc, 0)
secondBulkDoc := make([]byte, len(limitsDoc))
copy(secondBulkDoc, limitsDoc)
secondBulkDoc = secondBulkDoc[:len(secondBulkDoc)-1] // remove last byte to append new fields
secondBulkDoc = bsoncore.AppendStringElement(secondBulkDoc, "_id", "encryption_exceeds_2mib_2")
secondBulkDoc = bsoncore.AppendStringElement(secondBulkDoc, "unencrypted", string(str))
secondBulkDoc, _ = bsoncore.AppendDocumentEnd(secondBulkDoc, 0)
cpt.cseStarted = cpt.cseStarted[:0]
_, err = cpt.cseColl.InsertMany(context.Background(), []interface{}{firstBulkDoc, secondBulkDoc})
assert.Nil(mt, err, "InsertMany error for large documents: %v", err)
assert.Equal(mt, 2, len(cpt.cseStarted), "expected 2 insert events, got %d", len(cpt.cseStarted))
// insert a document slightly smaller than 16MiB and expect the operation to succeed
doc = bson.D{{"_id", "under_16mib"}, {"unencrypted", complete16mbStr[:maxBsonObjSize-2000]}}
_, err = cpt.cseColl.InsertOne(context.Background(), doc)
assert.Nil(mt, err, "InsertOne error: %v", err)
// insert a document over 16MiB and expect the operation to fail
var over16mb []byte
over16mb = append(over16mb, limitsDoc...)
over16mb = over16mb[:len(over16mb)-1] // remove last byte
over16mb = bsoncore.AppendStringElement(over16mb, "_id", "encryption_exceeds_16mib")
over16mb = bsoncore.AppendStringElement(over16mb, "unencrypted", complete16mbStr[:maxBsonObjSize-2000])
over16mb, _ = bsoncore.AppendDocumentEnd(over16mb, 0)
_, err = cpt.cseColl.InsertOne(context.Background(), over16mb)
assert.NotNil(mt, err, "expected InsertOne error for document over 16MiB, got nil")
})
mt.Run("5. views are prohibited", func(mt *mtest.T) {
kmsProviders := map[string]map[string]interface{}{
"local": {
"key": localMasterKey,
},
}
aeo := options.AutoEncryption().
SetKmsProviders(kmsProviders).
SetKeyVaultNamespace(kvNamespace).
SetExtraOptions(getCryptSharedLibExtraOptions())
cpt := setup(mt, aeo, nil, nil)
defer cpt.teardown(mt)
// create view on db.coll
mt.CreateCollection(mtest.Collection{
Name: "view",
DB: cpt.cseColl.Database().Name(),
ViewOn: "coll",
ViewPipeline: mongo.Pipeline{},
}, true)
view := cpt.cseColl.Database().Collection("view")
_, err := view.InsertOne(context.Background(), bson.D{{"_id", "insert_on_view"}})
assert.NotNil(mt, err, "expected InsertOne error on view, got nil")
errStr := strings.ToLower(err.Error())
viewErrSubstr := "cannot auto encrypt a view"
assert.True(mt, strings.Contains(errStr, viewErrSubstr),
"expected error '%v' to contain substring '%v'", errStr, viewErrSubstr)
})
mt.RunOpts("6. corpus test", noClientOpts, func(mt *mtest.T) {
if "" == os.Getenv("KMS_MOCK_SERVERS_RUNNING") {
mt.Skipf("Skipping test as KMS_MOCK_SERVERS_RUNNING is not set")
}
corpusSchema := readJSONFile(mt, "corpus-schema.json")
localSchemaMap := map[string]interface{}{
"db.coll": corpusSchema,
}
tlsConfig := make(map[string]*tls.Config)
if tlsCAFileKMIP != "" && tlsClientCertificateKeyFileKMIP != "" {
tlsOpts := map[string]interface{}{
"tlsCertificateKeyFile": tlsClientCertificateKeyFileKMIP,
"tlsCAFile": tlsCAFileKMIP,
}
kmipConfig, err := options.BuildTLSConfig(tlsOpts)
assert.Nil(mt, err, "BuildTLSConfig error: %v", err)
tlsConfig["kmip"] = kmipConfig
}
getBaseAutoEncryptionOpts := func() *options.AutoEncryptionOptions {
return options.AutoEncryption().
SetKmsProviders(fullKmsProvidersMap).
SetKeyVaultNamespace(kvNamespace).
SetTLSConfig(tlsConfig).
SetExtraOptions(getCryptSharedLibExtraOptions())
}
testCases := []struct {
name string
aeo *options.AutoEncryptionOptions
schema bson.Raw // the schema to create the collection. if nil, the collection won't be explicitly created
}{
{"remote schema", getBaseAutoEncryptionOpts(), corpusSchema},
{"local schema", getBaseAutoEncryptionOpts().SetSchemaMap(localSchemaMap), nil},
}
for _, tc := range testCases {
mt.Run(tc.name, func(mt *mtest.T) {
ceo := options.ClientEncryption().
SetKmsProviders(fullKmsProvidersMap).
SetKeyVaultNamespace(kvNamespace).
SetTLSConfig(tlsConfig)
cpt := setup(mt, tc.aeo, defaultKvClientOptions, ceo)
defer cpt.teardown(mt)
// create collection with JSON schema
if tc.schema != nil {
db := cpt.coll.Database()
err := db.RunCommand(context.Background(), bson.D{
{"create", "coll"},
{"validator", bson.D{
{"$jsonSchema", readJSONFile(mt, "corpus-schema.json")},
}},
}).Err()
assert.Nil(mt, err, "create error with validator: %v", err)
}
// Manually insert keys for each KMS provider into the key vault.
_, err := cpt.keyVaultColl.InsertMany(context.Background(), []interface{}{
readJSONFile(mt, "corpus-key-local.json"),
readJSONFile(mt, "corpus-key-aws.json"),
readJSONFile(mt, "corpus-key-azure.json"),
readJSONFile(mt, "corpus-key-gcp.json"),
readJSONFile(mt, "corpus-key-kmip.json"),
})
assert.Nil(mt, err, "InsertMany error for key vault: %v", err)
// read original corpus and recursively copy over each value to new corpus, encrypting certain values
// when needed
corpus := readJSONFile(mt, "corpus.json")
cidx, copied := bsoncore.AppendDocumentStart(nil)
elems, _ := corpus.Elements()
// Keys for top-level non-document elements that should be copied directly.
copiedKeys := map[string]struct{}{
"_id": {},
"altname_aws": {},
"altname_local": {},
"altname_azure": {},
"altname_gcp": {},
"altname_kmip": {},
}
for _, elem := range elems {
key := elem.Key()
val := elem.Value()
if _, ok := copiedKeys[key]; ok {
copied = bsoncore.AppendStringElement(copied, key, val.StringValue())
continue
}
doc := val.Document()
switch method := doc.Lookup("method").StringValue(); method {
case "auto":
// Copy the value directly because it will be auto-encrypted later.
copied = bsoncore.AppendDocumentElement(copied, key, doc)
continue
case "explicit":
// Handled below.
default:
mt.Fatalf("unrecognized 'method' value %q", method)
}
// explicitly encrypt value
algorithm := deterministicAlgorithm
if doc.Lookup("algo").StringValue() == "rand" {
algorithm = randomAlgorithm
}
eo := options.Encrypt().SetAlgorithm(algorithm)
identifier := doc.Lookup("identifier").StringValue()
kms := doc.Lookup("kms").StringValue()
switch identifier {
case "id":
var keyID string
switch kms {
case "local":
keyID = "LOCALAAAAAAAAAAAAAAAAA=="
case "aws":
keyID = "AWSAAAAAAAAAAAAAAAAAAA=="
case "azure":
keyID = "AZUREAAAAAAAAAAAAAAAAA=="
case "gcp":
keyID = "GCPAAAAAAAAAAAAAAAAAAA=="
case "kmip":
keyID = "KMIPAAAAAAAAAAAAAAAAAA=="
default:
mt.Fatalf("unrecognized KMS provider %q", kms)
}
keyIDBytes, err := base64.StdEncoding.DecodeString(keyID)
assert.Nil(mt, err, "base64 DecodeString error: %v", err)
eo.SetKeyID(primitive.Binary{Subtype: 4, Data: keyIDBytes})
case "altname":
eo.SetKeyAltName(kms) // alt name for a key is the same as the KMS name
default:
mt.Fatalf("unrecognized identifier: %v", identifier)
}
// iterate over all elements in the document. copy elements directly, except for ones that need to
// be encrypted, which should be copied after encryption.
var nestedIdx int32
nestedIdx, copied = bsoncore.AppendDocumentElementStart(copied, key)
docElems, _ := doc.Elements()
for _, de := range docElems {
deKey := de.Key()
deVal := de.Value()
// element to encrypt has key "value"
if deKey != "value" {
copied = bsoncore.AppendValueElement(copied, deKey, rawValueToCoreValue(deVal))
continue
}
encrypted, err := cpt.clientEnc.Encrypt(context.Background(), deVal, eo)
if !doc.Lookup("allowed").Boolean() {
// if allowed is false, encryption should error. in this case, the unencrypted value should be
// copied over
assert.NotNil(mt, err, "expected error encrypting value for key %v, got nil", key)
copied = bsoncore.AppendValueElement(copied, deKey, rawValueToCoreValue(deVal))
continue
}
// copy encrypted value
assert.Nil(mt, err, "Encrypt error for key %v: %v", key, err)
copied = bsoncore.AppendBinaryElement(copied, deKey, encrypted.Subtype, encrypted.Data)
}
copied, _ = bsoncore.AppendDocumentEnd(copied, nestedIdx)
}
copied, _ = bsoncore.AppendDocumentEnd(copied, cidx)
// insert document with encrypted values
_, err = cpt.cseColl.InsertOne(context.Background(), copied)
assert.Nil(mt, err, "InsertOne error for corpus document: %v", err)
// find document using client with encryption and assert it matches original
decryptedDoc, err := cpt.cseColl.FindOne(context.Background(), bson.D{}).DecodeBytes()
assert.Nil(mt, err, "Find error with encrypted client: %v", err)
assert.Equal(mt, corpus, decryptedDoc, "expected document %v, got %v", corpus, decryptedDoc)
// find document using a client without encryption enabled and assert fields remain encrypted
corpusEncrypted := readJSONFile(mt, "corpus-encrypted.json")
foundDoc, err := cpt.coll.FindOne(context.Background(), bson.D{}).DecodeBytes()
assert.Nil(mt, err, "Find error with unencrypted client: %v", err)
encryptedElems, _ := corpusEncrypted.Elements()
for _, encryptedElem := range encryptedElems {
// skip non-document fields
encryptedDoc, ok := encryptedElem.Value().DocumentOK()
if !ok {
continue
}
allowed := encryptedDoc.Lookup("allowed").Boolean()
expectedKey := encryptedElem.Key()
expectedVal := encryptedDoc.Lookup("value")
foundVal := foundDoc.Lookup(expectedKey).Document().Lookup("value")
// for deterministic encryption, the value should be exactly equal
// for random encryption, the value should not be equal if allowed is true
algo := encryptedDoc.Lookup("algo").StringValue()
switch algo {
case "det":
assert.True(mt, expectedVal.Equal(foundVal),
"expected value %v for key %v, got %v", expectedVal, expectedKey, foundVal)
case "rand":
if allowed {
assert.False(mt, expectedVal.Equal(foundVal),
"expected values for key %v to be different but were %v", expectedKey, expectedVal)
}
}
// if allowed is true, decrypt both values with clientEnc and validate equality
if allowed {
sub, data := expectedVal.Binary()
expectedDecrypted, err := cpt.clientEnc.Decrypt(context.Background(), primitive.Binary{Subtype: sub, Data: data})
assert.Nil(mt, err, "Decrypt error: %v", err)
sub, data = foundVal.Binary()
actualDecrypted, err := cpt.clientEnc.Decrypt(context.Background(), primitive.Binary{Subtype: sub, Data: data})
assert.Nil(mt, err, "Decrypt error: %v", err)
assert.True(mt, expectedDecrypted.Equal(actualDecrypted),
"expected decrypted value %v for key %v, got %v", expectedDecrypted, expectedKey, actualDecrypted)
continue
}
// if allowed is false, validate found value equals the original value in corpus
corpusVal := corpus.Lookup(expectedKey).Document().Lookup("value")
assert.True(mt, corpusVal.Equal(foundVal),
"expected value %v for key %v, got %v", corpusVal, expectedKey, foundVal)
}
})
}
})
mt.Run("7. custom endpoint", func(mt *mtest.T) {
validKmsProviders := map[string]map[string]interface{}{
"aws": {
"accessKeyId": awsAccessKeyID,
"secretAccessKey": awsSecretAccessKey,
},
"azure": {
"tenantId": azureTenantID,
"clientId": azureClientID,
"clientSecret": azureClientSecret,
"identityPlatformEndpoint": "login.microsoftonline.com:443",
},
"gcp": {
"email": gcpEmail,
"privateKey": gcpPrivateKey,
"endpoint": "oauth2.googleapis.com:443",
},
"kmip": {
"endpoint": "localhost:5698",
},
}
tlsConfig := make(map[string]*tls.Config)
if tlsCAFileKMIP != "" && tlsClientCertificateKeyFileKMIP != "" {
tlsOpts := map[string]interface{}{
"tlsCertificateKeyFile": tlsClientCertificateKeyFileKMIP,
"tlsCAFile": tlsCAFileKMIP,
}
kmipConfig, err := options.BuildTLSConfig(tlsOpts)
assert.Nil(mt, err, "BuildTLSConfig error: %v", err)
tlsConfig["kmip"] = kmipConfig
}
validClientEncryptionOptions := options.ClientEncryption().
SetKmsProviders(validKmsProviders).
SetKeyVaultNamespace(kvNamespace).
SetTLSConfig(tlsConfig)
invalidKmsProviders := map[string]map[string]interface{}{
"azure": {
"tenantId": azureTenantID,
"clientId": azureClientID,
"clientSecret": azureClientSecret,
"identityPlatformEndpoint": "doesnotexist.invalid:443",
},
"gcp": {
"email": gcpEmail,
"privateKey": gcpPrivateKey,
"endpoint": "doesnotexist.invalid:443",
},
"kmip": {
"endpoint": "doesnotexist.local:5698",
},
}
invalidClientEncryptionOptions := options.ClientEncryption().
SetKmsProviders(invalidKmsProviders).
SetKeyVaultNamespace(kvNamespace).
SetTLSConfig(tlsConfig)
awsSuccessWithoutEndpoint := map[string]interface{}{
"region": "us-east-1",
"key": "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
}
awsSuccessWithEndpoint := map[string]interface{}{
"region": "us-east-1",
"key": "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
"endpoint": "kms.us-east-1.amazonaws.com",
}
awsSuccessWithHTTPSEndpoint := map[string]interface{}{
"region": "us-east-1",
"key": "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
"endpoint": "kms.us-east-1.amazonaws.com:443",
}
awsFailureConnectionError := map[string]interface{}{
"region": "us-east-1",
"key": "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
"endpoint": "kms.us-east-1.amazonaws.com:12345",
}
awsFailureInvalidEndpoint := map[string]interface{}{
"region": "us-east-1",
"key": "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
"endpoint": "kms.us-east-2.amazonaws.com",
}
awsFailureParseError := map[string]interface{}{
"region": "us-east-1",
"key": "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
"endpoint": "doesnotexist.invalid",
}
azure := map[string]interface{}{
"keyVaultEndpoint": "key-vault-csfle.vault.azure.net",
"keyName": "key-name-csfle",
}
gcpSuccess := map[string]interface{}{
"projectId": "devprod-drivers",
"location": "global",
"keyRing": "key-ring-csfle",
"keyName": "key-name-csfle",
"endpoint": "cloudkms.googleapis.com:443",
}
gcpFailure := map[string]interface{}{
"projectId": "devprod-drivers",
"location": "global",
"keyRing": "key-ring-csfle",
"keyName": "key-name-csfle",
"endpoint": "doesnotexist.invalid:443",
}
kmipSuccessWithoutEndpoint := map[string]interface{}{
"keyId": "1",
}
kmipSuccessWithEndpoint := map[string]interface{}{
"keyId": "1",
"endpoint": "localhost:5698",
}
kmipFailureInvalidEndpoint := map[string]interface{}{
"keyId": "1",
"endpoint": "doesnotexist.local:5698",
}
testCases := []struct {
name string
provider string
masterKey interface{}
errorSubstring string
testInvalidClientEncryption bool
invalidClientEncryptionErrorSubstring string
}{
{"Case 1: aws success without endpoint", "aws", awsSuccessWithoutEndpoint, "", false, ""},
{"Case 2: aws success with endpoint", "aws", awsSuccessWithEndpoint, "", false, ""},
{"Case 3: aws success with https endpoint", "aws", awsSuccessWithHTTPSEndpoint, "", false, ""},
{"Case 4: aws failure with connection error", "aws", awsFailureConnectionError, "connection refused", false, ""},
{"Case 5: aws failure with wrong endpoint", "aws", awsFailureInvalidEndpoint, "mongocrypt error", false, ""},
{"Case 6: aws failure with parse error", "aws", awsFailureParseError, "no such host", false, ""},
{"Case 7: azure success", "azure", azure, "", true, "no such host"},
{"Case 8: gcp success", "gcp", gcpSuccess, "", true, "no such host"},
{"Case 9: gcp failure", "gcp", gcpFailure, "Invalid KMS response", false, ""},
{"Case 10: kmip success without endpoint", "kmip", kmipSuccessWithoutEndpoint, "", true, "no such host"},
{"Case 11: kmip success with endpoint", "kmip", kmipSuccessWithEndpoint, "", false, ""},
{"Case 12: kmip failure with invalid endpoint", "kmip", kmipFailureInvalidEndpoint, "no such host", false, ""},
}
for _, tc := range testCases {
mt.Run(tc.name, func(mt *mtest.T) {
if strings.Contains(tc.name, "kmip") && "" == os.Getenv("KMS_MOCK_SERVERS_RUNNING") {
mt.Skipf("Skipping test as KMS_MOCK_SERVERS_RUNNING is not set")
}
cpt := setup(mt, nil, defaultKvClientOptions, validClientEncryptionOptions)
defer cpt.teardown(mt)
dkOpts := options.DataKey().SetMasterKey(tc.masterKey)
createdKey, err := cpt.clientEnc.CreateDataKey(context.Background(), tc.provider, dkOpts)
if tc.errorSubstring != "" {
assert.NotNil(mt, err, "expected error, got nil")
errSubstr := tc.errorSubstring
if runtime.GOOS == "windows" && errSubstr == "connection refused" {
// tls.Dial returns an error that does not contain the substring "connection refused"
// on Windows machines
errSubstr = "No connection could be made because the target machine actively refused it"
}
assert.True(mt, strings.Contains(err.Error(), errSubstr),
"expected error '%s' to contain '%s'", err.Error(), errSubstr)
return
}
assert.Nil(mt, err, "CreateDataKey error: %v", err)
encOpts := options.Encrypt().SetKeyID(createdKey).SetAlgorithm(deterministicAlgorithm)
testVal := bson.RawValue{
Type: bson.TypeString,
Value: bsoncore.AppendString(nil, "test"),
}
encrypted, err := cpt.clientEnc.Encrypt(context.Background(), testVal, encOpts)
assert.Nil(mt, err, "Encrypt error: %v", err)
decrypted, err := cpt.clientEnc.Decrypt(context.Background(), encrypted)
assert.Nil(mt, err, "Decrypt error: %v", err)
assert.Equal(mt, testVal, decrypted, "expected value %s, got %s", testVal, decrypted)
if !tc.testInvalidClientEncryption {
return
}
invalidClientEncryption, err := mongo.NewClientEncryption(cpt.kvClient, invalidClientEncryptionOptions)
assert.Nil(mt, err, "error creating invalidClientEncryption object: %v", err)
defer invalidClientEncryption.Close(context.Background())
invalidKeyOpts := options.DataKey().SetMasterKey(tc.masterKey)
_, err = invalidClientEncryption.CreateDataKey(context.Background(), tc.provider, invalidKeyOpts)
assert.NotNil(mt, err, "expected CreateDataKey error, got nil")
assert.True(mt, strings.Contains(err.Error(), tc.invalidClientEncryptionErrorSubstring),
"expected error %v to contain substring '%v'", err, tc.invalidClientEncryptionErrorSubstring)
})
}
})
mt.RunOpts("8. bypass mongocryptd spawning", noClientOpts, func(mt *mtest.T) {
kmsProviders := map[string]map[string]interface{}{
"local": {
"key": localMasterKey,
},
}
schemaMap := map[string]interface{}{
"db.coll": readJSONFile(mt, "external-schema.json"),
}
// All mongocryptd options use port 27021 instead of the default 27020 to avoid interference
// with mongocryptd instances spawned by previous tests. Explicitly disable loading the
// crypt_shared library to make sure we're testing mongocryptd spawning behavior that is not
// influenced by loading the crypt_shared library.
mongocryptdBypassSpawnTrue := map[string]interface{}{
"mongocryptdBypassSpawn": true,
"mongocryptdURI": "mongodb://localhost:27021/db?serverSelectionTimeoutMS=1000",
"mongocryptdSpawnArgs": []string{"--pidfilepath=bypass-spawning-mongocryptd.pid", "--port=27021"},
"__cryptSharedLibDisabledForTestOnly": true, // Disable loading the crypt_shared library.
}
mongocryptdBypassSpawnFalse := map[string]interface{}{
"mongocryptdBypassSpawn": false,
"mongocryptdSpawnArgs": []string{"--pidfilepath=bypass-spawning-mongocryptd.pid", "--port=27021"},
"__cryptSharedLibDisabledForTestOnly": true, // Disable loading the crypt_shared library.
}
mongocryptdBypassSpawnNotSet := map[string]interface{}{
"mongocryptdSpawnArgs": []string{"--pidfilepath=bypass-spawning-mongocryptd.pid", "--port=27021"},
"__cryptSharedLibDisabledForTestOnly": true, // Disable loading the crypt_shared library.
}
testCases := []struct {
name string
mongocryptdOpts map[string]interface{}
setBypassAutoEncryption bool
bypassAutoEncryption bool
bypassQueryAnalysis bool
}{
{
name: "mongocryptdBypassSpawn only",
mongocryptdOpts: mongocryptdBypassSpawnTrue,
},
{
name: "bypassAutoEncryption only",
mongocryptdOpts: mongocryptdBypassSpawnNotSet,
setBypassAutoEncryption: true,
bypassAutoEncryption: true,
},
{
name: "mongocryptdBypassSpawn false, bypassAutoEncryption true",
mongocryptdOpts: mongocryptdBypassSpawnFalse,
setBypassAutoEncryption: true,
bypassAutoEncryption: true,
},
{
name: "mongocryptdBypassSpawn true, bypassAutoEncryption false",
mongocryptdOpts: mongocryptdBypassSpawnTrue,
setBypassAutoEncryption: true,
bypassAutoEncryption: false,
},
{
name: "bypassQueryAnalysis only",
mongocryptdOpts: mongocryptdBypassSpawnNotSet,
bypassQueryAnalysis: true,
},
}
for _, tc := range testCases {
mt.Run(tc.name, func(mt *mtest.T) {