Skip to content

Commit 7dd2250

Browse files
committed
update unified integration
1 parent 7f41f42 commit 7dd2250

File tree

2 files changed

+78
-5
lines changed

2 files changed

+78
-5
lines changed

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"`

0 commit comments

Comments
 (0)