Skip to content

Commit

Permalink
Merge branch 'v1' into GODRIVER-2701
Browse files Browse the repository at this point in the history
  • Loading branch information
timothy-kim-mongo committed Jul 1, 2024
2 parents 6477626 + 751a42e commit e9bb168
Show file tree
Hide file tree
Showing 17 changed files with 230 additions and 73 deletions.
43 changes: 34 additions & 9 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ axes:
- id: "windows-64-go-1-20"
display_name: "Windows 64-bit"
run_on:
- windows-vsCurrent-latest-small
- windows-vsCurrent-small
variables:
GCC_PATH: "/cygdrive/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin"
GO_DIST: "C:\\golang\\go1.20"
Expand All @@ -2038,7 +2038,7 @@ axes:
- id: "windows-64-go-1-20"
display_name: "Windows 64-bit"
run_on:
- windows-vsCurrent-latest-small
- windows-vsCurrent-small
variables:
GCC_PATH: "/cygdrive/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin"
GO_DIST: "C:\\golang\\go1.20"
Expand Down Expand Up @@ -2070,7 +2070,7 @@ axes:
- id: "windows-64-vsCurrent-latest-small-go-1-20"
display_name: "Windows 64-bit"
run_on:
- windows-vsCurrent-latest-small
- windows-vsCurrent-small
variables:
GCC_PATH: "/cygdrive/c/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin"
GO_DIST: "C:\\golang\\go1.20"
Expand Down Expand Up @@ -2391,23 +2391,48 @@ buildvariants:
tasks:
- name: "test-docker-runner"

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

- matrix_name: "tests-40-with-zlib-support"
- matrix_name: "tests-windows-36-with-zlib-support"
matrix_spec: { version: ["3.6"], os-ssl-32: ["windows-64-go-1-20"] }
display_name: "${version} ${os-ssl-32}"
tasks:
- name: ".test !.enterprise-auth !.snappy !.zstd"

- matrix_name: "tests-rhel-40-with-zlib-support"
tags: ["pullrequest"]
matrix_spec: { version: ["4.0"], os-ssl-40: ["windows-64-go-1-20", "rhel87-64-go-1-20"] }
matrix_spec: { version: ["4.0"], os-ssl-40: ["rhel87-64-go-1-20"] }
display_name: "${version} ${os-ssl-40}"
tasks:
- name: ".test !.enterprise-auth !.snappy !.zstd"

- matrix_name: "tests-42-plus-zlib-zstd-support"
- matrix_name: "tests-windows-40-with-zlib-support"
matrix_spec: { version: ["4.0"], os-ssl-40: ["windows-64-go-1-20"] }
display_name: "${version} ${os-ssl-40}"
tasks:
- name: ".test !.enterprise-auth !.snappy !.zstd"

