Skip to content

Commit ec61ea0

Browse files
Merge branch 'release/2.1' into merge-release/2.0-into-release/2.1-1746201960453
2 parents f0f3074 + fb62199 commit ec61ea0

File tree

154 files changed

+19732
-2641
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+19732
-2641
lines changed

.evergreen/config.yml

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,25 @@ functions:
561561
KMS_MOCK_SERVERS_RUNNING: "true"
562562
args: [*task-runner, evg-test-kmip]
563563

564+
run-retry-kms-requests:
565+
- command: subprocess.exec
566+
type: test
567+
params:
568+
binary: "bash"
569+
env:
570+
GO_BUILD_TAGS: cse
571+
include_expansions_in_env: [AUTH, SSL, MONGODB_URI, TOPOLOGY,
572+
MONGO_GO_DRIVER_COMPRESSOR]
573+
args: [*task-runner, setup-test]
574+
- command: subprocess.exec
575+
type: test
576+
params:
577+
binary: "bash"
578+
env:
579+
KMS_FAILPOINT_CA_FILE: "${DRIVERS_TOOLS}/.evergreen/x509gen/ca.pem"
580+
KMS_FAILPOINT_SERVER_RUNNING: "true"
581+
args: [*task-runner, evg-test-retry-kms-requests]
582+
564583
run-fuzz-tests:
565584
- command: subprocess.exec
566585
type: test
@@ -1468,7 +1487,7 @@ tasks:
14681487
SSL: "nossl"
14691488

14701489
- name: "test-kms-tls-invalid-cert"
1471-
tags: ["kms-tls"]
1490+
tags: ["kms-test"]
14721491
commands:
14731492
- func: bootstrap-mongo-orchestration
14741493
vars:
@@ -1484,7 +1503,7 @@ tasks:
14841503
SSL: "nossl"
14851504

14861505
- name: "test-kms-tls-invalid-hostname"
1487-
tags: ["kms-tls"]
1506+
tags: ["kms-test"]
14881507
commands:
14891508
- func: bootstrap-mongo-orchestration
14901509
vars:
@@ -1514,6 +1533,17 @@ tasks:
15141533
AUTH: "noauth"
15151534
SSL: "nossl"
15161535

1536+
- name: "test-retry-kms-requests"
1537+
tags: ["kms-test"]
1538+
commands:
1539+
- func: bootstrap-mongo-orchestration
1540+
vars:
1541+
TOPOLOGY: "server"
1542+
AUTH: "noauth"
1543+
SSL: "nossl"
1544+
- func: start-cse-servers
1545+
- func: run-retry-kms-requests
1546+
15171547
- name: "test-serverless"
15181548
tags: ["serverless"]
15191549
commands:
@@ -2201,11 +2231,11 @@ buildvariants:
22012231
tasks:
22022232
- name: ".versioned-api"
22032233

2204-
- matrix_name: "kms-tls-test"
2234+
- matrix_name: "kms-test"
22052235
matrix_spec: { version: ["7.0"], os-ssl-40: ["rhel87-64"] }
2206-
display_name: "KMS TLS ${os-ssl-40}"
2236+
display_name: "KMS TEST ${os-ssl-40}"
22072237
tasks:
2208-
- name: ".kms-tls"
2238+
- name: ".kms-test"
22092239

22102240
- matrix_name: "load-balancer-test"
22112241
tags: ["pullrequest"]

Taskfile.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ tasks:
143143
evg-test-kms:
144144
- go test -exec "env PKG_CONFIG_PATH=${PKG_CONFIG_PATH} LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" ${BUILD_TAGS} -v -timeout {{.TEST_TIMEOUT}}s ./internal/integration -run TestClientSideEncryptionProse/kms_tls_tests >> test.suite
145145

146+
evg-test-retry-kms-requests:
147+
- go test -exec "env PKG_CONFIG_PATH=${PKG_CONFIG_PATH} LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" ${BUILD_TAGS} -v -timeout {{.TEST_TIMEOUT}}s ./internal/integration -run TestClientSideEncryptionProse/kms_retry_tests >> test.suite
148+
146149
evg-test-load-balancers:
147150
# Load balancer should be tested with all unified tests as well as tests in the following
148151
# components: retryable reads, retryable writes, change streams, initial DNS seedlist discovery.

