@@ -2455,8 +2455,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
2455
2455
}
2456
2456
})
2457
2457
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" )
2460
2459
mt .RunOpts ("22. range explicit encryption" , qeRunOpts22 , func (mt * mtest.T ) {
2461
2460
type testcase struct {
2462
2461
typeStr string
@@ -2470,6 +2469,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
2470
2469
twoHundredOne bson.RawValue
2471
2470
}
2472
2471
2472
+ trimFactor := int32 (1 )
2473
+ sparsity := int64 (1 )
2473
2474
precision := int32 (2 )
2474
2475
2475
2476
d128_0 , err := bson .ParseDecimal128 ("0" )
@@ -2497,7 +2498,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
2497
2498
typeStr : "DecimalNoPrecision" ,
2498
2499
field : "encryptedDecimalNoPrecision" ,
2499
2500
typeBson : bson .TypeDecimal128 ,
2500
- rangeOpts : options .Range ().SetSparsity (1 ),
2501
+ rangeOpts : options .Range ().SetTrimFactor ( trimFactor ). SetSparsity (sparsity ),
2501
2502
zero : bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_0h , d128_0l )},
2502
2503
six : bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_6h , d128_6l )},
2503
2504
thirty : bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_30h , d128_30l )},
@@ -2511,7 +2512,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
2511
2512
rangeOpts : options .Range ().
2512
2513
SetMin (bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_0h , d128_0l )}).
2513
2514
SetMax (bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_200h , d128_200l )}).
2514
- SetSparsity (1 ).
2515
+ SetTrimFactor (trimFactor ).
2516
+ SetSparsity (sparsity ).
2515
2517
SetPrecision (precision ),
2516
2518
zero : bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_0h , d128_0l )},
2517
2519
six : bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_6h , d128_6l )},
@@ -2523,7 +2525,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
2523
2525
typeStr : "DoubleNoPrecision" ,
2524
2526
field : "encryptedDoubleNoPrecision" ,
2525
2527
typeBson : bson .TypeDouble ,
2526
- rangeOpts : options .Range ().SetSparsity (1 ),
2528
+ rangeOpts : options .Range ().SetTrimFactor ( trimFactor ). SetSparsity (sparsity ),
2527
2529
zero : bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 0 )},
2528
2530
six : bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 6 )},
2529
2531
thirty : bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 30 )},
@@ -2537,7 +2539,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
2537
2539
rangeOpts : options .Range ().
2538
2540
SetMin (bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 0 )}).
2539
2541
SetMax (bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 200 )}).
2540
- SetSparsity (1 ).
2542
+ SetTrimFactor (trimFactor ).
2543
+ SetSparsity (sparsity ).
2541
2544
SetPrecision (precision ),
2542
2545
zero : bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 0 )},
2543
2546
six : bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 6 )},
@@ -2552,7 +2555,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
2552
2555
rangeOpts : options .Range ().
2553
2556
SetMin (bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 0 )}).
2554
2557
SetMax (bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 200 )}).
2555
- SetSparsity (1 ),
2558
+ SetTrimFactor (trimFactor ).
2559
+ SetSparsity (sparsity ),
2556
2560
zero : bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 0 )},
2557
2561
six : bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 6 )},
2558
2562
thirty : bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 30 )},
@@ -2566,7 +2570,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
2566
2570
rangeOpts : options .Range ().
2567
2571
SetMin (bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 0 )}).
2568
2572
SetMax (bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 200 )}).
2569
- SetSparsity (1 ),
2573
+ SetTrimFactor (trimFactor ).
2574
+ SetSparsity (sparsity ),
2570
2575
zero : bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 0 )},
2571
2576
six : bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 6 )},
2572
2577
thirty : bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 30 )},
@@ -2580,7 +2585,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
2580
2585
rangeOpts : options .Range ().
2581
2586
SetMin (bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 0 )}).
2582
2587
SetMax (bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 200 )}).
2583
- SetSparsity (1 ),
2588
+ SetTrimFactor (trimFactor ).
2589
+ SetSparsity (sparsity ),
2584
2590
zero : bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 0 )},
2585
2591
six : bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 6 )},
2586
2592
thirty : bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 30 )},
@@ -2635,7 +2641,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
2635
2641
// Insert 0, 6, 30, and 200.
2636
2642
coll := encryptedClient .Database ("db" ).Collection ("explicit_encryption" )
2637
2643
eo := options .Encrypt ().
2638
- SetAlgorithm ("RangePreview " ).
2644
+ SetAlgorithm ("Range " ).
2639
2645
SetKeyID (key1ID ).
2640
2646
SetContentionFactor (0 ).
2641
2647
SetRangeOptions (test .rangeOpts )
@@ -2682,7 +2688,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
2682
2688
defer clientEncryption .Close (context .Background ())
2683
2689
defer encryptedClient .Disconnect (context .Background ())
2684
2690
eo := options .Encrypt ().
2685
- SetAlgorithm ("RangePreview " ).
2691
+ SetAlgorithm ("Range " ).
2686
2692
SetKeyID (key1ID ).
2687
2693
SetContentionFactor (0 ).
2688
2694
SetRangeOptions (test .rangeOpts )
@@ -2698,10 +2704,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
2698
2704
defer clientEncryption .Close (context .Background ())
2699
2705
defer encryptedClient .Disconnect (context .Background ())
2700
2706
eo := options .Encrypt ().
2701
- SetAlgorithm ("RangePreview " ).
2707
+ SetAlgorithm ("Range " ).
2702
2708
SetKeyID (key1ID ).
2703
2709
SetContentionFactor (0 ).
2704
- SetQueryType ("rangePreview " ).
2710
+ SetQueryType ("range " ).
2705
2711
SetRangeOptions (test .rangeOpts )
2706
2712
2707
2713
expr := bson.M {
@@ -2740,10 +2746,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
2740
2746
defer clientEncryption .Close (context .Background ())
2741
2747
defer encryptedClient .Disconnect (context .Background ())
2742
2748
eo := options .Encrypt ().
2743
- SetAlgorithm ("RangePreview " ).
2749
+ SetAlgorithm ("Range " ).
2744
2750
SetKeyID (key1ID ).
2745
2751
SetContentionFactor (0 ).
2746
- SetQueryType ("rangePreview " ).
2752
+ SetQueryType ("range " ).
2747
2753
SetRangeOptions (test .rangeOpts )
2748
2754
2749
2755
expr := bson.M {
@@ -2782,10 +2788,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
2782
2788
defer clientEncryption .Close (context .Background ())
2783
2789
defer encryptedClient .Disconnect (context .Background ())
2784
2790
eo := options .Encrypt ().
2785
- SetAlgorithm ("RangePreview " ).
2791
+ SetAlgorithm ("Range " ).
2786
2792
SetKeyID (key1ID ).
2787
2793
SetContentionFactor (0 ).
2788
- SetQueryType ("rangePreview " ).
2794
+ SetQueryType ("range " ).
2789
2795
SetRangeOptions (test .rangeOpts )
2790
2796
2791
2797
expr := bson.M {
@@ -2819,10 +2825,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
2819
2825
defer clientEncryption .Close (context .Background ())
2820
2826
defer encryptedClient .Disconnect (context .Background ())
2821
2827
eo := options .Encrypt ().
2822
- SetAlgorithm ("RangePreview " ).
2828
+ SetAlgorithm ("Range " ).
2823
2829
SetKeyID (key1ID ).
2824
2830
SetContentionFactor (0 ).
2825
- SetQueryType ("rangePreview " ).
2831
+ SetQueryType ("range " ).
2826
2832
SetRangeOptions (test .rangeOpts )
2827
2833
2828
2834
expr := bson.M {
@@ -2858,7 +2864,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
2858
2864
defer clientEncryption .Close (context .Background ())
2859
2865
defer encryptedClient .Disconnect (context .Background ())
2860
2866
eo := options .Encrypt ().
2861
- SetAlgorithm ("RangePreview " ).
2867
+ SetAlgorithm ("Range " ).
2862
2868
SetKeyID (key1ID ).
2863
2869
SetContentionFactor (0 ).
2864
2870
SetRangeOptions (test .rangeOpts )
@@ -2872,7 +2878,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
2872
2878
defer clientEncryption .Close (context .Background ())
2873
2879
defer encryptedClient .Disconnect (context .Background ())
2874
2880
eo := options .Encrypt ().
2875
- SetAlgorithm ("RangePreview " ).
2881
+ SetAlgorithm ("Range " ).
2876
2882
SetKeyID (key1ID ).
2877
2883
SetContentionFactor (0 ).
2878
2884
SetRangeOptions (test .rangeOpts )
@@ -2899,7 +2905,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
2899
2905
ro := test .rangeOpts
2900
2906
ro .SetPrecision (2 )
2901
2907
eo := options .Encrypt ().
2902
- SetAlgorithm ("RangePreview " ).
2908
+ SetAlgorithm ("Range " ).
2903
2909
SetKeyID (key1ID ).
2904
2910
SetContentionFactor (0 ).
2905
2911
SetRangeOptions (ro )
@@ -2911,6 +2917,68 @@ func TestClientSideEncryptionProse(t *testing.T) {
2911
2917
})
2912
2918
}
2913
2919
})
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
+ })
2914
2982
}
2915
2983
2916
2984
func getWatcher (mt * mtest.T , streamType mongo.StreamType , cpt * cseProseTest ) watcher {
0 commit comments