Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 15 additions & 10 deletions internal/integration/mtest/mongotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,18 +816,23 @@ func verifyRunOnBlockConstraint(rob RunOnBlock) error {
return err
}

if rob.CSFLE != nil {
if *rob.CSFLE && !IsCSFLEEnabled() {
return fmt.Errorf("runOnBlock requires CSFLE to be enabled. Build with the cse tag to enable")
} else if !*rob.CSFLE && IsCSFLEEnabled() {
return fmt.Errorf("runOnBlock requires CSFLE to be disabled. Build without the cse tag to disable")
}
if *rob.CSFLE {
if err := verifyVersionConstraints("4.2", ""); err != nil {
return err
}
// TODO(GODRIVER-3486): Once auto encryption is supported by the unified test
// format,this check should be removed.
if rob.CSFLEEnabled() && rob.CSFLE.Options != nil {
return fmt.Errorf("Auto encryption required (GODRIVER-3486)")
}

if rob.CSFLEEnabled() && !IsCSFLEEnabled() {
return fmt.Errorf("runOnBlock requires CSFLE to be enabled. Build with the cse tag to enable")
} else if !rob.CSFLEEnabled() && IsCSFLEEnabled() {
return fmt.Errorf("runOnBlock requires CSFLE to be disabled. Build without the cse tag to disable")
}
if rob.CSFLEEnabled() {
if err := verifyVersionConstraints("4.2", ""); err != nil {
return err
}
}

return nil
}

Expand Down
47 changes: 45 additions & 2 deletions internal/integration/mtest/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,45 @@ var (
falseBool = false
)

// CSFLEOptions holds configuration for Client-Side Field Level Encryption
// (CSFLE).
type CSFLEOptions struct{}

// CSFLE models the runOnRequirements.csfle field in Unified Test Format tests.
//
// The csfle field accepts either:
// - a boolean: true enables CSFLE with no options; false disables CSFLE
// (Options is nil).
// - an object: Options is populated from the document and Boolean is set to
// false.
type CSFLE struct {
Boolean bool
Options *CSFLEOptions
}

// UnmarshalBSON implements custom BSON unmarshalling for CSFLE, accepting
// either a boolean or an embedded document. If a document is provided, Options
// is set and Boolean is false. If a boolean is provided, Boolean is set and
// Options is nil.
func (csfle *CSFLE) UnmarshalBSON(data []byte) error {
embRawValue := bson.RawValue{Type: bson.TypeEmbeddedDocument, Value: data}
if err := embRawValue.Unmarshal(&csfle.Options); err == nil {
csfle.Boolean = false

return nil
}

rawValue := bson.RawValue{Type: bson.TypeBoolean, Value: data}
if b, ok := rawValue.BooleanOK(); ok {
csfle.Boolean = b
csfle.Options = nil

return nil
}

return fmt.Errorf("error unmarshalling CSFLE: %s", data)
}

// RunOnBlock describes a constraint for a test.
type RunOnBlock struct {
MinServerVersion string `bson:"minServerVersion"`
Expand All @@ -58,7 +97,11 @@ type RunOnBlock struct {
ServerParameters map[string]bson.RawValue `bson:"serverParameters"`
Auth *bool `bson:"auth"`
AuthEnabled *bool `bson:"authEnabled"`
CSFLE *bool `bson:"csfle"`
CSFLE *CSFLE `bson:"csfleConfiguration"`
}

func (r *RunOnBlock) CSFLEEnabled() bool {
return r.CSFLE != nil && (r.CSFLE.Boolean || r.CSFLE.Options != nil)
}

// UnmarshalBSON implements custom BSON unmarshalling behavior for RunOnBlock because some test formats use the
Expand All @@ -73,7 +116,7 @@ func (r *RunOnBlock) UnmarshalBSON(data []byte) error {
ServerParameters map[string]bson.RawValue `bson:"serverParameters"`
Auth *bool `bson:"auth"`
AuthEnabled *bool `bson:"authEnabled"`
CSFLE *bool `bson:"csfle"`
CSFLE *CSFLE `bson:"csfle"`
Extra map[string]any `bson:",inline"`
}
if err := bson.Unmarshal(data, &temp); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion testdata/specifications
Submodule specifications updated 213 files
Loading