Skip to content

Commit 6c5364a

Browse files
authored
Merge branch 'master' into godriver3098-36-eol
2 parents 8a55fd7 + ee212da commit 6c5364a

Some content is hidden

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

49 files changed

+1038
-223
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:
@@ -2184,11 +2214,11 @@ buildvariants:
21842214
tasks:
21852215
- name: ".versioned-api"
21862216

2187-
- matrix_name: "kms-tls-test"
2217+
- matrix_name: "kms-test"
21882218
matrix_spec: { version: ["7.0"], os-ssl-40: ["rhel87-64"] }
2189-
display_name: "KMS TLS ${os-ssl-40}"
2219+
display_name: "KMS TEST ${os-ssl-40}"
21902220
tasks:
2191-
- name: ".kms-tls"
2221+
- name: ".kms-test"
21922222

21932223
- matrix_name: "load-balancer-test"
21942224
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: 24 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package bson
99
import (
1010
"encoding/hex"
1111
"encoding/json"
12-
"fmt"
1312
"math"
1413
"os"
1514
"path"
@@ -64,53 +63,13 @@ func TestBsonBinaryVectorSpec(t *testing.T) {
6463
})
6564
}
6665

67-
t.Run("FLOAT32 with padding", func(t *testing.T) {
68-
t.Parallel()
69-
70-
t.Run("Unmarshaling", func(t *testing.T) {
71-
val := D{{"vector", Binary{Subtype: TypeBinaryVector, Data: []byte{Float32Vector, 3}}}}
72-
b, err := Marshal(val)
73-
require.NoError(t, err, "marshaling test BSON")
74-
var got struct {
75-
Vector Vector
76-
}
77-
err = Unmarshal(b, &got)
78-
require.ErrorContains(t, err, errNonZeroVectorPadding.Error())
79-
})
80-
})
81-
82-
t.Run("INT8 with padding", func(t *testing.T) {
83-
t.Parallel()
84-
85-
t.Run("Unmarshaling", func(t *testing.T) {
86-
val := D{{"vector", Binary{Subtype: TypeBinaryVector, Data: []byte{Int8Vector, 3}}}}
87-
b, err := Marshal(val)
88-
require.NoError(t, err, "marshaling test BSON")
89-
var got struct {
90-
Vector Vector
91-
}
92-
err = Unmarshal(b, &got)
93-
require.ErrorContains(t, err, errNonZeroVectorPadding.Error())
94-
})
95-
})
96-
9766
t.Run("Padding specified with no vector data PACKED_BIT", func(t *testing.T) {
9867
t.Parallel()
9968

10069
t.Run("Marshaling", func(t *testing.T) {
10170
_, err := NewPackedBitVector(nil, 1)
10271
require.EqualError(t, err, errNonZeroVectorPadding.Error())
10372
})
104-
t.Run("Unmarshaling", func(t *testing.T) {
105-
val := D{{"vector", Binary{Subtype: TypeBinaryVector, Data: []byte{PackedBitVector, 1}}}}
106-
b, err := Marshal(val)
107-
require.NoError(t, err, "marshaling test BSON")
108-
var got struct {
109-
Vector Vector
110-
}
111-
err = Unmarshal(b, &got)
112-
require.ErrorContains(t, err, errNonZeroVectorPadding.Error())
113-
})
11473
})
11574

11675
t.Run("Exceeding maximum padding PACKED_BIT", func(t *testing.T) {
@@ -120,47 +79,9 @@ func TestBsonBinaryVectorSpec(t *testing.T) {
12079
_, err := NewPackedBitVector(nil, 8)
12180
require.EqualError(t, err, errVectorPaddingTooLarge.Error())
12281
})
123-
t.Run("Unmarshaling", func(t *testing.T) {
124-
val := D{{"vector", Binary{Subtype: TypeBinaryVector, Data: []byte{PackedBitVector, 8}}}}
125-
b, err := Marshal(val)
126-
require.NoError(t, err, "marshaling test BSON")
127-
var got struct {
128-
Vector Vector
129-
}
130-
err = Unmarshal(b, &got)
131-
require.ErrorContains(t, err, errVectorPaddingTooLarge.Error())
132-
})
13382
})
13483
}
13584

