-
Notifications
You must be signed in to change notification settings - Fork 919
GODRIVER-3486 Support auto encryption in unified tests. #2240
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ package unified | |
|
|
||
| import ( | ||
| "context" | ||
| "crypto/tls" | ||
| "fmt" | ||
| "strings" | ||
| "sync" | ||
|
|
@@ -217,6 +218,13 @@ func newClientEntity(ctx context.Context, em *EntityMap, entityOptions *entityOp | |
| } else { | ||
| integtest.AddTestServerAPIVersion(clientOpts) | ||
| } | ||
| if entityOptions.AutoEncryptOpts != nil { | ||
| aeo, err := createAutoEncryptionOptions(entityOptions.AutoEncryptOpts) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error parsing auto encryption options: %w", err) | ||
| } | ||
| clientOpts.SetAutoEncryptionOptions(aeo) | ||
| } | ||
| for _, cmd := range entityOptions.IgnoredCommands { | ||
| entity.ignoredCommands[cmd] = struct{}{} | ||
| } | ||
|
|
@@ -251,6 +259,83 @@ func getURIForClient(opts *entityOptions) string { | |
| } | ||
| } | ||
|
|
||
| // TODO(GODRIVER-3726): Need to update the logic to an Unmarshal method. | ||
| func createAutoEncryptionOptions(opts bson.Raw) (*options.AutoEncryptionOptions, error) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] Could we add a TODO(GODRIVER-3726) here to investigate moving this logic to an
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [question] Can the analogue in integration/json_helpers_test.go be removed? Can we remove all support for auto encryption in the legacy runner?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can keep it until the legacy tests are completely eliminated to avoid handling logic fractions. |
||
| aeo := options.AutoEncryption() | ||
| var kvnsFound bool | ||
| elems, err := opts.Elements() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for _, elem := range elems { | ||
| name := elem.Key() | ||
| opt := elem.Value() | ||
|
|
||
| switch name { | ||
| case "kmsProviders": | ||
| providers := make(map[string]map[string]any) | ||
| elems, err := opt.Document().Elements() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| for _, elem := range elems { | ||
| key := elem.Key() | ||
| opt := elem.Value().Document() | ||
| provider, err := getKmsProvider(key, opt) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if provider == nil { | ||
| continue | ||
| } | ||
| providers[key] = provider | ||
| if key == "kmip" && tlsClientCertificateKeyFile != "" && tlsCAFile != "" { | ||
| cfg, err := options.BuildTLSConfig(map[string]any{ | ||
| "tlsCertificateKeyFile": tlsClientCertificateKeyFile, | ||
| "tlsCAFile": tlsCAFile, | ||
| }) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error constructing tls config: %w", err) | ||
| } | ||
| aeo.SetTLSConfig(map[string]*tls.Config{ | ||
| "kmip": cfg, | ||
| }) | ||
| } | ||
| } | ||
| aeo.SetKmsProviders(providers) | ||
| case "schemaMap": | ||
| var schemaMap map[string]any | ||
| err := bson.Unmarshal(opt.Document(), &schemaMap) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error creating schema map: %v", err) | ||
| } | ||
| aeo.SetSchemaMap(schemaMap) | ||
| case "keyVaultNamespace": | ||
| kvnsFound = true | ||
| aeo.SetKeyVaultNamespace(opt.StringValue()) | ||
| case "bypassAutoEncryption": | ||
| aeo.SetBypassAutoEncryption(opt.Boolean()) | ||
| case "encryptedFieldsMap": | ||
| var encryptedFieldsMap map[string]any | ||
| err := bson.Unmarshal(opt.Document(), &encryptedFieldsMap) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error creating encryptedFieldsMap: %v", err) | ||
| } | ||
| aeo.SetEncryptedFieldsMap(encryptedFieldsMap) | ||
| case "bypassQueryAnalysis": | ||
| aeo.SetBypassQueryAnalysis(opt.Boolean()) | ||
| default: | ||
| return nil, fmt.Errorf("unrecognized option: %v", name) | ||
| } | ||
| } | ||
| if !kvnsFound { | ||
| aeo.SetKeyVaultNamespace("keyvault.datakeys") | ||
| } | ||
|
|
||
| return aeo, nil | ||
| } | ||
|
|
||
| // disconnect disconnects the client associated with this entity. It is an | ||
| // idempotent operation, unlike the mongo client's disconnect method. This | ||
| // property will help avoid unnecessary errors when calling disconnect on a | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
csflelogically is enabled when it contains a document of properties.