- matrix_name: "tests-rhel-42-plus-zlib-zstd-support"
tags: ["pullrequest"]
matrix_spec: { version: ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0"], os-ssl-40: ["rhel87-64-go-1-20"] }
display_name: "${version} ${os-ssl-40}"
tasks:
- name: ".test !.enterprise-auth !.snappy"

- matrix_name: "tests-windows-42-plus-zlib-zstd-support"
matrix_spec: { version: ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0"], os-ssl-40: ["windows-64-go-1-20"] }
display_name: "${version} ${os-ssl-40}"
tasks:
- name: ".test !.enterprise-auth !.snappy"

- matrix_name: "tests-windows-80-zlib-zstd-support"
tags: ["pullrequest"]
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"] }
matrix_spec: { version: ["8.0"], os-ssl-40: ["windows-64-go-1-20"] }
display_name: "${version} ${os-ssl-40}"
tasks:
- name: ".test !.enterprise-auth !.snappy"
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ jobs:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: "The new version to set"
required: true
prev_version:
description: "The previous tagged version"
required: true
push_changes:
description: "Push changes?"
default: true
type: boolean

defaults:
run:
shell: bash -eux {0}

env:
# Changes per branch
SILK_ASSET_GROUP: mongodb-go-driver-v1
EVERGREEN_PROJECT: mongo-go-driver-v1

jobs:
pre-publish:
environment: release
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
outputs:
prev_version: ${{ steps.pre-publish.outputs.prev_version }}
steps:
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
with:
app_id: ${{ vars.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: mongodb-labs/drivers-github-tools/setup@v2
with:
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
aws_region_name: ${{ vars.AWS_REGION_NAME }}
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
- name: Pre Publish
id: pre-publish
uses: mongodb-labs/drivers-github-tools/golang/pre-publish@v2
with:
version: ${{ inputs.version }}
push_changes: ${{ inputs.push_changes }}

static-scan:
needs: [pre-publish]
permissions:
security-events: write
uses: ./.github/workflows/codeql.yml
with:
ref: ${{ github.ref }}

publish:
needs: [pre-publish, static-scan]
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
contents: write
security-events: read
steps:
- uses: mongodb-labs/drivers-github-tools/secure-checkout@v2
with:
app_id: ${{ vars.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: mongodb-labs/drivers-github-tools/setup@v2
with:
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
aws_region_name: ${{ vars.AWS_REGION_NAME }}
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
artifactory_username: ${{ vars.ARTIFACTORY_USERNAME }}
- name: Publish
uses: mongodb-labs/drivers-github-tools/golang/publish@v2
with:
version: ${{ inputs.version }}
silk_asset_group: ${{ env.SILK_ASSET_GROUP }}
evergreen_project: ${{ env.EVERGREEN_PROJECT }}
prev_version: ${{ inputs.prev_version }}
push_changes: ${{ inputs.push_changes }}
token: ${{ env.GH_TOKEN }}
4 changes: 2 additions & 2 deletions bson/bsoncodec/default_value_decoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (DefaultValueDecoders) intDecodeType(dc DecodeContext, vr bsonrw.ValueReade
case reflect.Int64:
return reflect.ValueOf(i64), nil
case reflect.Int:
if int64(int(i64)) != i64 { // Can we fit this inside of an int
if i64 > math.MaxInt { // Can we fit this inside of an int
return emptyValue, fmt.Errorf("%d overflows int", i64)
}

Expand Down Expand Up @@ -434,7 +434,7 @@ func (dvd DefaultValueDecoders) UintDecodeValue(dc DecodeContext, vr bsonrw.Valu
return fmt.Errorf("%d overflows uint64", i64)
}
case reflect.Uint:
if i64 < 0 || int64(uint(i64)) != i64 { // Can we fit this inside of an uint
if i64 < 0 || uint64(i64) > uint64(math.MaxUint) { // Can we fit this inside of an uint
return fmt.Errorf("%d overflows uint", i64)
}
default:
Expand Down
8 changes: 6 additions & 2 deletions bson/bsoncodec/uint_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,15 @@ func (uic *UIntCodec) decodeType(dc DecodeContext, vr bsonrw.ValueReader, t refl

return reflect.ValueOf(uint64(i64)), nil
case reflect.Uint:
if i64 < 0 || int64(uint(i64)) != i64 { // Can we fit this inside of an uint
if i64 < 0 {
return emptyValue, fmt.Errorf("%d overflows uint", i64)
}
v := uint64(i64)
if v > math.MaxUint { // Can we fit this inside of an uint
return emptyValue, fmt.Errorf("%d overflows uint", i64)
}

return reflect.ValueOf(uint(i64)), nil
return reflect.ValueOf(uint(v)), nil
default:
return emptyValue, ValueDecoderError{
Name: "UintDecodeValue",
Expand Down
4 changes: 2 additions & 2 deletions bson/bsonrw/extjson_wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func (ejv *extJSONValue) parseBinary() (b []byte, subType byte, err error) {
return nil, 0, fmt.Errorf("$binary subType value should be string, but instead is %s", val.t)
}

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

subType = byte(i)
Expand Down
12 changes: 5 additions & 7 deletions bson/bsonrw/value_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ func (vr *valueReader) peekLength() (int32, error) {
}

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

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

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

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

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

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

idx := vr.offset
vr.offset += 8
return int64(vr.d[idx]) | int64(vr.d[idx+1])<<8 | int64(vr.d[idx+2])<<16 | int64(vr.d[idx+3])<<24 |
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
return int64(binary.LittleEndian.Uint64(vr.d[idx:])), nil
}

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

idx := vr.offset
vr.offset += 8
return uint64(vr.d[idx]) | uint64(vr.d[idx+1])<<8 | uint64(vr.d[idx+2])<<16 | uint64(vr.d[idx+3])<<24 |
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
return binary.LittleEndian.Uint64(vr.d[idx:]), nil
}
8 changes: 6 additions & 2 deletions bson/raw_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ func (rv RawValue) UnmarshalWithRegistry(r *bsoncodec.Registry, val interface{})
return dec.DecodeValue(bsoncodec.DecodeContext{Registry: r}, vr, rval)
}

// UnmarshalWithContext performs the same unmarshalling as Unmarshal but uses the provided DecodeContext
// instead of the one attached or the default registry.
// UnmarshalWithContext performs the same unmarshalling as Unmarshal but uses
// the provided DecodeContext instead of the one attached or the default
// registry.
//
// Deprecated: Use [RawValue.UnmarshalWithRegistry] with a custom registry to customize
// unmarshal behavior instead.
func (rv RawValue) UnmarshalWithContext(dc *bsoncodec.DecodeContext, val interface{}) error {
if dc == nil {
return ErrNilContext
Expand Down
18 changes: 15 additions & 3 deletions bson/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,27 @@ import (
"go.mongodb.org/mongo-driver/bson/bsoncodec"
)

// DefaultRegistry is the default bsoncodec.Registry. It contains the default codecs and the
// primitive codecs.
// DefaultRegistry is the default bsoncodec.Registry. It contains the default
// codecs and the primitive codecs.
//
// Deprecated: Use [NewRegistry] to construct a new default registry. To use a
// custom registry when marshaling or unmarshaling, use the "SetRegistry" method
// on an [Encoder] or [Decoder] instead:
//
// dec, err := bson.NewDecoder(bsonrw.NewBSONDocumentReader(data))
// if err != nil {
// panic(err)
// }
// dec.SetRegistry(reg)
//
// See [Encoder] and [Decoder] for more examples.
var DefaultRegistry = NewRegistry()

// NewRegistryBuilder creates a new RegistryBuilder configured with the default encoders and
// decoders from the bsoncodec.DefaultValueEncoders and bsoncodec.DefaultValueDecoders types and the
// PrimitiveCodecs type in this package.
//
// Deprecated: Use NewRegistry instead.
// Deprecated: Use [NewRegistry] instead.
func NewRegistryBuilder() *bsoncodec.RegistryBuilder {
rb := bsoncodec.NewRegistryBuilder()
bsoncodec.DefaultValueEncoders{}.RegisterDefaultEncoders(rb)
Expand Down
18 changes: 12 additions & 6 deletions cmd/testatlas/main.go → cmd/testatlas/atlas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"errors"
"flag"
"fmt"
"os"
"testing"
"time"

"go.mongodb.org/mongo-driver/bson"
Expand All @@ -19,15 +21,19 @@ import (
"go.mongodb.org/mongo-driver/mongo/options"
)

func main() {
func TestMain(m *testing.M) {
flag.Parse()
os.Exit(m.Run())
}

func TestAtlas(t *testing.T) {
uris := flag.Args()
ctx := context.Background()

fmt.Printf("Running atlas tests for %d uris\n", len(uris))
t.Logf("Running atlas tests for %d uris\n", len(uris))

for idx, uri := range uris {
fmt.Printf("Running test %d\n", idx)
t.Logf("Running test %d\n", idx)

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

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

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

fmt.Println("Finished!")
t.Logf("Finished!")
}

func runTest(ctx context.Context, clientOpts *options.ClientOptions) error {
Expand Down
4 changes: 2 additions & 2 deletions etc/run-atlas-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ set +x
# Get the atlas secrets.
. ${DRIVERS_TOOLS}/.evergreen/secrets_handling/setup-secrets.sh drivers/atlas_connect

echo "Running cmd/testatlas/main.go"
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
echo "Running cmd/testatlas"
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
Loading

0 comments on commit e9bb168

Please sign in to comment.