Skip to content

Commit e014fc3

Browse files
authored
Merge branch 'master' into godriver3397-remove-cr
2 parents cf46ed0 + bcf7b14 commit e014fc3

File tree

13 files changed

+157
-133
lines changed

13 files changed

+157
-133
lines changed

.github/workflows/scorecard.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# This workflow uses actions that are not certified by GitHub. They are provided
2+
# by a third-party and are governed by separate terms of service, privacy
3+
# policy, and support documentation.
4+
5+
name: Scorecard supply-chain security
6+
on:
7+
# For Branch-Protection check. Only the default branch is supported. See
8+
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
9+
branch_protection_rule:
10+
# To guarantee Maintained check is occasionally updated. See
11+
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
12+
schedule:
13+
- cron: '24 21 * * 1'
14+
push:
15+
branches: [ "master" ]
16+
17+
# Declare default permissions as read only.
18+
permissions: read-all
19+
20+
jobs:
21+
analysis:
22+
name: Scorecard analysis
23+
runs-on: ubuntu-latest
24+
# `publish_results: true` only works when run from the default branch. conditional can be removed if disabled.
25+
if: github.event.repository.default_branch == github.ref_name || github.event_name == 'pull_request'
26+
permissions:
27+
# Needed to upload the results to code-scanning dashboard.
28+
security-events: write
29+
# Needed to publish results and get a badge (see publish_results below).
30+
id-token: write
31+
# Uncomment the permissions below if installing in a private repository.
32+
# contents: read
33+
# actions: read
34+
35+
steps:
36+
- name: "Checkout code"
37+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
38+
with:
39+
persist-credentials: false
40+
41+
- name: "Run analysis"
42+
uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2
43+
with:
44+
results_file: results.sarif
45+
results_format: sarif
46+
# (Optional) "write" PAT token. Uncomment the `repo_token` line below if:
47+
# - you want to enable the Branch-Protection check on a *public* repository, or
48+
# - you are installing Scorecard on a *private* repository
49+
# To create the PAT, follow the steps in https://github.com/ossf/scorecard-action?tab=readme-ov-file#authentication-with-fine-grained-pat-optional.
50+
# repo_token: ${{ secrets.SCORECARD_TOKEN }}
51+
52+
# Public repositories:
53+
# - Publish results to OpenSSF REST API for easy access by consumers
54+
# - Allows the repository to include the Scorecard badge.
55+
# - See https://github.com/ossf/scorecard-action#publishing-results.
56+
# For private repositories:
57+
# - `publish_results` will always be set to `false`, regardless
58+
# of the value entered here.
59+
publish_results: true
60+
61+
# (Optional) Uncomment file_mode if you have a .gitattributes with files marked export-ignore
62+
# file_mode: git
63+
64+
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
65+
# format to the repository Actions tab.
66+
- name: "Upload artifact"
67+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
68+
with:
69+
name: SARIF file
70+
path: results.sarif
71+
retention-days: 5
72+
73+
# Upload the results to GitHub's code scanning dashboard (optional).
74+
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
75+
- name: "Upload to code-scanning"
76+
uses: github/codeql-action/upload-sarif@v3
77+
with:
78+
sarif_file: results.sarif

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<a href="https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/mongo"><img src="etc/assets/godev-mongo-blue.svg" alt="docs"></a>
55
<a href="https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson"><img src="etc/assets/godev-bson-blue.svg" alt="docs"></a>
66
<a href="https://www.mongodb.com/docs/drivers/go/current/"><img src="etc/assets/docs-mongodb-green.svg"></a>
7+
<a href="https://securityscorecards.dev/viewer/?uri=github.com/mongodb/mongo-go-driver">
8+
<img src="https://api.securityscorecards.dev/projects/github.com/mongodb/mongo-go-driver/badge" alt="OpenSSF Scorecard" />
9+
</a>
710
</p>
811

912
# MongoDB Go Driver

bson/doc.go

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,14 @@
44
// not use this file except in compliance with the License. You may obtain
55
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
66

