@@ -2465,8 +2465,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
2465
2465
}
2466
2466
})
2467
2467
2468
- // GODRIVER-3123. When we implement this feature, lower the min server version to 8.0.1
2469
- qeRunOpts22 := qeRunOpts .MaxServerVersion ("7.99.99" )
2468
+ qeRunOpts22 := qeRunOpts .MinServerVersion ("8.0" )
2470
2469
mt .RunOpts ("22. range explicit encryption" , qeRunOpts22 , func (mt * mtest.T ) {
2471
2470
type testcase struct {
2472
2471
typeStr string
@@ -2480,6 +2479,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
2480
2479
twoHundredOne bson.RawValue
2481
2480
}
2482
2481
2482
+ trimFactor := int32 (1 )
2483
+ sparsity := int64 (1 )
2483
2484
precision := int32 (2 )
2484
2485
2485
2486
d128_0 , err := primitive .ParseDecimal128 ("0" )
@@ -2499,7 +2500,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
2499
2500
field : "encryptedDecimalNoPrecision" ,
2500
2501
typeBson : bson .TypeDecimal128 ,
2501
2502
rangeOpts : options.RangeOptions {
2502
- Sparsity : 1 ,
2503
+ TrimFactor : & trimFactor ,
2504
+ Sparsity : & sparsity ,
2503
2505
},
2504
2506
zero : bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_0 )},
2505
2507
six : bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_6 )},
@@ -2512,10 +2514,11 @@ func TestClientSideEncryptionProse(t *testing.T) {
2512
2514
field : "encryptedDecimalPrecision" ,
2513
2515
typeBson : bson .TypeDecimal128 ,
2514
2516
rangeOpts : options.RangeOptions {
2515
- Min : & bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_0 )},
2516
- Max : & bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_200 )},
2517
- Sparsity : 1 ,
2518
- Precision : & precision ,
2517
+ Min : & bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_0 )},
2518
+ Max : & bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_200 )},
2519
+ TrimFactor : & trimFactor ,
2520
+ Sparsity : & sparsity ,
2521
+ Precision : & precision ,
2519
2522
},
2520
2523
zero : bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_0 )},
2521
2524
six : bson.RawValue {Type : bson .TypeDecimal128 , Value : bsoncore .AppendDecimal128 (nil , d128_6 )},
@@ -2528,7 +2531,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
2528
2531
field : "encryptedDoubleNoPrecision" ,
2529
2532
typeBson : bson .TypeDouble ,
2530
2533
rangeOpts : options.RangeOptions {
2531
- Sparsity : 1 ,
2534
+ TrimFactor : & trimFactor ,
2535
+ Sparsity : & sparsity ,
2532
2536
},
2533
2537
zero : bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 0 )},
2534
2538
six : bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 6 )},
@@ -2541,10 +2545,11 @@ func TestClientSideEncryptionProse(t *testing.T) {
2541
2545
field : "encryptedDoublePrecision" ,
2542
2546
typeBson : bson .TypeDouble ,
2543
2547
rangeOpts : options.RangeOptions {
2544
- Min : & bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 0 )},
2545
- Max : & bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 200 )},
2546
- Sparsity : 1 ,
2547
- Precision : & precision ,
2548
+ Min : & bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 0 )},
2549
+ Max : & bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 200 )},
2550
+ TrimFactor : & trimFactor ,
2551
+ Sparsity : & sparsity ,
2552
+ Precision : & precision ,
2548
2553
},
2549
2554
zero : bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 0 )},
2550
2555
six : bson.RawValue {Type : bson .TypeDouble , Value : bsoncore .AppendDouble (nil , 6 )},
@@ -2557,9 +2562,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
2557
2562
field : "encryptedDate" ,
2558
2563
typeBson : bson .TypeDateTime ,
2559
2564
rangeOpts : options.RangeOptions {
2560
- Min : & bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 0 )},
2561
- Max : & bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 200 )},
2562
- Sparsity : 1 ,
2565
+ Min : & bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 0 )},
2566
+ Max : & bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 200 )},
2567
+ TrimFactor : & trimFactor ,
2568
+ Sparsity : & sparsity ,
2563
2569
},
2564
2570
zero : bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 0 )},
2565
2571
six : bson.RawValue {Type : bson .TypeDateTime , Value : bsoncore .AppendDateTime (nil , 6 )},
@@ -2572,9 +2578,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
2572
2578
field : "encryptedInt" ,
2573
2579
typeBson : bson .TypeInt32 ,
2574
2580
rangeOpts : options.RangeOptions {
2575
- Min : & bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 0 )},
2576
- Max : & bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 200 )},
2577
- Sparsity : 1 ,
2581
+ Min : & bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 0 )},
2582
+ Max : & bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 200 )},
2583
+ TrimFactor : & trimFactor ,
2584
+ Sparsity : & sparsity ,
2578
2585
},
2579
2586
zero : bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 0 )},
2580
2587
six : bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 6 )},
@@ -2587,9 +2594,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
2587
2594
field : "encryptedLong" ,
2588
2595
typeBson : bson .TypeInt64 ,
2589
2596
rangeOpts : options.RangeOptions {
2590
- Min : & bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 0 )},
2591
- Max : & bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 200 )},
2592
- Sparsity : 1 ,
2597
+ Min : & bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 0 )},
2598
+ Max : & bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 200 )},
2599
+ TrimFactor : & trimFactor ,
2600
+ Sparsity : & sparsity ,
2593
2601
},
2594
2602
zero : bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 0 )},
2595
2603
six : bson.RawValue {Type : bson .TypeInt64 , Value : bsoncore .AppendInt64 (nil , 6 )},
@@ -2645,7 +2653,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
2645
2653
// Insert 0, 6, 30, and 200.
2646
2654
coll := encryptedClient .Database ("db" ).Collection ("explicit_encryption" )
2647
2655
eo := options .Encrypt ().
2648
- SetAlgorithm ("RangePreview " ).
2656
+ SetAlgorithm ("Range " ).
2649
2657
SetKeyID (key1ID ).
2650
2658
SetContentionFactor (0 ).
2651
2659
SetRangeOptions (test .rangeOpts )
@@ -2692,7 +2700,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
2692
2700
defer clientEncryption .Close (context .Background ())
2693
2701
defer encryptedClient .Disconnect (context .Background ())
2694
2702
eo := options .Encrypt ().
2695
- SetAlgorithm ("RangePreview " ).
2703
+ SetAlgorithm ("Range " ).
2696
2704
SetKeyID (key1ID ).
2697
2705
SetContentionFactor (0 ).
2698
2706
SetRangeOptions (test .rangeOpts )
@@ -2708,10 +2716,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
2708
2716
defer clientEncryption .Close (context .Background ())
2709
2717
defer encryptedClient .Disconnect (context .Background ())
2710
2718
eo := options .Encrypt ().
2711
- SetAlgorithm ("RangePreview " ).
2719
+ SetAlgorithm ("Range " ).
2712
2720
SetKeyID (key1ID ).
2713
2721
SetContentionFactor (0 ).
2714
- SetQueryType ("rangePreview " ).
2722
+ SetQueryType ("range " ).
2715
2723
SetRangeOptions (test .rangeOpts )
2716
2724
2717
2725
expr := bson.M {
@@ -2750,10 +2758,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
2750
2758
defer clientEncryption .Close (context .Background ())
2751
2759
defer encryptedClient .Disconnect (context .Background ())
2752
2760
eo := options .Encrypt ().
2753
- SetAlgorithm ("RangePreview " ).
2761
+ SetAlgorithm ("Range " ).
2754
2762
SetKeyID (key1ID ).
2755
2763
SetContentionFactor (0 ).
2756
- SetQueryType ("rangePreview " ).
2764
+ SetQueryType ("range " ).
2757
2765
SetRangeOptions (test .rangeOpts )
2758
2766
2759
2767
expr := bson.M {
@@ -2792,10 +2800,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
2792
2800
defer clientEncryption .Close (context .Background ())
2793
2801
defer encryptedClient .Disconnect (context .Background ())
2794
2802
eo := options .Encrypt ().
2795
- SetAlgorithm ("RangePreview " ).
2803
+ SetAlgorithm ("Range " ).
2796
2804
SetKeyID (key1ID ).
2797
2805
SetContentionFactor (0 ).
2798
- SetQueryType ("rangePreview " ).
2806
+ SetQueryType ("range " ).
2799
2807
SetRangeOptions (test .rangeOpts )
2800
2808
2801
2809
expr := bson.M {
@@ -2829,10 +2837,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
2829
2837
defer clientEncryption .Close (context .Background ())
2830
2838
defer encryptedClient .Disconnect (context .Background ())
2831
2839
eo := options .Encrypt ().
2832
- SetAlgorithm ("RangePreview " ).
2840
+ SetAlgorithm ("Range " ).
2833
2841
SetKeyID (key1ID ).
2834
2842
SetContentionFactor (0 ).
2835
- SetQueryType ("rangePreview " ).
2843
+ SetQueryType ("range " ).
2836
2844
SetRangeOptions (test .rangeOpts )
2837
2845
2838
2846
expr := bson.M {
@@ -2868,7 +2876,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
2868
2876
defer clientEncryption .Close (context .Background ())
2869
2877
defer encryptedClient .Disconnect (context .Background ())
2870
2878
eo := options .Encrypt ().
2871
- SetAlgorithm ("RangePreview " ).
2879
+ SetAlgorithm ("Range " ).
2872
2880
SetKeyID (key1ID ).
2873
2881
SetContentionFactor (0 ).
2874
2882
SetRangeOptions (test .rangeOpts )
@@ -2882,7 +2890,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
2882
2890
defer clientEncryption .Close (context .Background ())
2883
2891
defer encryptedClient .Disconnect (context .Background ())
2884
2892
eo := options .Encrypt ().
2885
- SetAlgorithm ("RangePreview " ).
2893
+ SetAlgorithm ("Range " ).
2886
2894
SetKeyID (key1ID ).
2887
2895
SetContentionFactor (0 ).
2888
2896
SetRangeOptions (test .rangeOpts )
@@ -2909,7 +2917,7 @@ func TestClientSideEncryptionProse(t *testing.T) {
2909
2917
ro := test .rangeOpts
2910
2918
ro .SetPrecision (2 )
2911
2919
eo := options .Encrypt ().
2912
- SetAlgorithm ("RangePreview " ).
2920
+ SetAlgorithm ("Range " ).
2913
2921
SetKeyID (key1ID ).
2914
2922
SetContentionFactor (0 ).
2915
2923
SetRangeOptions (ro )
@@ -2921,6 +2929,71 @@ func TestClientSideEncryptionProse(t *testing.T) {
2921
2929
})
2922
2930
}
2923
2931
})
2932
+
2933
+ mt .RunOpts ("22. range explicit encryption applies defaults" , qeRunOpts22 , func (mt * mtest.T ) {
2934
+ err := mt .Client .Database ("keyvault" ).Collection ("datakeys" ).Drop (context .Background ())
2935
+ assert .Nil (mt , err , "error on Drop: %v" , err )
2936
+
2937
+ testVal := bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 123 )}
2938
+
2939
+ keyVaultClient , err := mongo .Connect (context .Background (), options .Client ().ApplyURI (mtest .ClusterURI ()))
2940
+ assert .Nil (mt , err , "error on Connect: %v" , err )
2941
+
2942
+ ceo := options .ClientEncryption ().
2943
+ SetKeyVaultNamespace ("keyvault.datakeys" ).
2944
+ SetKmsProviders (fullKmsProvidersMap )
2945
+ clientEncryption , err := mongo .NewClientEncryption (keyVaultClient , ceo )
2946
+ assert .Nil (mt , err , "error on NewClientEncryption: %v" , err )
2947
+
2948
+ dkOpts := options .DataKey ()
2949
+ keyID , err := clientEncryption .CreateDataKey (context .Background (), "local" , dkOpts )
2950
+ assert .Nil (mt , err , "error in CreateDataKey: %v" , err )
2951
+
2952
+ eo := options .Encrypt ().
2953
+ SetAlgorithm ("Range" ).
2954
+ SetKeyID (keyID ).
2955
+ SetContentionFactor (0 ).
2956
+ SetRangeOptions (options.RangeOptions {
2957
+ Min : & bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 0 )},
2958
+ Max : & bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 1000 )},
2959
+ })
2960
+ payloadDefaults , err := clientEncryption .Encrypt (context .Background (), testVal , eo )
2961
+ assert .Nil (mt , err , "error in Encrypt: %v" , err )
2962
+
2963
+ mt .Run ("Case 1: uses libmongocrypt defaults" , func (mt * mtest.T ) {
2964
+ trimFactor := int32 (6 )
2965
+ sparsity := int64 (2 )
2966
+ eo := options .Encrypt ().
2967
+ SetAlgorithm ("Range" ).
2968
+ SetKeyID (keyID ).
2969
+ SetContentionFactor (0 ).
2970
+ SetRangeOptions (options.RangeOptions {
2971
+ Min : & bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 0 )},
2972
+ Max : & bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 1000 )},
2973
+ TrimFactor : & trimFactor ,
2974
+ Sparsity : & sparsity ,
2975
+ })
2976
+ payload , err := clientEncryption .Encrypt (context .Background (), testVal , eo )
2977
+ assert .Nil (mt , err , "error in Encrypt: %v" , err )
2978
+ assert .Equalf (mt , len (payload .Data ), len (payloadDefaults .Data ), "the returned payload size is expected to be %d" , len (payloadDefaults .Data ))
2979
+ })
2980
+
2981
+ mt .Run ("Case 2: accepts trimFactor 0" , func (mt * mtest.T ) {
2982
+ trimFactor := int32 (0 )
2983
+ eo := options .Encrypt ().
2984
+ SetAlgorithm ("Range" ).
2985
+ SetKeyID (keyID ).
2986
+ SetContentionFactor (0 ).
2987
+ SetRangeOptions (options.RangeOptions {
2988
+ Min : & bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 0 )},
2989
+ Max : & bson.RawValue {Type : bson .TypeInt32 , Value : bsoncore .AppendInt32 (nil , 1000 )},
2990
+ TrimFactor : & trimFactor ,
2991
+ })
2992
+ payload , err := clientEncryption .Encrypt (context .Background (), testVal , eo )
2993
+ assert .Nil (mt , err , "error in Encrypt: %v" , err )
2994
+ assert .Greater (t , len (payload .Data ), len (payloadDefaults .Data ), "the returned payload size is expected to be greater than %d" , len (payloadDefaults .Data ))
2995
+ })
2996
+ })
2924
2997
}
2925
2998
2926
2999
func getWatcher (mt * mtest.T , streamType mongo.StreamType , cpt * cseProseTest ) watcher {
0 commit comments