Skip to content

Commit 4e58f2a

Browse files
committed
update unified integration
1 parent 45e00a6 commit 4e58f2a

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

internal/integration/unified/client_entity.go

Lines changed: 65 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,53 @@ 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, _ := opts.Elements()
271+
272+
for _, elem := range elems {
273+
name := elem.Key()
274+
opt := elem.Value()
275+
276+
switch name {
277+
case "kmsProviders":
278+
providers := make(map[string]map[string]any)
279+
elems, _ := opt.Document().Elements()
280+
for _, elem := range elems {
281+
provider := elem.Key()
282+
switch provider {
283+
case "aws":
284+
providers["aws"] = map[string]any{
285+
"accessKeyId": awsAccessKeyID,
286+
"secretAccessKey": awsSecretAccessKey,
287+
}
288+
default:
289+
return nil, fmt.Errorf("unrecognized KMS provider: %v", provider)
290+
}
291+
}
292+
aeo.SetKmsProviders(providers)
293+
case "schemaMap":
294+
var schemaMap map[string]any
295+
err := bson.Unmarshal(opt.Document(), &schemaMap)
296+
if err != nil {
297+
return nil, err
298+
}
299+
aeo.SetSchemaMap(schemaMap)
300+
case "keyVaultNamespace":
301+
kvnsFound = true
302+
aeo.SetKeyVaultNamespace(opt.StringValue())
303+
default:
304+
return nil, fmt.Errorf("unrecognized option: %v", name)
305+
}
306+
}
307+
if !kvnsFound {
308+
aeo.SetKeyVaultNamespace("keyvault.datakeys")
309+
}
310+
311+
return aeo, nil
312+
}
313+
254314
// disconnect disconnects the client associated with this entity. It is an
255315
// idempotent operation, unlike the mongo client's disconnect method. This
256316
// 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)