136-
// TODO: This test may be added into the spec tests.
137-
func TestFloat32VectorWithInsufficientData(t *testing.T) {
138-
t.Parallel()
139-
140-
val := Binary{Subtype: TypeBinaryVector}
141-
142-
for _, tc := range [][]byte{
143-
{Float32Vector, 0, 42},
144-
{Float32Vector, 0, 42, 42},
145-
{Float32Vector, 0, 42, 42, 42},
146-
147-
{Float32Vector, 0, 42, 42, 42, 42, 42},
148-
{Float32Vector, 0, 42, 42, 42, 42, 42, 42},
149-
{Float32Vector, 0, 42, 42, 42, 42, 42, 42, 42},
150-
} {
151-
t.Run(fmt.Sprintf("marshaling %d bytes", len(tc)-2), func(t *testing.T) {
152-
val.Data = tc
153-
b, err := Marshal(D{{"vector", val}})
154-
require.NoError(t, err, "marshaling test BSON")
155-
var got struct {
156-
Vector Vector
157-
}
158-
err = Unmarshal(b, &got)
159-
require.ErrorContains(t, err, errInsufficientVectorData.Error())
160-
})
161-
}
162-
}
163-
16485
func convertSlice[T int8 | float32 | byte](s []interface{}) []T {
16586
v := make([]T, len(s))
16687
for i, e := range s {
@@ -208,33 +129,44 @@ func runBsonBinaryVectorTest(t *testing.T, testKey string, test bsonBinaryVector
208129

209130
t.Run("Unmarshaling", func(t *testing.T) {
210131
skipCases := map[string]string{
211-
"FLOAT32 with padding": "run in alternative case",
212-
"Overflow Vector INT8": "compile-time restriction",
213-
"Underflow Vector INT8": "compile-time restriction",
214-
"INT8 with padding": "run in alternative case",
215-
"INT8 with float inputs": "compile-time restriction",
216-
"Overflow Vector PACKED_BIT": "compile-time restriction",
217-
"Underflow Vector PACKED_BIT": "compile-time restriction",
218-
"Vector with float values PACKED_BIT": "compile-time restriction",
219-
"Padding specified with no vector data PACKED_BIT": "run in alternative case",
220-
"Exceeding maximum padding PACKED_BIT": "run in alternative case",
221-
"Negative padding PACKED_BIT": "compile-time restriction",
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",
222139
}
223140
if reason, ok := skipCases[test.Description]; ok {
224141
t.Skipf("skip test case %s: %s", test.Description, reason)
225142
}
226143

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+
227151
t.Parallel()
228152

229153
var got map[string]Vector
230154
err := Unmarshal(testBSON, &got)
231-
require.NoError(t, err)
232-
require.Equal(t, testVector, 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+
}
233163
})
234164

235165
t.Run("Marshaling", func(t *testing.T) {
236166
skipCases := map[string]string{
237167
"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",
238170
"Overflow Vector INT8": "compile-time restriction",
239171
"Underflow Vector INT8": "compile-time restriction",
240172
"INT8 with padding": "private padding field",

bson/default_value_decoders.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,13 @@ func valueUnmarshalerDecodeValue(_ DecodeContext, vr ValueReader, val reflect.Va
12211221
return ValueDecoderError{Name: "ValueUnmarshalerDecodeValue", Types: []reflect.Type{tValueUnmarshaler}, Received: val}
12221222
}
12231223

1224-
if vr.Type() == TypeNull {
1224+
// If BSON value is null and the go value is a pointer, then don't call
1225+
// UnmarshalBSONValue. Even if the Go pointer is already initialized (i.e.,
1226+
// non-nil), encountering null in BSON will result in the pointer being
1227+
// directly set to nil here. Since the pointer is being replaced with nil,
1228+
// there is no opportunity (or reason) for the custom UnmarshalBSONValue logic
1229+
// to be called.
1230+
if vr.Type() == TypeNull && val.Kind() == reflect.Ptr {
12251231
val.Set(reflect.Zero(val.Type()))
12261232

12271233
return vr.ReadNull()

bson/unmarshal.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ type ValueUnmarshaler interface {
3636
}
3737

3838
// Unmarshal parses the BSON-encoded data and stores the result in the value
39-
// pointed to by val. If val is nil or not a pointer, Unmarshal returns an error.
39+
// pointed to by val. If val is nil or not a pointer, Unmarshal returns an
40+
// error.
41+
//
42+
// When unmarshaling BSON, if the BSON value is null and the Go value is a
43+
// pointer, the pointer is set to nil without calling UnmarshalBSONValue.
4044
func Unmarshal(data []byte, val interface{}) error {
4145
vr := newDocumentReader(bytes.NewReader(data))
4246
if l, err := vr.peekLength(); err != nil {

bson/unmarshal_value_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"testing"
1414

1515
"go.mongodb.org/mongo-driver/v2/internal/assert"
16+
"go.mongodb.org/mongo-driver/v2/internal/require"
1617
"go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore"
1718
)
1819

@@ -33,6 +34,26 @@ func TestUnmarshalValue(t *testing.T) {
3334
}
3435
}
3536

37+
func TestInitializedPointerDataWithBSONNull(t *testing.T) {
38+
// Set up the test case with initialized pointers.
39+
tc := unmarshalBehaviorTestCase{
40+
BSONValuePtrTracker: &unmarshalBSONValueCallTracker{},
41+
BSONPtrTracker: &unmarshalBSONCallTracker{},
42+
}
43+
// Create BSON data where the '*_ptr_tracker' fields are explicitly set to
44+
// null.
45+
bytes := docToBytes(D{
46+
{Key: "bv_ptr_tracker", Value: nil},
47+
{Key: "b_ptr_tracker", Value: nil},
48+
})
49+
// Unmarshal the BSON data into the test case struct. This should set the
50+
// pointer fields to nil due to the BSON null value.
51+
err := Unmarshal(bytes, &tc)
52+
require.NoError(t, err)
53+
assert.Nil(t, tc.BSONValuePtrTracker)
54+
assert.Nil(t, tc.BSONPtrTracker)
55+
}
56+
3657
// tests covering GODRIVER-2779
3758
func BenchmarkSliceCodecUnmarshal(b *testing.B) {
3859
benchmarks := []struct {

0 commit comments

Comments
 (0)