-
Notifications
You must be signed in to change notification settings - Fork 918
GODRIVER-2529 Return error if a ClientEncryption is used after Close #1785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0d66891
adding test
joyjwang 20c50cc
adding closed field value to ClientEncryption struct and methods
joyjwang eb91123
add unit tests and logic for closing a closed ClientEncryption
joyjwang 01dbf37
ran make to add license
joyjwang dfd7297
edit tests to create a closed ClientEncryption, utilize assert.ErrorI…
joyjwang 6430128
Update mongo/client_encryption_test.go
joyjwang 063497b
add cse flag for build
joyjwang 86254c0
Merge remote-tracking branch 'refs/remotes/origin/GODRIVER-2529' into…
joyjwang b053c1d
ran make check-fmt
joyjwang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (C) MongoDB, Inc. 2024-present. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. You may obtain | ||
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
package mongo | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"go.mongodb.org/mongo-driver/v2/bson" | ||
"go.mongodb.org/mongo-driver/v2/internal/assert" | ||
"go.mongodb.org/mongo-driver/v2/mongo/options" | ||
"go.mongodb.org/mongo-driver/v2/x/mongo/driver" | ||
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/mongocrypt" | ||
) | ||
|
||
func TestClientEncryption_ErrClientDisconnected(t *testing.T) { | ||
joyjwang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
client, _ := Connect(options.Client().ApplyURI("mongodb://test")) | ||
crypt := driver.NewCrypt(&driver.CryptOptions{MongoCrypt: &mongocrypt.MongoCrypt{}}) | ||
|
||
ce := &ClientEncryption{keyVaultClient: client, crypt: crypt} | ||
_ = ce.Close(context.Background()) | ||
|
||
t.Run("CreateEncryptedCollection", func(t *testing.T) { | ||
joyjwang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t.Parallel() | ||
_, _, err := ce.CreateEncryptedCollection(context.Background(), nil, "", options.CreateCollection(), "", nil) | ||
assert.Equal(t, ErrClientDisconnected, err, "expected error %v, got %v", ErrClientDisconnected, err) | ||
assert.ErrorIs(t, err, ErrClientDisconnected) | ||
}) | ||
t.Run("AddKeyAltName", func(t *testing.T) { | ||
t.Parallel() | ||
err := ce.AddKeyAltName(context.Background(), bson.Binary{}, "").err | ||
assert.ErrorIs(t, err, ErrClientDisconnected) | ||
}) | ||
t.Run("CreateDataKey", func(t *testing.T) { | ||
t.Parallel() | ||
_, err := ce.CreateDataKey(context.Background(), "", options.DataKey()) | ||
assert.ErrorIs(t, err, ErrClientDisconnected) | ||
}) | ||
t.Run("Encrypt", func(t *testing.T) { | ||
t.Parallel() | ||
_, err := ce.Encrypt(context.Background(), bson.RawValue{}, options.Encrypt()) | ||
assert.ErrorIs(t, err, ErrClientDisconnected) | ||
}) | ||
t.Run("EncryptExpression", func(t *testing.T) { | ||
t.Parallel() | ||
err := ce.EncryptExpression(context.Background(), nil, nil, options.Encrypt()) | ||
assert.ErrorIs(t, err, ErrClientDisconnected) | ||
}) | ||
t.Run("Decrypt", func(t *testing.T) { | ||
t.Parallel() | ||
_, err := ce.Decrypt(context.Background(), bson.Binary{}) | ||
assert.ErrorIs(t, err, ErrClientDisconnected) | ||
}) | ||
t.Run("Close", func(t *testing.T) { | ||
t.Parallel() | ||
err := ce.Close(context.Background()) | ||
assert.ErrorIs(t, err, ErrClientDisconnected) | ||
}) | ||
t.Run("DeleteKey", func(t *testing.T) { | ||
t.Parallel() | ||
_, err := ce.DeleteKey(context.Background(), bson.Binary{}) | ||
assert.ErrorIs(t, err, ErrClientDisconnected) | ||
}) | ||
t.Run("GetKeyByAltName", func(t *testing.T) { | ||
t.Parallel() | ||
err := ce.GetKeyByAltName(context.Background(), "").err | ||
assert.ErrorIs(t, err, ErrClientDisconnected) | ||
}) | ||
t.Run("GetKey", func(t *testing.T) { | ||
t.Parallel() | ||
err := ce.GetKey(context.Background(), bson.Binary{}).err | ||
assert.ErrorIs(t, err, ErrClientDisconnected) | ||
}) | ||
t.Run("GetKeys", func(t *testing.T) { | ||
t.Parallel() | ||
_, err := ce.GetKeys(context.Background()) | ||
assert.ErrorIs(t, err, ErrClientDisconnected) | ||
}) | ||
t.Run("RemoveKeyAltName", func(t *testing.T) { | ||
t.Parallel() | ||
err := ce.RemoveKeyAltName(context.Background(), bson.Binary{}, "").err | ||
assert.ErrorIs(t, err, ErrClientDisconnected) | ||
}) | ||
t.Run("RewrapManyDataKey", func(t *testing.T) { | ||
t.Parallel() | ||
_, err := ce.RewrapManyDataKey(context.Background(), nil, options.RewrapManyDataKey()) | ||
assert.ErrorIs(t, err, ErrClientDisconnected) | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.