49
49
falseBool = false
50
50
)
51
51
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
+
52
91
// RunOnBlock describes a constraint for a test.
53
92
type RunOnBlock struct {
54
93
MinServerVersion string `bson:"minServerVersion"`
@@ -58,7 +97,11 @@ type RunOnBlock struct {
58
97
ServerParameters map [string ]bson.RawValue `bson:"serverParameters"`
59
98
Auth * bool `bson:"auth"`
60
99
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 )
62
105
}
63
106
64
107
// 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 {
73
116
ServerParameters map [string ]bson.RawValue `bson:"serverParameters"`
74
117
Auth * bool `bson:"auth"`
75
118
AuthEnabled * bool `bson:"authEnabled"`
76
- CSFLE * bool `bson:"csfle"`
119
+ CSFLE * CSFLE `bson:"csfle"`
77
120
Extra map [string ]any `bson:",inline"`
78
121
}
79
122
if err := bson .Unmarshal (data , & temp ); err != nil {
0 commit comments