Skip to content

Commit a871c58

Browse files
committed
update unified integration
1 parent 6bf8480 commit a871c58

File tree

9 files changed

+205
-157
lines changed

9 files changed

+205
-157
lines changed

etc/install-libmongocrypt.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This script installs libmongocrypt into an "install" directory.
44
set -eux
55

6-
LIBMONGOCRYPT_TAG="1.12.0"
6+
LIBMONGOCRYPT_TAG="1.15.1"
77

88
# Install libmongocrypt based on OS.
99
if [ "Windows_NT" = "${OS:-}" ]; then

internal/integration/unified/client_entity.go

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ package unified
88

99
import (
1010
"context"
11-
"encoding/base64"
11+
"crypto/tls"
1212
"fmt"
13-
"os"
1413
"strings"
1514
"sync"
1615
"sync/atomic"
@@ -34,19 +33,11 @@ import (
3433
// exceed the default truncation length.
3534
const defaultMaxDocumentLen = 10_000
3635

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

5142
// clientEntity is a wrapper for a mongo.Client object that also holds additional information required during test
5243
// execution.
@@ -288,44 +279,49 @@ func createAutoEncryptionOptions(opts bson.Raw) (*options.AutoEncryptionOptions,
288279
return nil, err
289280
}
290281
for _, elem := range elems {
291-
provider := elem.Key()
292-
providerOpt := elem.Value()
293-
switch provider {
294-
case "aws":
295-
providers["aws"] = map[string]any{
296-
"accessKeyId": awsAccessKeyID,
297-
"secretAccessKey": awsSecretAccessKey,
298-
}
299-
case "azure":
300-
providers["azure"] = map[string]any{
301-
"tenantId": azureTenantID,
302-
"clientId": azureClientID,
303-
"clientSecret": azureClientSecret,
304-
}
305-
case "local":
306-
str := providerOpt.Document().Lookup("key").StringValue()
307-
key, err := base64.StdEncoding.DecodeString(str)
282+
key := elem.Key()
283+
opt := elem.Value().Document()
284+
provider, err := getKmsProvider(key, opt)
285+
if err != nil {
286+
return nil, err
287+
}
288+
if provider == nil {
289+
continue
290+
}
291+
providers[key] = provider
292+
if key == "kmip" && tlsClientCertificateKeyFile != "" && tlsCAFile != "" {
293+
cfg, err := options.BuildTLSConfig(map[string]any{
294+
"tlsCertificateKeyFile": tlsClientCertificateKeyFile,
295+
"tlsCAFile": tlsCAFile,
296+
})
308297
if err != nil {
309-
return nil, err
310-
}
311-
providers["local"] = map[string]any{
312-
"key": key,
298+
return nil, fmt.Errorf("error constructing tls config: %w", err)
313299
}
314-
default:
315-
return nil, fmt.Errorf("unrecognized KMS provider: %v", provider)
300+
aeo.SetTLSConfig(map[string]*tls.Config{
301+
"kmip": cfg,
302+
})
316303
}
317304
}
318305
aeo.SetKmsProviders(providers)
319306
case "schemaMap":
320307
var schemaMap map[string]any
321308
err := bson.Unmarshal(opt.Document(), &schemaMap)
322309
if err != nil {
323-
return nil, err
310+
return nil, fmt.Errorf("error creating schema map: %v", err)
324311
}
325312
aeo.SetSchemaMap(schemaMap)
326313
case "keyVaultNamespace":
327314
kvnsFound = true
328315
aeo.SetKeyVaultNamespace(opt.StringValue())
316+
case "bypassAutoEncryption":
317+
aeo.SetBypassAutoEncryption(opt.Boolean())
318+
case "encryptedFieldsMap":
319+
var encryptedFieldsMap map[string]any
320+
err := bson.Unmarshal(opt.Document(), &encryptedFieldsMap)
321+
if err != nil {
322+
return nil, fmt.Errorf("error creating encryptedFieldsMap: %v", err)
323+
}
324+
aeo.SetEncryptedFieldsMap(encryptedFieldsMap)
329325
case "bypassQueryAnalysis":
330326
aeo.SetBypassQueryAnalysis(opt.Boolean())
331327
default:

internal/integration/unified/collection_data.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ type collectionData struct {
2727
}
2828

2929
type createOptions struct {
30-
Capped *bool `bson:"capped"`
31-
SizeInBytes *int64 `bson:"size"`
32-
EncryptedFields any `bson:"encryptedFields"`
30+
Capped *bool `bson:"capped"`
31+
SizeInBytes *int64 `bson:"size"`
32+
EncryptedFields bson.Raw `bson:"encryptedFields"`
33+
Validator bson.Raw `bson:"validator"`
3334
}
3435

3536
// createCollection configures the collection represented by the receiver using the internal client. This function
@@ -53,6 +54,9 @@ func (c *collectionData) createCollection(ctx context.Context) error {
5354
if c.Options.EncryptedFields != nil {
5455
createOpts = createOpts.SetEncryptedFields(c.Options.EncryptedFields)
5556
}
57+
if c.Options.Validator != nil {
58+
createOpts = createOpts.SetValidator(c.Options.Validator)
59+
}
5660

5761
if err := db.CreateCollection(ctx, c.CollectionName, createOpts); err != nil {
5862
return fmt.Errorf("error creating collection: %w", err)

internal/integration/unified/database_operation_execution.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ func executeCreateCollection(ctx context.Context, operation *operation) (*operat
125125
cco.SetTimeSeriesOptions(tso)
126126
case "clusteredIndex":
127127
cco.SetClusteredIndex(val.Document())
128+
case "validator":
129+
cco.SetValidator(val.Document())
130+
case "encryptedFields":
131+
cco.SetEncryptedFields(val.Document())
128132
default:
129133
return nil, fmt.Errorf("unrecognized createCollection option %q", key)
130134
}
@@ -156,13 +160,17 @@ func executeDropCollection(ctx context.Context, operation *operation) (*operatio
156160
return nil, err
157161
}
158162

163+
dco := options.DropCollection()
164+
159165
var collName string
160166
elems, _ := operation.Arguments.Elements()
161167
for _, elem := range elems {
162168
key := elem.Key()
163169
val := elem.Value()
164170

165171
switch key {
172+
case "encryptedFields":
173+
dco.SetEncryptedFields(val.Document())
166174
case "collection":
167175
collName = val.StringValue()
168176
default:
@@ -173,7 +181,7 @@ func executeDropCollection(ctx context.Context, operation *operation) (*operatio
173181
return nil, newMissingArgumentError("collection")
174182
}
175183

176-
err = db.Collection(collName).Drop(ctx)
184+
err = db.Collection(collName).Drop(ctx, dco)
177185
return newErrorResult(err), nil
178186
}
179187

0 commit comments

Comments
 (0)