Skip to content

Commit e9bb168

Browse files
Merge branch 'v1' into GODRIVER-2701
2 parents 6477626 + 751a42e commit e9bb168

File tree

17 files changed

+230
-73
lines changed

17 files changed

+230
-73
lines changed

.evergreen/config.yml

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ axes:
20142014
- id: "windows-64-go-1-20"
20152015
display_name: "Windows 64-bit"
20162016
run_on:
2017-
- windows-vsCurrent-latest-small
2017+
- windows-vsCurrent-small
20182018
variables:
20192019
GCC_PATH: "/cygdrive/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin"
20202020
GO_DIST: "C:\\golang\\go1.20"
@@ -2038,7 +2038,7 @@ axes:
20382038
- id: "windows-64-go-1-20"
20392039
display_name: "Windows 64-bit"
20402040
run_on:
2041-
- windows-vsCurrent-latest-small
2041+
- windows-vsCurrent-small
20422042
variables:
20432043
GCC_PATH: "/cygdrive/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin"
20442044
GO_DIST: "C:\\golang\\go1.20"
@@ -2070,7 +2070,7 @@ axes:
20702070
- id: "windows-64-vsCurrent-latest-small-go-1-20"
20712071
display_name: "Windows 64-bit"
20722072
run_on:
2073-
- windows-vsCurrent-latest-small
2073+
- windows-vsCurrent-small
20742074
variables:
20752075
GCC_PATH: "/cygdrive/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin"
20762076
GO_DIST: "C:\\golang\\go1.20"
@@ -2391,23 +2391,48 @@ buildvariants:
23912391
tasks:
23922392
- name: "test-docker-runner"
23932393

2394-
- matrix_name: "tests-36-with-zlib-support"
2394+
- matrix_name: "tests-rhel-36-with-zlib-support"
23952395
tags: ["pullrequest"]
2396-
matrix_spec: { version: ["3.6"], os-ssl-32: ["windows-64-go-1-20", "rhel87-64-go-1-20"] }
2396+
matrix_spec: { version: ["3.6"], os-ssl-32: ["rhel87-64-go-1-20"] }
23972397
display_name: "${version} ${os-ssl-32}"
23982398
tasks:
23992399
- name: ".test !.enterprise-auth !.snappy !.zstd"
24002400

2401-
- matrix_name: "tests-40-with-zlib-support"
2401+
- matrix_name: "tests-windows-36-with-zlib-support"
2402+
matrix_spec: { version: ["3.6"], os-ssl-32: ["windows-64-go-1-20"] }
2403+
display_name: "${version} ${os-ssl-32}"
2404+
tasks:
2405+
- name: ".test !.enterprise-auth !.snappy !.zstd"
2406+
2407+
- matrix_name: "tests-rhel-40-with-zlib-support"
24022408
tags: ["pullrequest"]
2403-
matrix_spec: { version: ["4.0"], os-ssl-40: ["windows-64-go-1-20", "rhel87-64-go-1-20"] }
2409+
matrix_spec: { version: ["4.0"], os-ssl-40: ["rhel87-64-go-1-20"] }
24042410
display_name: "${version} ${os-ssl-40}"
24052411
tasks:
24062412
- name: ".test !.enterprise-auth !.snappy !.zstd"
24072413

