4949 falseBool = false
5050)
5151
52+ // CSFLEOptions holds configuration for Client-Side Field Level Encryption
53+ // (CSFLE).
54+ type CSFLEOptions struct {}
55+
56+ // CSFLE models the runOnRequirements.csfle field in Unified Test Format tests.
57+ //
58+ // The csfle field accepts either:
59+ // - a boolean: true enables CSFLE with no options; false disables CSFLE
60+ // (Options is nil).
61+ // - an object: Options is populated from the document and Boolean is set to
62+ // false.
63+ type CSFLE struct {
64+ Boolean bool
65+ Options * CSFLEOptions
66+ }
67+
68+ // UnmarshalBSON implements custom BSON unmarshalling for CSFLE, accepting
69+ // either a boolean or an embedded document. If a document is provided, Options
70+ // is set and Boolean is false. If a boolean is provided, Boolean is set and
71+ // Options is nil.
72+ func (csfle * CSFLE ) UnmarshalBSON (data []byte ) error {
73+ embRawValue := bson.RawValue {Type : bson .TypeEmbeddedDocument , Value : data }
74+ if err := embRawValue .Unmarshal (& csfle .Options ); err == nil {
75+ csfle .Boolean = false
76+
77+ return nil
78+ }
79+
80+ rawValue := bson.RawValue {Type : bson .TypeBoolean , Value : data }
81+ if b , ok := rawValue .BooleanOK (); ok {
82+ csfle .Boolean = b
83+ csfle .Options = nil
84+
85+ return nil
86+ }
87+
88+ return fmt .Errorf ("error unmarshalling CSFLE: %s" , data )
89+ }
90+
5291// RunOnBlock describes a constraint for a test.
5392type RunOnBlock struct {
5493 MinServerVersion string `bson:"minServerVersion"`
@@ -58,7 +97,11 @@ type RunOnBlock struct {
5897 ServerParameters map [string ]bson.RawValue `bson:"serverParameters"`
5998 Auth * bool `bson:"auth"`
6099 AuthEnabled * bool `bson:"authEnabled"`
61- CSFLE * bool `bson:"csfle"`
100+ CSFLE * CSFLE `bson:"csfleConfiguration"`
101+ }
102+
103+ func (r * RunOnBlock ) CSFLEEnabled () bool {
104+ return r .CSFLE != nil && (r .CSFLE .Boolean || r .CSFLE .Options != nil )
62105}
63106
64107// UnmarshalBSON implements custom BSON unmarshalling behavior for RunOnBlock because some test formats use the
@@ -73,7 +116,7 @@ func (r *RunOnBlock) UnmarshalBSON(data []byte) error {
73116 ServerParameters map [string ]bson.RawValue `bson:"serverParameters"`
74117 Auth * bool `bson:"auth"`
75118 AuthEnabled * bool `bson:"authEnabled"`
76- CSFLE * bool `bson:"csfle"`
119+ CSFLE * CSFLE `bson:"csfle"`
77120 Extra map [string ]any `bson:",inline"`
78121 }
79122 if err := bson .Unmarshal (data , & temp ); err != nil {
0 commit comments