Skip to content

Commit f2113d4

Browse files
committed
update unified integration
1 parent d17ef8b commit f2113d4

File tree

10 files changed

+262
-145
lines changed

10 files changed

+262
-145
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/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: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package unified
88

99
import (
1010
"context"
11+
"crypto/tls"
1112
"fmt"
1213
"strings"
1314
"sync"
@@ -217,6 +218,13 @@ func newClientEntity(ctx context.Context, em *EntityMap, entityOptions *entityOp
217218
} else {
218219
integtest.AddTestServerAPIVersion(clientOpts)
219220
}
221+
if entityOptions.AutoEncryptOpts != nil {
222+
aeo, err := createAutoEncryptionOptions(entityOptions.AutoEncryptOpts)
223+
if err != nil {
224+
return nil, fmt.Errorf("error parsing auto encryption options: %w", err)
225+
}
226+
clientOpts.SetAutoEncryptionOptions(aeo)
227+
}
220228
for _, cmd := range entityOptions.IgnoredCommands {
221229
entity.ignoredCommands[cmd] = struct{}{}
222230
}
@@ -251,6 +259,82 @@ func getURIForClient(opts *entityOptions) string {
251259
}
252260
}
253261

262+
func createAutoEncryptionOptions(opts bson.Raw) (*options.AutoEncryptionOptions, error) {
263+
aeo := options.AutoEncryption()
264+
var kvnsFound bool
265+
elems, err := opts.Elements()
266+
if err != nil {
267+
return nil, err
268+
}
269+
270+
for _, elem := range elems {
271+
name := elem.Key()
272+
opt := elem.Value()
273+
274+
switch name {
275+
case "kmsProviders":
276+
providers := make(map[string]map[string]any)
277+
elems, err := opt.Document().Elements()
278+
if err != nil {
279+
return nil, err
280+
}
281+
for _, elem := range elems {
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+
})
297+
if err != nil {
298+
return nil, fmt.Errorf("error constructing tls config: %w", err)
299+
}
300+
aeo.SetTLSConfig(map[string]*tls.Config{
301+
"kmip": cfg,
302+
})
303+
}
304+
}
305+
aeo.SetKmsProviders(providers)
306+
case "schemaMap":
307+
var schemaMap map[string]any
308+
err := bson.Unmarshal(opt.Document(), &schemaMap)
309+
if err != nil {
310+
return nil, fmt.Errorf("error creating schema map: %v", err)
311+
}
312+
aeo.SetSchemaMap(schemaMap)
313+
case "keyVaultNamespace":
314+
kvnsFound = true
315+
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)
325+
case "bypassQueryAnalysis":
326+
aeo.SetBypassQueryAnalysis(opt.Boolean())
327+
default:
328+
return nil, fmt.Errorf("unrecognized option: %v", name)
329+
}
330+
}
331+
if !kvnsFound {
332+
aeo.SetKeyVaultNamespace("keyvault.datakeys")
333+
}
334+
335+
return aeo, nil
336+
}
337+
254338
// disconnect disconnects the client associated with this entity. It is an
255339
// idempotent operation, unlike the mongo client's disconnect method. This
256340
// property will help avoid unnecessary errors when calling disconnect on a

internal/integration/unified/collection_data.go

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

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

3436
// createCollection configures the collection represented by the receiver using the internal client. This function
@@ -49,14 +51,18 @@ func (c *collectionData) createCollection(ctx context.Context) error {
4951
if c.Options.SizeInBytes != nil {
5052
createOpts = createOpts.SetSizeInBytes(*c.Options.SizeInBytes)
5153
}
54+
if c.Options.EncryptedFields != nil {
55+
createOpts = createOpts.SetEncryptedFields(c.Options.EncryptedFields)
56+
}
57+
if c.Options.Validator != nil {
58+
createOpts = createOpts.SetValidator(c.Options.Validator)
59+
}
5260

5361
if err := db.CreateCollection(ctx, c.CollectionName, createOpts); err != nil {
5462
return fmt.Errorf("error creating collection: %w", err)
5563
}
56-
}
57-
58-
// If neither documents nor options are provided, still create the collection with write concern "majority".
59-
if len(c.Documents) == 0 && c.Options == nil {
64+
} else {
65+
// If options are provided, still create the collection with write concern "majority".
6066
// The write concern has to be manually specified in the command document because RunCommand does not honor
6167
// the database's write concern.
6268
create := bson.D{
@@ -68,13 +74,15 @@ func (c *collectionData) createCollection(ctx context.Context) error {
6874
if err := db.RunCommand(ctx, create).Err(); err != nil {
6975
return fmt.Errorf("error creating collection: %w", err)
7076
}
71-
return nil
7277
}
7378

74-
docs := bsonutil.RawToInterfaces(c.Documents...)
75-
if _, err := coll.InsertMany(ctx, docs); err != nil {
76-
return fmt.Errorf("error inserting data: %w", err)
79+
if len(c.Documents) != 0 {
80+
docs := bsonutil.RawToInterfaces(c.Documents...)
81+
if _, err := coll.InsertMany(ctx, docs); err != nil {
82+
return fmt.Errorf("error inserting data: %w", err)
83+
}
7784
}
85+
7886
return nil
7987
}
8088

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)