@@ -2455,8 +2455,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
24552455 }
24562456 })
24572457
2458- // GODRIVER-3123. When we implement this feature, lower the min server version to 8.0.1
2459- qeRunOpts22 := qeRunOpts .MaxServerVersion ("7.99.99" )
2458+ qeRunOpts22 := qeRunOpts .MinServerVersion ("8.0" )
24602459 mt .RunOpts ("22. range explicit encryption" , qeRunOpts22 , func (mt * mtest.T ) {
24612460 type testcase struct {
24622461 typeStr string
@@ -2470,6 +2469,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
24702469 twoHundredOne bson.RawValue
24712470 }
24722471
2472+ trimFactor := int32 (1 )
2473+ sparsity := int64 (1 )
24732474 precision := int32 (2 )
24742475
24752476 d128_0 , err := bson .ParseDecimal128 ("0" )
@@ -2497,7 +2498,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
24972498 typeStr : "DecimalNoPrecision" ,
24982499 field : "encryptedDecimalNoPrecision" ,
24992500 typeBson : bson .TypeDecimal128 ,
2500- rangeOpts : options .Range ().SetSparsity (1 ),
2501+ rangeOpts : options .Range ().SetTrimFactor ( trimFactor ). SetSparsity (sparsity ),
25012502 zero : bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_0h , d128_0l )},
25022503 six : bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_6h , d128_6l )},
25032504 thirty : bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_30h , d128_30l )},
@@ -2511,7 +2512,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
25112512 rangeOpts : options .Range ().
25122513 SetMin (bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_0h , d128_0l )}).
25132514 SetMax (bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_200h , d128_200l )}).
2514- SetSparsity (1 ).
2515+ SetTrimFactor (trimFactor ).
2516+ SetSparsity (sparsity ).
25152517 SetPrecision (precision ),
25162518 zero : bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_0h , d128_0l )},
25172519 six : bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_6h , d128_6l )},
@@ -2523,7 +2525,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
25232525 typeStr : "DoubleNoPrecision" ,
25242526 field : "encryptedDoubleNoPrecision" ,
25252527 typeBson : bson .TypeDouble ,
2526- rangeOpts : options .Range ().SetSparsity (1 ),
2528+ rangeOpts : options .Range ().SetTrimFactor ( trimFactor ). SetSparsity (sparsity ),
25272529 zero : bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 0 )},
25282530 six : bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 6 )},
25292531 thirty : bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 30 )},
@@ -2537,7 +2539,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
25372539 rangeOpts : options .Range ().
25382540 SetMin (bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 0 )}).
25392541 SetMax (bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 200 )}).
2540- SetSparsity (1 ).
2542+ SetTrimFactor (trimFactor ).
2543+ SetSparsity (sparsity ).
25412544 SetPrecision (precision ),
25422545 zero : bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 0 )},
25432546 six : bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 6 )},
@@ -2552,7 +2555,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
25522555 rangeOpts : options .Range ().
25532556 SetMin (bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 0 )}).
25542557 SetMax (bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 200 )}).
2555- SetSparsity (1 ),
2558+ SetTrimFactor (trimFactor ).
2559+ SetSparsity (sparsity ),
25562560 zero : bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 0 )},
25572561 six : bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 6 )},
25582562 thirty : bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 30 )},
@@ -2566,7 +2570,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
25662570 rangeOpts : options .Range ().
25672571 SetMin (bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 0 )}).
25682572 SetMax (bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 200 )}).
2569- SetSparsity (1 ),
2573+ SetTrimFactor (trimFactor ).
2574+ SetSparsity (sparsity ),
25702575 zero : bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 0 )},
25712576 six : bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 6 )},
25722577 thirty : bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 30 )},
@@ -2580,7 +2585,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
25802585 rangeOpts : options .Range ().
25812586 SetMin (bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 0 )}).
25822587 SetMax (bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 200 )}).
2583- SetSparsity (1 ),
2588+ SetTrimFactor (trimFactor ).
2589+ SetSparsity (sparsity ),
25842590 zero : bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 0 )},
25852591 six : bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 6 )},
25862592 thirty : bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 30 )},
@@ -2635,7 +2641,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
26352641 // Insert 0, 6, 30, and 200.
26362642 coll := encryptedClient .Database ("db" ).Collection ("explicit_encryption" )
26372643 eo := options .Encrypt ().
2638- SetAlgorithm ("RangePreview " ).
2644+ SetAlgorithm ("Range " ).
26392645 SetKeyID (key1ID ).
26402646 SetContentionFactor (0 ).
26412647 SetRangeOptions (test .rangeOpts )
@@ -2682,7 +2688,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
26822688 defer clientEncryption .Close (context .Background ())
26832689 defer encryptedClient .Disconnect (context .Background ())
26842690 eo := options .Encrypt ().
2685- SetAlgorithm ("RangePreview " ).
2691+ SetAlgorithm ("Range " ).
26862692 SetKeyID (key1ID ).
26872693 SetContentionFactor (0 ).
26882694 SetRangeOptions (test .rangeOpts )
@@ -2698,10 +2704,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
26982704 defer clientEncryption .Close (context .Background ())
26992705 defer encryptedClient .Disconnect (context .Background ())
27002706 eo := options .Encrypt ().
2701- SetAlgorithm ("RangePreview " ).
2707+ SetAlgorithm ("Range " ).
27022708 SetKeyID (key1ID ).
27032709 SetContentionFactor (0 ).
2704- SetQueryType ("rangePreview " ).
2710+ SetQueryType ("range " ).
27052711 SetRangeOptions (test .rangeOpts )
27062712
27072713 expr := bson.M {
@@ -2740,10 +2746,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
27402746 defer clientEncryption .Close (context .Background ())
27412747 defer encryptedClient .Disconnect (context .Background ())
27422748 eo := options .Encrypt ().
2743- SetAlgorithm ("RangePreview " ).
2749+ SetAlgorithm ("Range " ).
27442750 SetKeyID (key1ID ).
27452751 SetContentionFactor (0 ).
2746- SetQueryType ("rangePreview " ).
2752+ SetQueryType ("range " ).
27472753 SetRangeOptions (test .rangeOpts )
27482754
27492755 expr := bson.M {
@@ -2782,10 +2788,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
27822788 defer clientEncryption .Close (context .Background ())
27832789 defer encryptedClient .Disconnect (context .Background ())
27842790 eo := options .Encrypt ().
2785- SetAlgorithm ("RangePreview " ).
2791+ SetAlgorithm ("Range " ).
27862792 SetKeyID (key1ID ).
27872793 SetContentionFactor (0 ).
2788- SetQueryType ("rangePreview " ).
2794+ SetQueryType ("range " ).
27892795 SetRangeOptions (test .rangeOpts )
27902796
27912797 expr := bson.M {
@@ -2819,10 +2825,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
28192825 defer clientEncryption .Close (context .Background ())
28202826 defer encryptedClient .Disconnect (context .Background ())
28212827 eo := options .Encrypt ().
2822- SetAlgorithm ("RangePreview " ).
2828+ SetAlgorithm ("Range " ).
28232829 SetKeyID (key1ID ).
28242830 SetContentionFactor (0 ).
2825- SetQueryType ("rangePreview " ).
2831+ SetQueryType ("range " ).
28262832 SetRangeOptions (test .rangeOpts )
28272833
28282834 expr := bson.M {
@@ -2858,7 +2864,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
28582864 defer clientEncryption .Close (context .Background ())
28592865 defer encryptedClient .Disconnect (context .Background ())
28602866 eo := options .Encrypt ().
2861- SetAlgorithm ("RangePreview " ).
2867+ SetAlgorithm ("Range " ).
28622868 SetKeyID (key1ID ).
28632869 SetContentionFactor (0 ).
28642870 SetRangeOptions (test .rangeOpts )
@@ -2872,7 +2878,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
28722878 defer clientEncryption .Close (context .Background ())
28732879 defer encryptedClient .Disconnect (context .Background ())
28742880 eo := options .Encrypt ().
2875- SetAlgorithm ("RangePreview " ).
2881+ SetAlgorithm ("Range " ).
28762882 SetKeyID (key1ID ).
28772883 SetContentionFactor (0 ).
28782884 SetRangeOptions (test .rangeOpts )
@@ -2899,7 +2905,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
28992905 ro := test .rangeOpts
29002906 ro .SetPrecision (2 )
29012907 eo := options .Encrypt ().
2902- SetAlgorithm ("RangePreview " ).
2908+ SetAlgorithm ("Range " ).
29032909 SetKeyID (key1ID ).
29042910 SetContentionFactor (0 ).
29052911 SetRangeOptions (ro )
@@ -2911,6 +2917,68 @@ func TestClientSideEncryptionProse(t *testing.T) {
29112917 })
29122918 }
29132919 })
2920+
2921+ mt .RunOpts ("22. range explicit encryption applies defaults" , qeRunOpts22 , func (mt * mtest.T ) {
2922+ err := mt .Client .Database ("keyvault" ).Collection ("datakeys" ).Drop (context .Background ())
2923+ assert .Nil (mt , err , "error on Drop: %v" , err )
2924+
2925+ testVal := bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 123 )}
2926+
2927+ keyVaultClient , err := mongo .Connect (options .Client ().ApplyURI (mtest .ClusterURI ()))
2928+ assert .Nil (mt , err , "error on Connect: %v" , err )
2929+
2930+ ceo := options .ClientEncryption ().
2931+ SetKeyVaultNamespace ("keyvault.datakeys" ).
2932+ SetKmsProviders (fullKmsProvidersMap )
2933+ clientEncryption , err := mongo .NewClientEncryption (keyVaultClient , ceo )
2934+ assert .Nil (mt , err , "error on NewClientEncryption: %v" , err )
2935+
2936+ dkOpts := options .DataKey ()
2937+ keyID , err := clientEncryption .CreateDataKey (context .Background (), "local" , dkOpts )
2938+ assert .Nil (mt , err , "error in CreateDataKey: %v" , err )
2939+
2940+ eo := options .Encrypt ().
2941+ SetAlgorithm ("Range" ).
2942+ SetKeyID (keyID ).
2943+ SetContentionFactor (0 ).
2944+ SetRangeOptions (options .Range ().
2945+ SetMin (bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 0 )}).
2946+ SetMax (bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 1000 )}))
2947+ payloadDefaults , err := clientEncryption .Encrypt (context .Background (), testVal , eo )
2948+ assert .Nil (mt , err , "error in Encrypt: %v" , err )
2949+
2950+ mt .Run ("Case 1: uses libmongocrypt defaults" , func (mt * mtest.T ) {
2951+ trimFactor := int32 (6 )
2952+ sparsity := int64 (2 )
2953+ eo := options .Encrypt ().
2954+ SetAlgorithm ("Range" ).
2955+ SetKeyID (keyID ).
2956+ SetContentionFactor (0 ).
2957+ SetRangeOptions (options .Range ().
2958+ SetMin (bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 0 )}).
2959+ SetMax (bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 1000 )}).
2960+ SetTrimFactor (trimFactor ).
2961+ SetSparsity (sparsity ))
2962+ payload , err := clientEncryption .Encrypt (context .Background (), testVal , eo )
2963+ assert .Nil (mt , err , "error in Encrypt: %v" , err )
2964+ assert .Equalf (mt , len (payload .Data ), len (payloadDefaults .Data ), "the returned payload size is expected to be %d" , len (payloadDefaults .Data ))
2965+ })
2966+
2967+ mt .Run ("Case 2: accepts trimFactor 0" , func (mt * mtest.T ) {
2968+ trimFactor := int32 (0 )
2969+ eo := options .Encrypt ().
2970+ SetAlgorithm ("Range" ).
2971+ SetKeyID (keyID ).
2972+ SetContentionFactor (0 ).
2973+ SetRangeOptions (options .Range ().
2974+ SetMin (bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 0 )}).
2975+ SetMax (bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 1000 )}).
2976+ SetTrimFactor (trimFactor ))
2977+ payload , err := clientEncryption .Encrypt (context .Background (), testVal , eo )
2978+ assert .Nil (mt , err , "error in Encrypt: %v" , err )
2979+ assert .Greater (t , len (payload .Data ), len (payloadDefaults .Data ), "the returned payload size is expected to be greater than %d" , len (payloadDefaults .Data ))
2980+ })
2981+ })
29142982}
29152983
29162984func getWatcher (mt * mtest.T , streamType mongo.StreamType , cpt * cseProseTest ) watcher {
0 commit comments