bson/bson_binary_vector_spec_test.go

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
// Copyright (C) MongoDB, Inc. 2024-present.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
package bson
8+
9+
import (
10+
"encoding/hex"
11+
"encoding/json"
12+
"math"
13+
"os"
14+
"path"
15+
"testing"
16+
17+
"go.mongodb.org/mongo-driver/v2/internal/require"
18+
)
19+
20+
const bsonBinaryVectorDir = "../testdata/bson-binary-vector/"
21+
22+
type bsonBinaryVectorTests struct {
23+
Description string `json:"description"`
24+
TestKey string `json:"test_key"`
25+
Tests []bsonBinaryVectorTestCase `json:"tests"`
26+
}
27+
28+
type bsonBinaryVectorTestCase struct {
29+
Description string `json:"description"`
30+
Valid bool `json:"valid"`
31+
Vector []interface{} `json:"vector"`
32+
DtypeHex string `json:"dtype_hex"`
33+
DtypeAlias string `json:"dtype_alias"`
34+
Padding int `json:"padding"`
35+
CanonicalBson string `json:"canonical_bson"`
36+
}
37+
38+
func TestBsonBinaryVectorSpec(t *testing.T) {
39+
t.Parallel()
40+
41+
jsonFiles, err := findJSONFilesInDir(bsonBinaryVectorDir)
42+
require.NoErrorf(t, err, "error finding JSON files in %s: %v", bsonBinaryVectorDir, err)
43+
44+
for _, file := range jsonFiles {
45+
filepath := path.Join(bsonBinaryVectorDir, file)
46+
content, err := os.ReadFile(filepath)
47+
require.NoErrorf(t, err, "reading test file %s", filepath)
48+
49+
var tests bsonBinaryVectorTests
50+
require.NoErrorf(t, json.Unmarshal(content, &tests), "parsing test file %s", filepath)
51+
52+
t.Run(tests.Description, func(t *testing.T) {
53+
t.Parallel()
54+
55+
for _, test := range tests.Tests {
56+
test := test
57+
t.Run(test.Description, func(t *testing.T) {
58+
t.Parallel()
59+
60+
runBsonBinaryVectorTest(t, tests.TestKey, test)
61+
})
62+
}
63+
})
64+
}
65+
66+
t.Run("Padding specified with no vector data PACKED_BIT", func(t *testing.T) {
67+
t.Parallel()
68+
69+
t.Run("Marshaling", func(t *testing.T) {
70+
_, err := NewPackedBitVector(nil, 1)
71+
require.EqualError(t, err, errNonZeroVectorPadding.Error())
72+
})
73+
})
74+
75+
t.Run("Exceeding maximum padding PACKED_BIT", func(t *testing.T) {
76+
t.Parallel()
77+
78+
t.Run("Marshaling", func(t *testing.T) {
79+
_, err := NewPackedBitVector(nil, 8)
80+
require.EqualError(t, err, errVectorPaddingTooLarge.Error())
81+
})
82+
})
83+
}
84+
85+
func convertSlice[T int8 | float32 | byte](s []interface{}) []T {
86+
v := make([]T, len(s))
87+
for i, e := range s {
88+
f := math.NaN()
89+
switch val := e.(type) {
90+
case float64:
91+
f = val
92+
case string:
93+
if val == "inf" {
94+
f = math.Inf(0)
95+
} else if val == "-inf" {
96+
f = math.Inf(-1)
97+
}
98+
}
99+
v[i] = T(f)
100+
}
101+
return v
102+
}
103+
104+
func runBsonBinaryVectorTest(t *testing.T, testKey string, test bsonBinaryVectorTestCase) {
105+
testVector := make(map[string]Vector)
106+
switch alias := test.DtypeHex; alias {
107+
case "0x03":
108+
testVector[testKey] = Vector{
109+
dType: Int8Vector,
110+
int8Data: convertSlice[int8](test.Vector),
111+
}
112+
case "0x27":
113+
testVector[testKey] = Vector{
114+
dType: Float32Vector,
115+
float32Data: convertSlice[float32](test.Vector),
116+
}
117+
case "0x10":
118+
testVector[testKey] = Vector{
119+
dType: PackedBitVector,
120+
bitData: convertSlice[byte](test.Vector),
121+
bitPadding: uint8(test.Padding),
122+
}
123+
default:
124+
t.Fatalf("unsupported vector type: %s", alias)
125+
}
126+
127+
testBSON, err := hex.DecodeString(test.CanonicalBson)
128+
require.NoError(t, err, "decoding canonical BSON")
129+
130+
t.Run("Unmarshaling", func(t *testing.T) {
131+
skipCases := map[string]string{
132+
"Overflow Vector INT8": "compile-time restriction",
133+
"Underflow Vector INT8": "compile-time restriction",
134+
"INT8 with float inputs": "compile-time restriction",
135+
"Overflow Vector PACKED_BIT": "compile-time restriction",
136+
"Underflow Vector PACKED_BIT": "compile-time restriction",
137+
"Vector with float values PACKED_BIT": "compile-time restriction",
138+
"Negative padding PACKED_BIT": "compile-time restriction",
139+
}
140+
if reason, ok := skipCases[test.Description]; ok {
141+
t.Skipf("skip test case %s: %s", test.Description, reason)
142+
}
143+
144+
errMap := map[string]string{
145+
"FLOAT32 with padding": "padding must be 0",
146+
"INT8 with padding": "padding must be 0",
147+
"Padding specified with no vector data PACKED_BIT": "padding must be 0",
148+
"Exceeding maximum padding PACKED_BIT": "padding cannot be larger than 7",
149+
}
150+
151+
t.Parallel()
152+
153+
var got map[string]Vector
154+
err := Unmarshal(testBSON, &got)
155+
if test.Valid {
156+
require.NoError(t, err)
157+
require.Equal(t, testVector, got)
158+
} else if errMsg, ok := errMap[test.Description]; ok {
159+
require.ErrorContains(t, err, errMsg)
160+
} else {
161+
require.Error(t, err)
162+
}
163+
})
164+
165+
t.Run("Marshaling", func(t *testing.T) {
166+
skipCases := map[string]string{
167+
"FLOAT32 with padding": "private padding field",
168+
"Insufficient vector data with 3 bytes FLOAT32": "invalid case",
169+
"Insufficient vector data with 5 bytes FLOAT32": "invalid case",
170+
"Overflow Vector INT8": "compile-time restriction",
171+
"Underflow Vector INT8": "compile-time restriction",
172+
"INT8 with padding": "private padding field",
173+
"INT8 with float inputs": "compile-time restriction",
174+
"Overflow Vector PACKED_BIT": "compile-time restriction",
175+
"Underflow Vector PACKED_BIT": "compile-time restriction",
176+
"Vector with float values PACKED_BIT": "compile-time restriction",
177+
"Padding specified with no vector data PACKED_BIT": "run in alternative case",
178+
"Exceeding maximum padding PACKED_BIT": "run in alternative case",
179+
"Negative padding PACKED_BIT": "compile-time restriction",
180+
}
181+
if reason, ok := skipCases[test.Description]; ok {
182+
t.Skipf("skip test case %s: %s", test.Description, reason)
183+
}
184+
185+
t.Parallel()
186+
187+
got, err := Marshal(testVector)
188+
require.NoError(t, err)
189+
require.Equal(t, testBSON, got)
190+
})
191+
}