7-
// Package bson is a library for reading, writing, and manipulating BSON. BSON is a binary serialization format used to
8-
// store documents and make remote procedure calls in MongoDB. The BSON specification is located at https://bsonspec.org.
9-
// The BSON library handles marshaling and unmarshaling of values through a configurable codec system. For a description
10-
// of the codec system and examples of registering custom codecs, see the bsoncodec package. For additional information
11-
// and usage examples, check out the [Work with BSON] page in the Go Driver docs site.
12-
//
13-
// # Raw BSON
14-
//
15-
// The Raw family of types is used to validate and retrieve elements from a slice of bytes. This
16-
// type is most useful when you want do lookups on BSON bytes without unmarshaling it into another
17-
// type.
18-
//
19-
// Example:
20-
//
21-
// var raw bson.Raw = ... // bytes from somewhere
22-
// err := raw.Validate()
23-
// if err != nil { return err }
24-
// val := raw.Lookup("foo")
25-
// i32, ok := val.Int32OK()
26-
// // do something with i32...
7+
// Package bson is a library for reading, writing, and manipulating BSON. BSON is a binary serialization
8+
// format used to store documents and make remote procedure calls in MongoDB. For more information about
9+
// the Go BSON library, including usage examples, check out the [Work with BSON] page in the Go Driver
10+
// docs site. For more information about BSON, see https://bsonspec.org.
2711
//
2812
// # Native Go Types
2913
//
30-
// The D and M types defined in this package can be used to build representations of BSON using native Go types. D is a
14+
// The [D] and [M] types defined in this package can be used to build representations of BSON using native Go types. D is a
3115
// slice and M is a map. For more information about the use cases for these types, see the documentation on the type
3216
// definitions.
3317
//
@@ -93,26 +77,16 @@
9377
// 5. When unmarshaling, a field of type interface{} will follow the D/M type mappings listed above. BSON documents
9478
// unmarshaled into an interface{} field will be unmarshaled as a D.
9579
//
96-
// The encoding of each struct field can be customized by the "bson" struct tag.
97-
//
98-
// This tag behavior is configurable, and different struct tag behavior can be configured by initializing a new
99-
// bsoncodec.StructCodec with the desired tag parser and registering that StructCodec onto the Registry. By default, JSON
100-
// tags are not honored, but that can be enabled by creating a StructCodec with JSONFallbackStructTagParser, like below:
101-
//
102-
// Example:
103-
//
104-
// structcodec, _ := bsoncodec.NewStructCodec(bsoncodec.JSONFallbackStructTagParser)
105-
//
106-
// The bson tag gives the name of the field, possibly followed by a comma-separated list of options.
107-
// The name may be empty in order to specify options without overriding the default field name. The following options can
108-
// be used to configure behavior:
80+
// The encoding of each struct field can be customized by the "bson" struct tag. The "bson" tag gives the name of the
81+
// field, followed by a comma-separated list of options. The name may be omitted in order to specify options without
82+
// overriding the default field name. The following options can be used to configure behavior:
10983
//
11084
// 1. omitempty: If the "omitempty" struct tag is specified on a field, the field will not be marshaled if it is set to
11185
// an "empty" value. Numbers, booleans, and strings are considered empty if their value is equal to the zero value for
11286
// the type (i.e. 0 for numbers, false for booleans, and "" for strings). Slices, maps, and arrays are considered
11387
// empty if they are of length zero. Interfaces and pointers are considered empty if their value is nil. By default,
114-
// structs are only considered empty if the struct type implements [bsoncodec.Zeroer] and the IsZero
115-
// method returns true. Struct types that do not implement [bsoncodec.Zeroer] are never considered empty and will be
88+
// structs are only considered empty if the struct type implements [Zeroer] and the "IsZero"
89+
// method returns true. Struct types that do not implement [Zeroer] are never considered empty and will be
11690
// marshaled as embedded documents. NOTE: It is recommended that this tag be used for all slice and map fields.
11791
//
11892
// 2. minsize: If the minsize struct tag is specified on a field of type int64, uint, uint32, or uint64 and the value of
@@ -134,22 +108,34 @@
134108
// error will be returned. This tag can be used with fields that are pointers to structs. If an inlined pointer field
135109
// is nil, it will not be marshaled. For fields that are not maps or structs, this tag is ignored.
136110
//
137-
// # Marshaling and Unmarshaling
111+
// # Raw BSON
138112
//
139-
// Manually marshaling and unmarshaling can be done with the Marshal and Unmarshal family of functions.
113+
// The Raw family of types is used to validate and retrieve elements from a slice of bytes. This
114+
// type is most useful when you want do lookups on BSON bytes without unmarshaling it into another
115+
// type.
140116
//
141-
// bsoncodec code provides a system for encoding values to BSON representations and decoding
142-
// values from BSON representations. This package considers both binary BSON and ExtendedJSON as
143-
// BSON representations. The types in this package enable a flexible system for handling this
144-
// encoding and decoding.
117+
// Example:
145118
//
146-
// The codec system is composed of two parts:
119+
// var raw bson.Raw = ... // bytes from somewhere
120+
// err := raw.Validate()
121+
// if err != nil { return err }
122+
// val := raw.Lookup("foo")
123+
// i32, ok := val.Int32OK()
124+
// // do something with i32...
125+
//
126+
// # Custom Registry
127+
//
128+
// The Go BSON library uses a [Registry] to define encoding and decoding behavior for different data types.
129+
// The default encoding and decoding behavior can be customized or extended by using a modified Registry.
130+
// The custom registry system is composed of two parts:
147131
//
148132
// 1) [ValueEncoder] and [ValueDecoder] that handle encoding and decoding Go values to and from BSON
149133
// representations.
150134
//
151135
// 2) A [Registry] that holds these ValueEncoders and ValueDecoders and provides methods for
152136
// retrieving them.
153137
//
138+
// To use a custom Registry, use [Encoder.SetRegistry] or [Decoder.SetRegistry].
139+
//
154140
// [Work with BSON]: https://www.mongodb.com/docs/drivers/go/current/fundamentals/bson/
155141
package bson