2408-
- matrix_name: "tests-42-plus-zlib-zstd-support"
2414+
- matrix_name: "tests-windows-40-with-zlib-support"
2415+
matrix_spec: { version: ["4.0"], os-ssl-40: ["windows-64-go-1-20"] }
2416+
display_name: "${version} ${os-ssl-40}"
2417+
tasks:
2418+
- name: ".test !.enterprise-auth !.snappy !.zstd"
2419+
2420+
- matrix_name: "tests-rhel-42-plus-zlib-zstd-support"
2421+
tags: ["pullrequest"]
2422+
matrix_spec: { version: ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0"], os-ssl-40: ["rhel87-64-go-1-20"] }
2423+
display_name: "${version} ${os-ssl-40}"
2424+
tasks:
2425+
- name: ".test !.enterprise-auth !.snappy"
2426+
2427+
- matrix_name: "tests-windows-42-plus-zlib-zstd-support"
2428+
matrix_spec: { version: ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0"], os-ssl-40: ["windows-64-go-1-20"] }
2429+
display_name: "${version} ${os-ssl-40}"
2430+
tasks:
2431+
- name: ".test !.enterprise-auth !.snappy"
2432+
2433+
- matrix_name: "tests-windows-80-zlib-zstd-support"
24092434
tags: ["pullrequest"]
2410-
matrix_spec: { version: ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0"], os-ssl-40: ["windows-64-go-1-20", "rhel87-64-go-1-20"] }
2435+
matrix_spec: { version: ["8.0"], os-ssl-40: ["windows-64-go-1-20"] }
24112436
display_name: "${version} ${os-ssl-40}"
24122437
tasks:
24132438
- name: ".test !.enterprise-auth !.snappy"

.github/workflows/codeql.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ jobs:
2222
# required for all workflows
2323
security-events: write
2424

25-
# required to fetch internal or private CodeQL packs
26-
packages: read
27-
28-
# only required for workflows in private repositories
29-
actions: read
30-
contents: read
31-
3225
strategy:
3326
fail-fast: false
3427
matrix:

.github/workflows/release.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "The new version to set"
8+
required: true
9+
prev_version:
10+
description: "The previous tagged version"
11+
required: true
12+
push_changes:
13+
description: "Push changes?"
14+
default: true
15+
type: boolean
16+
17+
defaults:
18+
run:
19+
shell: bash -eux {0}
20+
21+
env:
22+
# Changes per branch
23+
SILK_ASSET_GROUP: mongodb-go-driver-v1
24+
EVERGREEN_PROJECT: mongo-go-driver-v1
25+
26+
jobs:
27+
pre-publish:
28+
environment: release
29+
runs-on: ubuntu-latest
30+
permissions:
31+
id-token: write
32+
contents: write
33+
outputs:
34+
prev_version: ${{ steps.pre-publish.outputs.prev_version }}
35+
steps:
36+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
37+
with:
38+
app_id: ${{ vars.APP_ID }}
39+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
40+
- uses: mongodb-labs/drivers-github-tools/setup@v2
41+
with:
42+
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
43+
aws_region_name: ${{ vars.AWS_REGION_NAME }}
44+
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
45+
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
46+
- name: Pre Publish
47+
id: pre-publish
48+
uses: mongodb-labs/drivers-github-tools/golang/pre-publish@v2
49+
with:
50+
version: ${{ inputs.version }}
51+
push_changes: ${{ inputs.push_changes }}
52+
53+
static-scan:
54+
needs: [pre-publish]
55+
permissions:
56+
security-events: write
57+
uses: ./.github/workflows/codeql.yml
58+
with:
59+
ref: ${{ github.ref }}
60+
61+
publish:
62+
needs: [pre-publish, static-scan]
63+
runs-on: ubuntu-latest
64+
environment: release
65+
permissions:
66+
id-token: write
67+
contents: write
68+
security-events: read
69+
steps:
70+
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
71+
with:
72+
app_id: ${{ vars.APP_ID }}
73+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
74+
- uses: mongodb-labs/drivers-github-tools/setup@v2
75+
with:
76+
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
77+
aws_region_name: ${{ vars.AWS_REGION_NAME }}
78+
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
79+
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
80+
- name: Publish
81+
uses: mongodb-labs/drivers-github-tools/golang/publish@v2
82+
with:
83+
version: ${{ inputs.version }}
84+
silk_asset_group: ${{ env.SILK_ASSET_GROUP }}
85+
evergreen_project: ${{ env.EVERGREEN_PROJECT }}
86+
prev_version: ${{ inputs.prev_version }}
87+
push_changes: ${{ inputs.push_changes }}
88+
token: ${{ env.GH_TOKEN }}

bson/bsoncodec/default_value_decoders.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func (DefaultValueDecoders) intDecodeType(dc DecodeContext, vr bsonrw.ValueReade
330330
case reflect.Int64:
331331
return reflect.ValueOf(i64), nil
332332
case reflect.Int:
333-
if int64(int(i64)) != i64 { // Can we fit this inside of an int
333+
if i64 > math.MaxInt { // Can we fit this inside of an int
334334
return emptyValue, fmt.Errorf("%d overflows int", i64)
335335
}
336336

@@ -434,7 +434,7 @@ func (dvd DefaultValueDecoders) UintDecodeValue(dc DecodeContext, vr bsonrw.Valu
434434
return fmt.Errorf("%d overflows uint64", i64)
435435
}
436436
case reflect.Uint:
437-
if i64 < 0 || int64(uint(i64)) != i64 { // Can we fit this inside of an uint
437+
if i64 < 0 || uint64(i64) > uint64(math.MaxUint) { // Can we fit this inside of an uint
438438
return fmt.Errorf("%d overflows uint", i64)
439439
}
440440
default:

bson/bsoncodec/uint_codec.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,15 @@ func (uic *UIntCodec) decodeType(dc DecodeContext, vr bsonrw.ValueReader, t refl
164164

165165
return reflect.ValueOf(uint64(i64)), nil
166166
case reflect.Uint:
167-
if i64 < 0 || int64(uint(i64)) != i64 { // Can we fit this inside of an uint
167+
if i64 < 0 {
168+
return emptyValue, fmt.Errorf("%d overflows uint", i64)
169+
}
170+
v := uint64(i64)
171+
if v > math.MaxUint { // Can we fit this inside of an uint
168172
return emptyValue, fmt.Errorf("%d overflows uint", i64)
169173
}
170174

171-
return reflect.ValueOf(uint(i64)), nil
175+
return reflect.ValueOf(uint(v)), nil
172176
default:
173177
return emptyValue, ValueDecoderError{
174178
Name: "UintDecodeValue",

bson/bsonrw/extjson_wrappers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ func (ejv *extJSONValue) parseBinary() (b []byte, subType byte, err error) {
9595
return nil, 0, fmt.Errorf("$binary subType value should be string, but instead is %s", val.t)
9696
}
9797

98-
i, err := strconv.ParseInt(val.v.(string), 16, 64)
98+
i, err := strconv.ParseUint(val.v.(string), 16, 8)
9999
if err != nil {
100-
return nil, 0, fmt.Errorf("invalid $binary subType string: %s", val.v.(string))
100+
return nil, 0, fmt.Errorf("invalid $binary subType string: %q: %w", val.v.(string), err)
101101
}
102102

103103
subType = byte(i)

bson/bsonrw/value_reader.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ func (vr *valueReader) peekLength() (int32, error) {
842842
}
843843

844844
idx := vr.offset
845-
return (int32(vr.d[idx]) | int32(vr.d[idx+1])<<8 | int32(vr.d[idx+2])<<16 | int32(vr.d[idx+3])<<24), nil
845+
return int32(binary.LittleEndian.Uint32(vr.d[idx:])), nil
846846
}
847847

848848
func (vr *valueReader) readLength() (int32, error) { return vr.readi32() }
@@ -854,7 +854,7 @@ func (vr *valueReader) readi32() (int32, error) {
854854

855855
idx := vr.offset
856856
vr.offset += 4
857-
return (int32(vr.d[idx]) | int32(vr.d[idx+1])<<8 | int32(vr.d[idx+2])<<16 | int32(vr.d[idx+3])<<24), nil
857+
return int32(binary.LittleEndian.Uint32(vr.d[idx:])), nil
858858
}
859859

860860
func (vr *valueReader) readu32() (uint32, error) {
@@ -864,7 +864,7 @@ func (vr *valueReader) readu32() (uint32, error) {
864864

865865
idx := vr.offset
866866
vr.offset += 4
867-
return (uint32(vr.d[idx]) | uint32(vr.d[idx+1])<<8 | uint32(vr.d[idx+2])<<16 | uint32(vr.d[idx+3])<<24), nil
867+
return binary.LittleEndian.Uint32(vr.d[idx:]), nil
868868
}
869869

870870
func (vr *valueReader) readi64() (int64, error) {
@@ -874,8 +874,7 @@ func (vr *valueReader) readi64() (int64, error) {
874874

875875
idx := vr.offset
876876
vr.offset += 8
877-
return int64(vr.d[idx]) | int64(vr.d[idx+1])<<8 | int64(vr.d[idx+2])<<16 | int64(vr.d[idx+3])<<24 |
878-
int64(vr.d[idx+4])<<32 | int64(vr.d[idx+5])<<40 | int64(vr.d[idx+6])<<48 | int64(vr.d[idx+7])<<56, nil
877+
return int64(binary.LittleEndian.Uint64(vr.d[idx:])), nil
879878
}
880879

881880
func (vr *valueReader) readu64() (uint64, error) {
@@ -885,6 +884,5 @@ func (vr *valueReader) readu64() (uint64, error) {
885884

886885
idx := vr.offset
887886
vr.offset += 8
888-
return uint64(vr.d[idx]) | uint64(vr.d[idx+1])<<8 | uint64(vr.d[idx+2])<<16 | uint64(vr.d[idx+3])<<24 |
889-
uint64(vr.d[idx+4])<<32 | uint64(vr.d[idx+5])<<40 | uint64(vr.d[idx+6])<<48 | uint64(vr.d[idx+7])<<56, nil
887+
return binary.LittleEndian.Uint64(vr.d[idx:]), nil
890888
}

bson/raw_value.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ func (rv RawValue) UnmarshalWithRegistry(r *bsoncodec.Registry, val interface{})
8888
return dec.DecodeValue(bsoncodec.DecodeContext{Registry: r}, vr, rval)
8989
}
9090

91-
// UnmarshalWithContext performs the same unmarshalling as Unmarshal but uses the provided DecodeContext
92-
// instead of the one attached or the default registry.
91+
// UnmarshalWithContext performs the same unmarshalling as Unmarshal but uses
92+
// the provided DecodeContext instead of the one attached or the default
93+
// registry.
94+
//
95+
// Deprecated: Use [RawValue.UnmarshalWithRegistry] with a custom registry to customize
96+
// unmarshal behavior instead.
9397
func (rv RawValue) UnmarshalWithContext(dc *bsoncodec.DecodeContext, val interface{}) error {
9498
if dc == nil {
9599
return ErrNilContext

bson/registry.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,27 @@ import (
1010
"go.mongodb.org/mongo-driver/bson/bsoncodec"
1111
)
1212

13-
// DefaultRegistry is the default bsoncodec.Registry. It contains the default codecs and the
14-
// primitive codecs.
13+
// DefaultRegistry is the default bsoncodec.Registry. It contains the default
14+
// codecs and the primitive codecs.
15+
//
16+
// Deprecated: Use [NewRegistry] to construct a new default registry. To use a
17+
// custom registry when marshaling or unmarshaling, use the "SetRegistry" method
18+
// on an [Encoder] or [Decoder] instead:
19+
//
20+
// dec, err := bson.NewDecoder(bsonrw.NewBSONDocumentReader(data))
21+
// if err != nil {
22+
// panic(err)
23+
// }
24+
// dec.SetRegistry(reg)
25+
//
26+
// See [Encoder] and [Decoder] for more examples.
1527
var DefaultRegistry = NewRegistry()
1628

1729
// NewRegistryBuilder creates a new RegistryBuilder configured with the default encoders and
1830
// decoders from the bsoncodec.DefaultValueEncoders and bsoncodec.DefaultValueDecoders types and the
1931
// PrimitiveCodecs type in this package.
2032
//
21-
// Deprecated: Use NewRegistry instead.
33+
// Deprecated: Use [NewRegistry] instead.
2234
func NewRegistryBuilder() *bsoncodec.RegistryBuilder {
2335
rb := bsoncodec.NewRegistryBuilder()
2436
bsoncodec.DefaultValueEncoders{}.RegisterDefaultEncoders(rb)

cmd/testatlas/main.go renamed to cmd/testatlas/atlas_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"errors"
1212
"flag"
1313
"fmt"
14+
"os"
15+
"testing"
1416
"time"
1517

1618
"go.mongodb.org/mongo-driver/bson"
@@ -19,15 +21,19 @@ import (
1921
"go.mongodb.org/mongo-driver/mongo/options"
2022
)
2123

22-
func main() {
24+
func TestMain(m *testing.M) {
2325
flag.Parse()
26+
os.Exit(m.Run())
27+
}
28+
29+
func TestAtlas(t *testing.T) {
2430
uris := flag.Args()
2531
ctx := context.Background()
2632

27-
fmt.Printf("Running atlas tests for %d uris\n", len(uris))
33+
t.Logf("Running atlas tests for %d uris\n", len(uris))
2834

2935
for idx, uri := range uris {
30-
fmt.Printf("Running test %d\n", idx)
36+
t.Logf("Running test %d\n", idx)
3137

3238
// Set a low server selection timeout so we fail fast if there are errors.
3339
clientOpts := options.Client().
@@ -36,18 +42,18 @@ func main() {
3642

3743
// Run basic connectivity test.
3844
if err := runTest(ctx, clientOpts); err != nil {
39-
panic(fmt.Sprintf("error running test with TLS at index %d: %v", idx, err))
45+
t.Fatalf("error running test with TLS at index %d: %v", idx, err)
4046
}
4147

4248
// Run the connectivity test with InsecureSkipVerify to ensure SNI is done correctly even if verification is
4349
// disabled.
4450
clientOpts.TLSConfig.InsecureSkipVerify = true
4551
if err := runTest(ctx, clientOpts); err != nil {
46-
panic(fmt.Sprintf("error running test with tlsInsecure at index %d: %v", idx, err))
52+
t.Fatalf("error running test with tlsInsecure at index %d: %v", idx, err)
4753
}
4854
}
4955

50-
fmt.Println("Finished!")
56+
t.Logf("Finished!")
5157
}
5258

5359
func runTest(ctx context.Context, clientOpts *options.ClientOptions) error {

etc/run-atlas-test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ set +x
77
# Get the atlas secrets.
88
. ${DRIVERS_TOOLS}/.evergreen/secrets_handling/setup-secrets.sh drivers/atlas_connect
99

10-
echo "Running cmd/testatlas/main.go"
11-
go run ./cmd/testatlas/main.go "$ATLAS_REPL" "$ATLAS_SHRD" "$ATLAS_FREE" "$ATLAS_TLS11" "$ATLAS_TLS12" "$ATLAS_SERVERLESS" "$ATLAS_SRV_REPL" "$ATLAS_SRV_SHRD" "$ATLAS_SRV_FREE" "$ATLAS_SRV_TLS11" "$ATLAS_SRV_TLS12" "$ATLAS_SRV_SERVERLESS" >> test.suite
10+
echo "Running cmd/testatlas"
11+
go test -v -run ^TestAtlas$ go.mongodb.org/mongo-driver/cmd/testatlas -args "$ATLAS_REPL" "$ATLAS_SHRD" "$ATLAS_FREE" "$ATLAS_TLS11" "$ATLAS_TLS12" "$ATLAS_SERVERLESS" "$ATLAS_SRV_REPL" "$ATLAS_SRV_SHRD" "$ATLAS_SRV_FREE" "$ATLAS_SRV_TLS11" "$ATLAS_SRV_TLS12" "$ATLAS_SRV_SERVERLESS" >> test.suite

0 commit comments

Comments
 (0)