bson/bson_corpus_spec_test.go

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,15 @@ func normalizeRelaxedDouble(t *testing.T, key string, rEJ string) string {
217217
func bsonToNative(t *testing.T, b []byte, bType, testDesc string) D {
218218
var doc D
219219
err := Unmarshal(b, &doc)
220-
expectNoError(t, err, fmt.Sprintf("%s: decoding %s BSON", testDesc, bType))
220+
require.NoErrorf(t, err, "%s: decoding %s BSON", testDesc, bType)
221221
return doc
222222
}
223223

224224
// nativeToBSON encodes the native Document (doc) into canonical BSON and compares it to the expected
225225
// canonical BSON (cB)
226226
func nativeToBSON(t *testing.T, cB []byte, doc D, testDesc, bType, docSrcDesc string) {
227227
actual, err := Marshal(doc)
228-
expectNoError(t, err, fmt.Sprintf("%s: encoding %s BSON", testDesc, bType))
228+
require.NoErrorf(t, err, "%s: encoding %s BSON", testDesc, bType)
229229

230230
if diff := cmp.Diff(cB, actual); diff != "" {
231231
t.Errorf("%s: 'native_to_bson(%s) = cB' failed (-want, +got):\n-%v\n+%v\n",
@@ -261,7 +261,7 @@ func jsonToBytes(ej, ejType, testDesc string) ([]byte, error) {
261261
// nativeToJSON encodes the native Document (doc) into an extended JSON string
262262
func nativeToJSON(t *testing.T, ej string, doc D, testDesc, ejType, ejShortName, docSrcDesc string) {
263263
actualEJ, err := MarshalExtJSON(doc, ejType != "relaxed", true)
264-
expectNoError(t, err, fmt.Sprintf("%s: encoding %s extended JSON", testDesc, ejType))
264+
require.NoErrorf(t, err, "%s: encoding %s extended JSON", testDesc, ejType)
265265

266266
if diff := cmp.Diff(ej, string(actualEJ)); diff != "" {
267267
t.Errorf("%s: 'native_to_%s_extended_json(%s) = %s' failed (-want, +got):\n%s\n",
@@ -288,7 +288,7 @@ func runTest(t *testing.T, file string) {
288288
t.Run(v.Description, func(t *testing.T) {
289289
// get canonical BSON
290290
cB, err := hex.DecodeString(v.CanonicalBson)
291-
expectNoError(t, err, fmt.Sprintf("%s: reading canonical BSON", v.Description))
291+
require.NoErrorf(t, err, "%s: reading canonical BSON", v.Description)
292292

293293
// get canonical extended JSON
294294
var compactEJ bytes.Buffer
@@ -341,7 +341,7 @@ func runTest(t *testing.T, file string) {
341341
/*** degenerate BSON round-trip tests (if exists) ***/
342342
if v.DegenerateBSON != nil {
343343
dB, err := hex.DecodeString(*v.DegenerateBSON)
344-
expectNoError(t, err, fmt.Sprintf("%s: reading degenerate BSON", v.Description))
344+
require.NoErrorf(t, err, "%s: reading degenerate BSON", v.Description)
345345

346346
doc = bsonToNative(t, dB, "degenerate", v.Description)
347347

@@ -377,7 +377,7 @@ func runTest(t *testing.T, file string) {
377377
for _, d := range test.DecodeErrors {
378378
t.Run(d.Description, func(t *testing.T) {
379379
b, err := hex.DecodeString(d.Bson)
380-
expectNoError(t, err, d.Description)
380+
require.NoError(t, err, d.Description)
381381

382382
var doc D
383383
err = Unmarshal(b, &doc)
@@ -392,12 +392,12 @@ func runTest(t *testing.T, file string) {
392392
invalidDBPtr := ok && !utf8.ValidString(dbPtr.DB)
393393

394394
if invalidString || invalidDBPtr {
395-
expectNoError(t, err, d.Description)
395+
require.NoError(t, err, d.Description)
396396
return
397397
}
398398
}
399399

400-
expectError(t, err, fmt.Sprintf("%s: expected decode error", d.Description))
400+
require.Errorf(t, err, "%s: expected decode error", d.Description)
401401
})
402402
}
403403
})
@@ -418,7 +418,7 @@ func runTest(t *testing.T, file string) {
418418
if strings.Contains(p.Description, "Null") {
419419
_, err = Marshal(doc)
420420
}
421-
expectError(t, err, fmt.Sprintf("%s: expected parse error", p.Description))
421+
require.Errorf(t, err, "%s: expected parse error", p.Description)
422422
default:
423423
t.Errorf("Update test to check for parse errors for type %s", test.BsonType)
424424
t.Fail()
@@ -431,31 +431,13 @@ func runTest(t *testing.T, file string) {
431431

432432
func Test_BsonCorpus(t *testing.T) {
433433
jsonFiles, err := findJSONFilesInDir(dataDir)
434-
if err != nil {
435-
t.Fatalf("error finding JSON files in %s: %v", dataDir, err)
436-
}
434+
require.NoErrorf(t, err, "error finding JSON files in %s: %v", dataDir, err)
437435

438436
for _, file := range jsonFiles {
439437
runTest(t, file)
440438
}
441439
}
442440

443-
func expectNoError(t *testing.T, err error, desc string) {
444-
if err != nil {
445-
t.Helper()
446-
t.Errorf("%s: Unepexted error: %v", desc, err)
447-
t.FailNow()
448-
}
449-
}
450-
451-
func expectError(t *testing.T, err error, desc string) {
452-
if err == nil {
453-
t.Helper()
454-
t.Errorf("%s: Expected error", desc)
455-
t.FailNow()
456-
}
457-
}
458-
459441
func TestRelaxedUUIDValidation(t *testing.T) {
460442
testCases := []struct {
461443
description string

0 commit comments

Comments
 (0)