Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions internal/integration/client_side_encryption_prose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3126,16 +3126,36 @@ func TestClientSideEncryptionProse_27_text_explicit_encryption(t *testing.T) {
mt := newCSE_T(t, newQEOpts().MinServerVersion("8.2"))
mt.Setup()

encryptedFields := readJSONFile(mt, "encryptedFields-prefix-suffix.json")
key1Document := readJSONFile(mt, "key1-document.json")
subtype, data := key1Document.Lookup("_id").Binary()
key1ID := bson.Binary{Subtype: subtype, Data: data}

var encryptedColls []struct {
name string
fields bson.Raw
}
if mtest.CompareServerVersions(mtest.ServerVersion(), "9.0.0") < 0 {
encryptedColls = append(encryptedColls, struct {
name string
fields bson.Raw
}{
name: "prefix-suffix",
fields: readJSONFile(mt, "encryptedFields-prefix-suffix.json"),
})
}
encryptedColls = append(encryptedColls, struct {
name string
fields bson.Raw
}{
name: "substring",
fields: readJSONFile(mt, "encryptedFields-substring.json"),
})

testSetup := func() (*mongo.Client, *mongo.ClientEncryption) {
for _, collName := range []string{"prefix-suffix", "substring"} {
mtest.DropEncryptedCollection(mt, mt.Client.Database("db").Collection(collName), encryptedFields)
cco := options.CreateCollection().SetEncryptedFields(encryptedFields)
err := mt.Client.Database("db").CreateCollection(context.Background(), collName, cco)
for _, coll := range encryptedColls {
mtest.DropEncryptedCollection(mt, mt.Client.Database("db").Collection(coll.name), coll.fields)
cco := options.CreateCollection().SetEncryptedFields(coll.fields)
err := mt.Client.Database("db").CreateCollection(context.Background(), coll.name, cco)
require.NoError(mt, err, "error on CreateCollection: %v", err)
}
err := mt.Client.Database("keyvault").Collection("datakeys").Drop(context.Background())
Expand Down Expand Up @@ -3217,7 +3237,7 @@ func TestClientSideEncryptionProse_27_text_explicit_encryption(t *testing.T) {
bar := bson.RawValue{Type: bson.TypeString, Value: bsoncore.AppendString(nil, "bar")}
baz := bson.RawValue{Type: bson.TypeString, Value: bsoncore.AppendString(nil, "baz")}

mt.Run("Case 1: can find a document by prefix", func(mt *mtest.T) {
mt.RunOpts("Case 1: can find a document by prefix", mtest.NewOptions().MaxServerVersion("8.99.99"), func(mt *mtest.T) {
encryptedClient, clientEncryption := testSetup()
defer clientEncryption.Close(context.Background())
defer encryptedClient.Disconnect(context.Background())
Expand Down Expand Up @@ -3254,7 +3274,7 @@ func TestClientSideEncryptionProse_27_text_explicit_encryption(t *testing.T) {
require.Equal(mt, 0, got.Id)
require.Equal(mt, "foobarbaz", got.EncryptedText)
})
mt.Run("Case 2: find a document by suffix", func(mt *mtest.T) {
mt.RunOpts("Case 2: find a document by suffix", mtest.NewOptions().MaxServerVersion("8.99.99"), func(mt *mtest.T) {
encryptedClient, clientEncryption := testSetup()
defer clientEncryption.Close(context.Background())
defer encryptedClient.Disconnect(context.Background())
Expand Down Expand Up @@ -3291,7 +3311,7 @@ func TestClientSideEncryptionProse_27_text_explicit_encryption(t *testing.T) {
require.Equal(mt, 0, got.Id)
require.Equal(mt, "foobarbaz", got.EncryptedText)
})
mt.Run("Case 3: assert no document found by prefix", func(mt *mtest.T) {
mt.RunOpts("Case 3: assert no document found by prefix", mtest.NewOptions().MaxServerVersion("8.99.99"), func(mt *mtest.T) {
encryptedClient, clientEncryption := testSetup()
defer clientEncryption.Close(context.Background())
defer encryptedClient.Disconnect(context.Background())
Expand Down Expand Up @@ -3321,7 +3341,7 @@ func TestClientSideEncryptionProse_27_text_explicit_encryption(t *testing.T) {
}).Raw()
require.Equal(mt, err, mongo.ErrNoDocuments)
})
mt.Run("Case 4: assert no document found by suffix", func(mt *mtest.T) {
mt.RunOpts("Case 4: assert no document found by suffix", mtest.NewOptions().MaxServerVersion("8.99.99"), func(mt *mtest.T) {
encryptedClient, clientEncryption := testSetup()
defer clientEncryption.Close(context.Background())
defer encryptedClient.Disconnect(context.Background())
Expand Down Expand Up @@ -3421,7 +3441,7 @@ func TestClientSideEncryptionProse_27_text_explicit_encryption(t *testing.T) {
}).Raw()
require.Equal(mt, err, mongo.ErrNoDocuments)
})
mt.Run("Case 7: assert contentionFactor is required", func(mt *mtest.T) {
mt.RunOpts("Case 7: assert contentionFactor is required", mtest.NewOptions().MaxServerVersion("8.99.99"), func(mt *mtest.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These commands will change to non-preview on 9.0+, so these tests will not be relevant for 9.0+.

encryptedClient, clientEncryption := testSetup()
defer clientEncryption.Close(context.Background())
defer encryptedClient.Disconnect(context.Background())
Expand Down
Loading