Skip to content

Commit e036710

Browse files
committed
updates
1 parent 54766aa commit e036710

File tree

7 files changed

+62
-3
lines changed

7 files changed

+62
-3
lines changed

internal/integration/unified/collection_data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type collectionData struct {
2929
type createOptions struct {
3030
Capped *bool `bson:"capped"`
3131
SizeInBytes *int64 `bson:"size"`
32-
EncryptedFields any `bson:"encryptedFields"`
32+
EncryptedFields bson.Raw `bson:"encryptedFields"`
3333
Validator bson.Raw `bson:"validator"`
3434
}
3535

internal/integration/unified/database_operation_execution.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ func executeCreateCollection(ctx context.Context, operation *operation) (*operat
127127
cco.SetClusteredIndex(val.Document())
128128
case "validator":
129129
cco.SetValidator(val.Document())
130+
case "encryptedFields":
131+
cco.SetEncryptedFields(val.Document())
130132
default:
131133
return nil, fmt.Errorf("unrecognized createCollection option %q", key)
132134
}
@@ -158,13 +160,17 @@ func executeDropCollection(ctx context.Context, operation *operation) (*operatio
158160
return nil, err
159161
}
160162

163+
dco := options.DropCollection()
164+
161165
var collName string
162166
elems, _ := operation.Arguments.Elements()
163167
for _, elem := range elems {
164168
key := elem.Key()
165169
val := elem.Value()
166170

167171
switch key {
172+
case "encryptedFields":
173+
dco.SetEncryptedFields(val.Document())
168174
case "collection":
169175
collName = val.StringValue()
170176
default:
@@ -175,7 +181,7 @@ func executeDropCollection(ctx context.Context, operation *operation) (*operatio
175181
return nil, newMissingArgumentError("collection")
176182
}
177183

178-
err = db.Collection(collName).Drop(ctx)
184+
err = db.Collection(collName).Drop(ctx, dco)
179185
return newErrorResult(err), nil
180186
}
181187

internal/integration/unified/entity.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"errors"
1414
"fmt"
1515
"os"
16+
"regexp"
1617
"sync"
1718
"sync/atomic"
1819
"time"
@@ -506,6 +507,24 @@ func (em *EntityMap) close(ctx context.Context) []error {
506507
}
507508
}
508509

510+
// Clear automatically created collections used for queryable encryption
511+
for id, db := range em.dbEntites {
512+
colls, err := db.ListCollectionNames(ctx, bson.D{})
513+
if err != nil {
514+
errs = append(errs, fmt.Errorf("error listing collections in database with ID %q: %w", id, err))
515+
continue
516+
}
517+
for _, coll := range colls {
518+
re := regexp.MustCompile("^enxcol_.*.e(sc|coc)$")
519+
if re.MatchString(coll) {
520+
_, err = db.Collection(coll).DeleteMany(ctx, bson.D{})
521+
if err != nil {
522+
errs = append(errs, fmt.Errorf("error clearing collection %q: %w", coll, err))
523+
}
524+
}
525+
}
526+
}
527+
509528
for id, client := range em.clientEntities {
510529
if ok := em.keyVaultClientIDs[id]; ok {
511530
// Client will be closed in clientEncryption.Close()

internal/integration/unified/error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type clientBulkWriteException struct {
4242
// will perform any other assertions required by the expectedError object. An error is returned if any checks fail.
4343
func verifyOperationError(ctx context.Context, expected *expectedError, result *operationResult) error {
4444
if expected == nil {
45-
if result.Err != nil {
45+
if result != nil && result.Err != nil {
4646
return fmt.Errorf("expected no error, but got %w", result.Err)
4747
}
4848
return nil

internal/integration/unified/matches.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ func verifyValuesMatchInner(ctx context.Context, expected, actual bson.RawValue)
150150
return nil
151151
}
152152

153+
if expected.Type == bson.TypeDecimal128 {
154+
if actual.Type != bson.TypeDecimal128 {
155+
return newMatchingError(keyPath, "expected value to be a decimal type but got a %s", actual.Type)
156+
}
157+
expectedDecimal := expected.Decimal128()
158+
actualDecimal := actual.Decimal128()
159+
eh, el := expectedDecimal.GetBytes()
160+
ah, al := actualDecimal.GetBytes()
161+
if eh != ah || el != al {
162+
return newMatchingError(keyPath, "expected decimal value %v, got %v", expectedDecimal, actualDecimal)
163+
}
164+
return nil
165+
}
153166
// Numeric values must be considered equal even if their types are different (e.g. if expected is an int32 and
154167
// actual is an int64).
155168
if expected.IsNumber() {

internal/integration/unified/operation.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,21 @@ func (op *operation) run(ctx context.Context, loopDone <-chan struct{}) (*operat
275275
case "decrypt":
276276
return executeDecrypt(ctx, op)
277277

278+
case "assertIndexNotExists":
279+
db := lookupString(op.Arguments, "databaseName")
280+
coll := lookupString(op.Arguments, "collectionName")
281+
index := lookupString(op.Arguments, "indexName")
282+
return newErrorResult(nil), verifyIndexExists(ctx, db, coll, index, false)
283+
case "assertIndexExists":
284+
db := lookupString(op.Arguments, "databaseName")
285+
coll := lookupString(op.Arguments, "collectionName")
286+
index := lookupString(op.Arguments, "indexName")
287+
return newErrorResult(nil), verifyIndexExists(ctx, db, coll, index, true)
288+
case "assertCollectionExists":
289+
db := lookupString(op.Arguments, "databaseName")
290+
coll := lookupString(op.Arguments, "collectionName")
291+
return newErrorResult(nil), verifyCollectionExists(ctx, db, coll, true)
292+
278293
// Unsupported operations
279294
case "count", "listIndexNames", "mapReduce":
280295
return nil, newSkipTestError(fmt.Sprintf("the %q operation is not supported", op.Name))

internal/spectest/skip.go

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

395+
// TODO(GODRIVER-3403): Support QE with Client.bulkWrite
396+
"Support QE with Client.bulkWrite (GODRIVER-3403)": {
397+
"TestUnifiedSpec/client-side-encryption/tests/unified/client-bulkWrite-qe.json/client_bulkWrite_QE_replaceOne",
398+
"TestUnifiedSpec/client-side-encryption/tests/unified/client-bulkWrite-qe.json/client_bulkWrite_QE_with_multiple_replace_fails",
399+
},
400+
395401
// TODO(GODRIVER-3076): CSFLE/QE Support for more than 1 KMS provider per
396402
// type.
397403
"Support multiple KMS providers per type (GODRIVER-3076)": {

0 commit comments

Comments
 (0)