internal/integration/unified/matches.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,32 @@ func evaluateSpecialComparison(ctx context.Context, assertionDoc bson.Raw, actua
242242
return fmt.Errorf("expected lsid %v, got %v", expectedID, actualID)
243243
}
244244
case "$$lte":
245-
if assertionVal.Type != bson.TypeInt32 && assertionVal.Type != bson.TypeInt64 {
246-
return fmt.Errorf("expected assertionVal to be an Int32 or Int64 but got a %s", assertionVal.Type)
245+
if assertionVal.Type != bson.TypeInt32 && assertionVal.Type != bson.TypeInt64 && assertionVal.Type != bson.TypeDouble {
246+
return fmt.Errorf("expected assertionVal to be an Int32, Int64, or Double but got a %s", assertionVal.Type)
247247
}
248-
if actual.Type != bson.TypeInt32 && actual.Type != bson.TypeInt64 {
249-
return fmt.Errorf("expected value to be an Int32 or Int64 but got a %s", actual.Type)
248+
if actual.Type != bson.TypeInt32 && actual.Type != bson.TypeInt64 && assertionVal.Type != bson.TypeDouble {
249+
return fmt.Errorf("expected value to be an Int32, Int64, or Double but got a %s", actual.Type)
250250
}
251251

252252
// Numeric values can be compared even if their types are different (e.g. if expected is an int32 and actual
253253
// is an int64).
254-
expectedInt64 := assertionVal.AsInt64()
255-
actualInt64 := actual.AsInt64()
256-
if actualInt64 > expectedInt64 {
257-
return fmt.Errorf("expected numeric value %d to be less than or equal %d", actualInt64, expectedInt64)
254+
255+
// TODO(GODRIVER-3594): If we decide to add AsDoubleOK() as a method to RawValue, this following conversion should be updated.
256+
var expectedF64 float64
257+
if assertionVal.Type == bson.TypeDouble {
258+
expectedF64 = assertionVal.Double()
259+
} else {
260+
expectedF64 = float64(assertionVal.AsInt64())
261+
}
262+
var actualF64 float64
263+
if actual.Type == bson.TypeDouble {
264+
actualF64 = actual.Double()
265+
} else {
266+
actualF64 = float64(actual.AsInt64())
267+
}
268+
269+
if actualF64 > expectedF64 {
270+
return fmt.Errorf("expected numeric value %f to be less than or equal %f", actualF64, expectedF64)
258271
}
259272
return nil
260273
case "$$matchAsDocument":

internal/integtest/integtest.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ func AddServerlessAuthCredentials(uri string) (string, error) {
223223

224224
// ConnString gets the globally configured connection string.
225225
func ConnString(t *testing.T) *connstring.ConnString {
226+
if testing.Short() {
227+
t.Skip("skipping integration test in short mode")
228+
}
229+
226230
connectionStringOnce.Do(func() {
227231
uri, err := MongoDBURI()
228232
require.NoError(t, err, "error constructing mongodb URI: %v", err)

internal/spectest/skip.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import "testing"
1111
// skipTests is a map of "fully-qualified test name" to "the reason for skipping
1212
// the test".
1313
var skipTests = map[string][]string{
14-
// TODO(GODRIVER-3518): Test flexible numeric comparisons with $$lte
15-
"Modifies $$lte operator test to also use floating point and Int64 types (GODRIVER-3518)": {
16-
"TestUnifiedSpec/unified-test-format/tests/valid-pass/operator-lte.json/special_lte_matching_operator",
17-
},
1814

1915
// SPEC-1403: This test checks to see if the correct error is thrown when auto
2016
// encrypting with a server < 4.2. Currently, the test will fail because a

internal/test/aws/aws_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import (
2020

2121
func TestAWS(t *testing.T) {
2222
uri := os.Getenv("MONGODB_URI")
23+
if uri == "" {
24+
t.Skip("Skipping test: MONGODB_URI environment variable is not set")
25+
}
2326

2427
client, err := mongo.Connect(options.Client().ApplyURI(uri))
25-
require.NoError(t, err, "Connect error")
2628

2729
defer func() {
2830
err = client.Disconnect(context.Background())

internal/test/compilecheck/compile_check_test.go

Lines changed: 10 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,38 @@ package main
88

99
import (
1010
"context"
11-
"encoding/json"
1211
"fmt"
1312
"io"
14-
"net/http"
1513
"os"
1614
"path/filepath"
17-
"strings"
1815
"testing"
1916

2017
"github.com/stretchr/testify/assert"
2118
"github.com/stretchr/testify/require"
2219
"github.com/testcontainers/testcontainers-go"
23-
"golang.org/x/mod/semver"
2420
)
2521

2622
// TODO(GODRIVER-3515): This module cannot be included in the workspace since it
2723
// requires a version of klauspost/compress that is not compatible with the Go
2824
// Driver. Must use GOWORK=off to run this test.
2925

30-
const minSupportedVersion = "1.19"
26+
// TODO(GODRIVER-3592): Add "1.25" to the list when Go 1.25 is released.
27+
// Estimated release date is August 2025.
28+
var versions = []string{
29+
"1.19",
30+
"1.20",
31+
"1.21",
32+
"1.22",
33+
"1.23",
34+
"1.24",
35+
}
3136

3237
func TestCompileCheck(t *testing.T) {
3338
cwd, err := os.Getwd()
3439
require.NoError(t, err)
3540

3641
rootDir := filepath.Dir(filepath.Dir(filepath.Dir(cwd)))
3742

38-
versions, err := getDockerGolangImages()
39-
require.NoError(t, err)
40-
4143
for _, version := range versions {
4244
version := version // Capture range variable.
4345

@@ -85,67 +87,3 @@ func TestCompileCheck(t *testing.T) {
8587
})
8688
}
8789
}
88-
89-
// getDockerGolangImages retrieves the available Golang Docker image tags from
90-
// Docker Hub that are considered valid and meet the specified version
91-
// condition. It returns a slice of version strings in the MajorMinor format and
92-
// an error, if any.
93-
func getDockerGolangImages() ([]string, error) {
94-
// URL to fetch the Golang tags from Docker Hub with a page size of 100
95-
// records.
96-
var url = "https://hub.docker.com/v2/repositories/library/golang/tags?page_size=100"
97-
98-
versionSet := map[string]bool{}
99-
versions := []string{}
100-
101-
// Iteratively fetch and process tags from Docker Hub as long as there is a
102-
// valid next page URL.
103-
for url != "" {
104-
resp, err := http.Get(url)
105-
if err != nil {
106-
return nil, fmt.Errorf("failed to get response from Docker Hub: %w", err)
107-
}
108-
109-
var data struct {
110-
Results []struct {
111-
Name string `json:"name"`
112-
} `json:"results"`
113-
Next string `json:"next"` // URL of the next page for pagination.
114-
}
115-
116-
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
117-
resp.Body.Close()
118-
119-
return nil, fmt.Errorf("failed to decode response Body from Docker Hub: %w", err)
120-
}
121-
122-
resp.Body.Close()
123-
124-
for _, tag := range data.Results {
125-
// Skip tags that don't start with a digit (typically version numbers).
126-
if len(tag.Name) == 0 || tag.Name[0] < '0' || tag.Name[0] > '9' {
127-
continue
128-
}
129-
130-
// Split the tag name and extract the base version part.
131-
// This handles tags like `1.18.1-alpine` by extracting `1.18.1`.
132-
base := strings.Split(tag.Name, "-")[0]
133-
134-
// Reduce the base version to MajorMinor format (e.g., `v1.18`).
135-
baseMajMin := semver.MajorMinor("v" + base)
136-
if !semver.IsValid(baseMajMin) || versionSet[baseMajMin] {
137-
continue
138-
}
139-
140-
if semver.Compare(baseMajMin, "v"+minSupportedVersion) >= 0 {
141-
versionSet[baseMajMin] = true
142-
versions = append(versions, baseMajMin[1:])
143-
}
144-
}
145-
146-
// Move to the next page of results, set by the `Next` field.
147-
url = data.Next
148-
}
149-
150-
return versions, nil
151-
}

internal/test/compilecheck/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ toolchain go1.23.1
77
require (
88
github.com/stretchr/testify v1.10.0
99
github.com/testcontainers/testcontainers-go v0.35.0
10-
golang.org/x/mod v0.24.0
1110
)
1211

1312
require (

0 commit comments

Comments
 (0)