Skip to content

Commit 5637f56

Browse files
committed
update unified integration
1 parent db01901 commit 5637f56

File tree

4 files changed

+78
-24
lines changed

4 files changed

+78
-24
lines changed

internal/integration/mtest/mongotest.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -797,12 +797,6 @@ func verifyRunOnBlockConstraint(rob RunOnBlock) error {
797797
return err
798798
}
799799

800-
// TODO(GODRIVER-3486): Once auto encryption is supported by the unified test
801-
// format,this check should be removed.
802-
if rob.CSFLEEnabled() && rob.CSFLE.Options != nil {
803-
return fmt.Errorf("Auto encryption required (GODRIVER-3486)")
804-
}
805-
806800
if rob.CSFLEEnabled() && !IsCSFLEEnabled() {
807801
return fmt.Errorf("runOnBlock requires CSFLE to be enabled. Build with the cse tag to enable")
808802
} else if !rob.CSFLEEnabled() && IsCSFLEEnabled() {

internal/integration/unified/client_entity.go

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package unified
99
import (
1010
"context"
1111
"fmt"
12+
"os"
1213
"strings"
1314
"sync"
1415
"sync/atomic"
@@ -32,11 +33,16 @@ import (
3233
// exceed the default truncation length.
3334
const defaultMaxDocumentLen = 10_000
3435

35-
// Security-sensitive commands that should be ignored in command monitoring by default.
36-
var securitySensitiveCommands = []string{
37-
"authenticate", "saslStart", "saslContinue", "getnonce",
38-
"createUser", "updateUser", "copydbgetnonce", "copydbsaslstart", "copydb",
39-
}
36+
var (
37+
// Security-sensitive commands that should be ignored in command monitoring by default.
38+
securitySensitiveCommands = []string{
39+
"authenticate", "saslStart", "saslContinue", "getnonce",
40+
"createUser", "updateUser", "copydbgetnonce", "copydbsaslstart", "copydb",
41+
}
42+
43+
awsAccessKeyID = os.Getenv("FLE_AWS_KEY")
44+
awsSecretAccessKey = os.Getenv("FLE_AWS_SECRET")
45+
)
4046

4147
// clientEntity is a wrapper for a mongo.Client object that also holds additional information required during test
4248
// execution.
@@ -217,6 +223,13 @@ func newClientEntity(ctx context.Context, em *EntityMap, entityOptions *entityOp
217223
} else {
218224
integtest.AddTestServerAPIVersion(clientOpts)
219225
}
226+
if entityOptions.AutoEncryptOpts != nil {
227+
aeo, err := createAutoEncryptionOptions(entityOptions.AutoEncryptOpts)
228+
if err != nil {
229+
return nil, fmt.Errorf("error parsing auto encryption options: %w", err)
230+
}
231+
clientOpts.SetAutoEncryptionOptions(aeo)
232+
}
220233
for _, cmd := range entityOptions.IgnoredCommands {
221234
entity.ignoredCommands[cmd] = struct{}{}
222235
}
@@ -251,6 +264,65 @@ func getURIForClient(opts *entityOptions) string {
251264
}
252265
}
253266

267+
func createAutoEncryptionOptions(opts bson.Raw) (*options.AutoEncryptionOptions, error) {
268+
aeo := options.AutoEncryption()
269+
var kvnsFound bool
270+
elems, err := opts.Elements()
271+
if err != nil {
272+
return nil, err
273+
}
274+
275+
for _, elem := range elems {
276+
name := elem.Key()
277+
opt := elem.Value()
278+
279+
switch name {
280+
case "kmsProviders":
281+
providers := make(map[string]map[string]any)
282+
elems, err := opt.Document().Elements()
283+
if err != nil {
284+
return nil, err
285+
}
286+
for _, elem := range elems {
287+
provider := elem.Key()
288+
providerOpt := elem.Value()
289+
switch provider {
290+
case "aws":
291+
providers["aws"] = map[string]any{
292+
"accessKeyId": awsAccessKeyID,
293+
"secretAccessKey": awsSecretAccessKey,
294+
}
295+
case "local":
296+
_, key := providerOpt.Document().Lookup("key").Binary()
297+
providers["local"] = map[string]any{
298+
"key": key,
299+
}
300+
default:
301+
return nil, fmt.Errorf("unrecognized KMS provider: %v", provider)
302+
}
303+
}
304+
aeo.SetKmsProviders(providers)
305+
case "schemaMap":
306+
var schemaMap map[string]any
307+
err := bson.Unmarshal(opt.Document(), &schemaMap)
308+
if err != nil {
309+
return nil, err
310+
}
311+
aeo.SetSchemaMap(schemaMap)
312+
case "keyVaultNamespace":
313+
kvnsFound = true
314+
aeo.SetKeyVaultNamespace(opt.StringValue())
315+
default:
316+
return nil, fmt.Errorf("unrecognized option: %v", name)
317+
}
318+
}
319+
if !kvnsFound {
320+
aeo.SetKeyVaultNamespace("keyvault.datakeys")
321+
}
322+
323+
return aeo, nil
324+
}
325+
254326
// disconnect disconnects the client associated with this entity. It is an
255327
// idempotent operation, unlike the mongo client's disconnect method. This
256328
// property will help avoid unnecessary errors when calling disconnect on a

internal/integration/unified/entity.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type entityOptions struct {
5252
ID string `bson:"id"`
5353

5454
// Options for client entities.
55+
AutoEncryptOpts bson.Raw `bson:"autoEncryptOpts"`
5556
URIOptions bson.M `bson:"uriOptions"`
5657
UseMultipleMongoses *bool `bson:"useMultipleMongoses"`
5758
ObserveEvents []string `bson:"observeEvents"`

internal/spectest/skip.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,6 @@ var skipTests = map[string][]string{
392392
"TestClientSideEncryptionSpec/timeoutMS.json/timeoutMS_applied_to_listCollections_to_get_collection_schema",
393393
},
394394

395-
// TODO(GODRIVER-3486): Support auto encryption in unified tests.
396-
"Support auto encryption in unified tests (GODRIVER-3486)": {
397-
"TestUnifiedSpec/unified-test-format/tests/valid-pass/poc-queryable-encryption.json/insert,_replace,_and_find_with_queryable_encryption",
398-
},
399-
400-
// TODO(DRIVERS-3106): Support auto encryption in unified tests.
401-
"Support auto encryption in unified tests (DRIVERS-3106)": {
402-
"TestUnifiedSpec/client-side-encryption/tests/unified/localSchema.json/A_local_schema_should_override",
403-
"TestUnifiedSpec/client-side-encryption/tests/unified/localSchema.json/A_local_schema_with_no_encryption_is_an_error",
404-
"TestUnifiedSpec/client-side-encryption/tests/unified/fle2v2-BypassQueryAnalysis.json/BypassQueryAnalysis_decrypts",
405-
"TestUnifiedSpec/client-side-encryption/tests/unified/fle2v2-EncryptedFields-vs-EncryptedFieldsMap.json/encryptedFieldsMap_is_preferred_over_remote_encryptedFields",
406-
},
407-
408395
// TODO(GODRIVER-3076): CSFLE/QE Support for more than 1 KMS provider per
409396
// type.
410397
"Support multiple KMS providers per type (GODRIVER-3076)": {

0 commit comments

Comments
 (0)