From 4a04b51c2617051cb09a5cf2f6ad1099c40af15f Mon Sep 17 00:00:00 2001 From: Preston Vasquez <24281431+prestonvasquez@users.noreply.github.com> Date: Mon, 7 Nov 2022 19:22:33 -0700 Subject: [PATCH 1/9] GODRIVER-2333 Assert that Ping op succeeds initial DNS spec tests --- .../initial_dns_seedlist_discovery_test.go | 39 +++++++++++++++++++ .../loadBalanced-directConnection.json | 3 +- .../loadBalanced-directConnection.yml | 1 + .../load-balanced/loadBalanced-true-txt.json | 3 +- .../load-balanced/loadBalanced-true-txt.yml | 1 + .../load-balanced/srvMaxHosts-zero-txt.json | 3 +- .../load-balanced/srvMaxHosts-zero-txt.yml | 1 + .../load-balanced/srvMaxHosts-zero.json | 3 +- .../load-balanced/srvMaxHosts-zero.yml | 1 + .../replica-set/direct-connection-false.json | 7 ++-- .../replica-set/direct-connection-false.yml | 1 + .../replica-set/encoded-userinfo-and-db.json | 22 +++++++++++ .../replica-set/encoded-userinfo-and-db.yml | 19 +++++++++ .../replica-set/loadBalanced-false-txt.json | 3 +- .../replica-set/loadBalanced-false-txt.yml | 1 + .../replica-set/longer-parent-in-return.json | 1 + .../replica-set/longer-parent-in-return.yml | 1 + .../replica-set/one-result-default-port.json | 3 +- .../replica-set/one-result-default-port.yml | 1 + .../one-txt-record-multiple-strings.json | 3 +- .../one-txt-record-multiple-strings.yml | 1 + .../replica-set/one-txt-record.json | 3 +- .../replica-set/one-txt-record.yml | 1 + .../replica-set/srv-service-name.json | 3 +- .../replica-set/srv-service-name.yml | 1 + .../srvMaxHosts-equal_to_srv_records.json | 3 +- .../srvMaxHosts-equal_to_srv_records.yml | 1 + .../srvMaxHosts-greater_than_srv_records.json | 3 +- .../srvMaxHosts-greater_than_srv_records.yml | 1 + .../srvMaxHosts-less_than_srv_records.json | 3 +- .../srvMaxHosts-less_than_srv_records.yml | 1 + .../replica-set/srvMaxHosts-zero-txt.json | 3 +- .../replica-set/srvMaxHosts-zero-txt.yml | 1 + .../replica-set/srvMaxHosts-zero.json | 3 +- .../replica-set/srvMaxHosts-zero.yml | 1 + .../replica-set/two-results-default-port.json | 3 +- .../replica-set/two-results-default-port.yml | 1 + .../two-results-nonstandard-port.json | 3 +- .../two-results-nonstandard-port.yml | 1 + ...txt-record-with-overridden-ssl-option.json | 3 +- .../txt-record-with-overridden-ssl-option.yml | 1 + ...txt-record-with-overridden-uri-option.json | 3 +- .../txt-record-with-overridden-uri-option.yml | 1 + .../replica-set/uri-with-admin-database.json | 3 +- .../replica-set/uri-with-admin-database.yml | 1 + .../replica-set/uri-with-auth.json | 22 +++++++++++ .../replica-set/uri-with-auth.yml | 19 +++++++++ .../srvMaxHosts-equal_to_srv_records.json | 3 +- .../srvMaxHosts-equal_to_srv_records.yml | 1 + .../srvMaxHosts-greater_than_srv_records.json | 3 +- .../srvMaxHosts-greater_than_srv_records.yml | 1 + .../srvMaxHosts-less_than_srv_records.json | 3 +- .../srvMaxHosts-less_than_srv_records.yml | 1 + .../sharded/srvMaxHosts-zero.json | 3 +- .../sharded/srvMaxHosts-zero.yml | 1 + 55 files changed, 196 insertions(+), 27 deletions(-) create mode 100644 testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json create mode 100644 testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.yml create mode 100644 testdata/initial-dns-seedlist-discovery/replica-set/uri-with-auth.json create mode 100644 testdata/initial-dns-seedlist-discovery/replica-set/uri-with-auth.yml diff --git a/mongo/integration/initial_dns_seedlist_discovery_test.go b/mongo/integration/initial_dns_seedlist_discovery_test.go index 10cd49bd0a..adcd08684e 100644 --- a/mongo/integration/initial_dns_seedlist_discovery_test.go +++ b/mongo/integration/initial_dns_seedlist_discovery_test.go @@ -15,12 +15,15 @@ import ( "runtime" "strings" "testing" + "time" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/internal/testutil/assert" + "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/description" "go.mongodb.org/mongo-driver/mongo/integration/mtest" "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/mongo/readpref" "go.mongodb.org/mongo-driver/x/mongo/driver/connstring" "go.mongodb.org/mongo-driver/x/mongo/driver/topology" ) @@ -37,6 +40,7 @@ type seedlistTest struct { NumHosts *int `bson:"numHosts"` Error bool `bson:"error"` Options bson.Raw `bson:"options"` + Ping bool `bson:"ping"` } func TestInitialDNSSeedlistDiscoverySpec(t *testing.T) { @@ -63,6 +67,38 @@ func runSeedlistDiscoveryDirectory(mt *mtest.T, subdirectory string) { } } +// runSeedListDiscoverPingTest will create a new connection using the test URI and ping the server. +func runSeedListDiscoveryPingTest(mt *mtest.T, tcase seedlistTest) { + mt.Parallel() + + if !tcase.Ping { + return + } + + // Create a new connection using the test URI. + opts := options.Client().ApplyURI(tcase.URI) + + // If the test case expects SSL, set the CA file. + if tlsConfig := getSSLSettings(mt, tcase); tlsConfig != nil { + opts.SetTLSConfig(tlsConfig) + } + + ctx := context.Background() + + client, err := mongo.Connect(ctx, opts) + assert.Nil(mt, err, "Connect error: %v", err) + + mt.Cleanup(func() { _ = client.Disconnect(ctx) }) + + // Create a context with a timeout to prevent the ping operation from blocking indefinitely. + pingCtx, cancel := context.WithTimeout(ctx, 1*time.Second) + defer cancel() + + // Ping the server. + err = client.Ping(pingCtx, readpref.Nearest()) + assert.Nil(mt, err, "Ping error: %v", err) +} + func runSeedlistDiscoveryTest(mt *mtest.T, file string) { content, err := ioutil.ReadFile(file) assert.Nil(mt, err, "ReadFile error for %v: %v", file, err) @@ -131,6 +167,8 @@ func runSeedlistDiscoveryTest(mt *mtest.T, file string) { _, err := getServerByAddress(host, topo) assert.Nil(mt, err, "error finding host %q: %v", host, err) } + + runSeedListDiscoveryPingTest(mt, test) } func buildSet(list []string) map[string]struct{} { @@ -230,6 +268,7 @@ func getServerByAddress(address string, topo *topology.Topology) (description.Se if err != nil { return description.Server{}, err } + selectedServerConnection, err := selectedServer.Connection(context.Background()) if err != nil { return description.Server{}, err diff --git a/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.json b/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.json index 3f500acdc6..8e459115c1 100644 --- a/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.json +++ b/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.json @@ -10,5 +10,6 @@ "loadBalanced": true, "ssl": true, "directConnection": false - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.yml b/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.yml index c8395f7786..7a77944a30 100644 --- a/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.yml +++ b/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-directConnection.yml @@ -11,3 +11,4 @@ options: loadBalanced: true ssl: true directConnection: false +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.json b/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.json index f9719e760d..39bff5a23b 100644 --- a/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.json +++ b/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.json @@ -9,5 +9,6 @@ "options": { "loadBalanced": true, "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.yml b/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.yml index a172bda52b..c373192f01 100644 --- a/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.yml +++ b/testdata/initial-dns-seedlist-discovery/load-balanced/loadBalanced-true-txt.yml @@ -8,3 +8,4 @@ hosts: options: loadBalanced: true ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.json b/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.json index a18360ea64..474a314fd7 100644 --- a/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.json +++ b/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.json @@ -10,5 +10,6 @@ "loadBalanced": true, "srvMaxHosts": 0, "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.yml b/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.yml index 986164e3b9..f223a8d558 100644 --- a/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.yml +++ b/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero-txt.yml @@ -8,3 +8,4 @@ options: loadBalanced: true srvMaxHosts: 0 ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.json b/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.json index bd85418117..dfc90dc96d 100644 --- a/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.json +++ b/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.json @@ -10,5 +10,6 @@ "loadBalanced": true, "srvMaxHosts": 0, "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.yml b/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.yml index 7dc1593484..f8343e0e3e 100644 --- a/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.yml +++ b/testdata/initial-dns-seedlist-discovery/load-balanced/srvMaxHosts-zero.yml @@ -8,3 +8,4 @@ options: loadBalanced: true srvMaxHosts: 0 ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/direct-connection-false.json b/testdata/initial-dns-seedlist-discovery/replica-set/direct-connection-false.json index 1d57bdcb3c..8c90a4a0a0 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/direct-connection-false.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/direct-connection-false.json @@ -4,12 +4,11 @@ "localhost.test.build.10gen.cc:27017" ], "hosts": [ - "localhost:27017", - "localhost:27018", - "localhost:27019" + "mongo-rs-ssl1:27017" ], "options": { "ssl": true, "directConnection": false - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/direct-connection-false.yml b/testdata/initial-dns-seedlist-discovery/replica-set/direct-connection-false.yml index 20a32da594..21de8dc771 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/direct-connection-false.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/direct-connection-false.yml @@ -8,3 +8,4 @@ hosts: options: ssl: true directConnection: false +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json b/testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json new file mode 100644 index 0000000000..4493628be9 --- /dev/null +++ b/testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json @@ -0,0 +1,22 @@ +{ + "uri": "mongodb+srv://b*b%40f3tt%3D:%244to%40L8%3DMC@test3.test.build.10gen.cc/mydb%3F?replicaSet=repl0", + "seeds": [ + "localhost.test.build.10gen.cc:27017" + ], + "hosts": [ + "localhost:27017", + "localhost:27018", + "localhost:27019" + ], + "options": { + "replicaSet": "repl0", + "ssl": true + }, + "parsed_options": { + "user": "b*b@f3tt=", + "password": "$4to@L8=MC", + "db": "mydb?" + }, + "ping": false, + "comment": "Encoded user, pass, and DB parse correctly" +} diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.yml b/testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.yml new file mode 100644 index 0000000000..4b25a46db5 --- /dev/null +++ b/testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.yml @@ -0,0 +1,19 @@ +uri: "mongodb+srv://b*b%40f3tt%3D:%244to%40L8%3DMC@test3.test.build.10gen.cc/mydb%3F?replicaSet=repl0" +seeds: + - localhost.test.build.10gen.cc:27017 +hosts: + - localhost:27017 + - localhost:27018 + - localhost:27019 +options: + replicaSet: repl0 + ssl: true +parsed_options: + user: "b*b@f3tt=" + password: "$4to@L8=MC" + db: "mydb?" +# Don't run a ping for URIs that include userinfo. Ping doesn't require authentication, so missing +# userinfo isn't a problem, but some drivers will fail handshake on a connection if userinfo is +# provided but incorrect. +ping: false +comment: Encoded user, pass, and DB parse correctly diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/loadBalanced-false-txt.json b/testdata/initial-dns-seedlist-discovery/replica-set/loadBalanced-false-txt.json index fd2e565c7b..682d32a742 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/loadBalanced-false-txt.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/loadBalanced-false-txt.json @@ -11,5 +11,6 @@ "options": { "loadBalanced": false, "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/loadBalanced-false-txt.yml b/testdata/initial-dns-seedlist-discovery/replica-set/loadBalanced-false-txt.yml index 424d192072..c7e31da131 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/loadBalanced-false-txt.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/loadBalanced-false-txt.yml @@ -8,3 +8,4 @@ hosts: options: loadBalanced: false ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/longer-parent-in-return.json b/testdata/initial-dns-seedlist-discovery/replica-set/longer-parent-in-return.json index 9a8267eaeb..ebe3fe1e77 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/longer-parent-in-return.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/longer-parent-in-return.json @@ -12,5 +12,6 @@ "replicaSet": "repl0", "ssl": true }, + "ping": true, "comment": "Is correct, as returned host name shared the URI root \"test.build.10gen.cc\"." } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/longer-parent-in-return.yml b/testdata/initial-dns-seedlist-discovery/replica-set/longer-parent-in-return.yml index e77c4570d3..92b54ae57f 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/longer-parent-in-return.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/longer-parent-in-return.yml @@ -8,4 +8,5 @@ hosts: options: replicaSet: repl0 ssl: true +ping: true comment: Is correct, as returned host name shared the URI root "test.build.10gen.cc". diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/one-result-default-port.json b/testdata/initial-dns-seedlist-discovery/replica-set/one-result-default-port.json index cebb3b1ec3..9f7733de80 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/one-result-default-port.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/one-result-default-port.json @@ -11,5 +11,6 @@ "options": { "replicaSet": "repl0", "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/one-result-default-port.yml b/testdata/initial-dns-seedlist-discovery/replica-set/one-result-default-port.yml index 395bcdc968..748d4634ea 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/one-result-default-port.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/one-result-default-port.yml @@ -8,3 +8,4 @@ hosts: options: replicaSet: repl0 ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record-multiple-strings.json b/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record-multiple-strings.json index 622668c351..1d740b1b59 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record-multiple-strings.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record-multiple-strings.json @@ -11,5 +11,6 @@ "options": { "replicaSet": "repl0", "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record-multiple-strings.yml b/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record-multiple-strings.yml index 90a702cdbe..2f353ffb74 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record-multiple-strings.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record-multiple-strings.yml @@ -8,3 +8,4 @@ hosts: options: replicaSet: repl0 ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record.json b/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record.json index 2385021ad4..ecdb0a7e2a 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record.json @@ -12,5 +12,6 @@ "replicaSet": "repl0", "authSource": "thisDB", "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record.yml b/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record.yml index 9356eaa2c2..3bc0f0405c 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/one-txt-record.yml @@ -9,3 +9,4 @@ options: replicaSet: repl0 authSource: thisDB ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/srv-service-name.json b/testdata/initial-dns-seedlist-discovery/replica-set/srv-service-name.json index ec36cdbb00..e320c2ca3e 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/srv-service-name.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/srv-service-name.json @@ -12,5 +12,6 @@ "options": { "ssl": true, "srvServiceName": "customname" - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/srv-service-name.yml b/testdata/initial-dns-seedlist-discovery/replica-set/srv-service-name.yml index b6f25d0ca7..3bf9c2c676 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/srv-service-name.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/srv-service-name.yml @@ -9,3 +9,4 @@ hosts: options: ssl: true srvServiceName: "customname" +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-equal_to_srv_records.json b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-equal_to_srv_records.json index d9765ac663..70edacfd06 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-equal_to_srv_records.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-equal_to_srv_records.json @@ -13,5 +13,6 @@ "options": { "srvMaxHosts": 2, "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-equal_to_srv_records.yml b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-equal_to_srv_records.yml index 6d905809b9..b483279614 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-equal_to_srv_records.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-equal_to_srv_records.yml @@ -14,3 +14,4 @@ hosts: options: srvMaxHosts: 2 ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-greater_than_srv_records.json b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-greater_than_srv_records.json index 494bb87687..72540ed408 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-greater_than_srv_records.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-greater_than_srv_records.json @@ -12,5 +12,6 @@ "options": { "srvMaxHosts": 3, "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-greater_than_srv_records.yml b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-greater_than_srv_records.yml index 03307f8110..363dd4fd8b 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-greater_than_srv_records.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-greater_than_srv_records.yml @@ -13,3 +13,4 @@ hosts: options: srvMaxHosts: 3 ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.json b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.json index 66a5e90dad..a9d6dd6fd9 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.json @@ -9,5 +9,6 @@ "options": { "srvMaxHosts": 1, "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.yml b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.yml index 4ff86a623f..1143ab375f 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-less_than_srv_records.yml @@ -13,3 +13,4 @@ hosts: options: srvMaxHosts: 1 ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero-txt.json b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero-txt.json index 241a901c64..e232edb9eb 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero-txt.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero-txt.json @@ -13,5 +13,6 @@ "replicaSet": "repl0", "srvMaxHosts": 0, "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero-txt.yml b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero-txt.yml index 0df9fb49f4..81e92a09b1 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero-txt.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero-txt.yml @@ -13,3 +13,4 @@ options: replicaSet: repl0 srvMaxHosts: 0 ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero.json b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero.json index c68610a201..3421a35a3d 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero.json @@ -13,5 +13,6 @@ "replicaSet": "repl0", "srvMaxHosts": 0, "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero.yml b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero.yml index 3092889205..d095b6d677 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/srvMaxHosts-zero.yml @@ -13,3 +13,4 @@ options: replicaSet: repl0 srvMaxHosts: 0 ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/two-results-default-port.json b/testdata/initial-dns-seedlist-discovery/replica-set/two-results-default-port.json index 66028310a6..43efcc6310 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/two-results-default-port.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/two-results-default-port.json @@ -12,5 +12,6 @@ "options": { "replicaSet": "repl0", "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/two-results-default-port.yml b/testdata/initial-dns-seedlist-discovery/replica-set/two-results-default-port.yml index 61d38b5e82..c3f7156dc7 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/two-results-default-port.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/two-results-default-port.yml @@ -9,3 +9,4 @@ hosts: options: replicaSet: repl0 ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/two-results-nonstandard-port.json b/testdata/initial-dns-seedlist-discovery/replica-set/two-results-nonstandard-port.json index 4900f7cff1..f6e8e415a7 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/two-results-nonstandard-port.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/two-results-nonstandard-port.json @@ -12,5 +12,6 @@ "options": { "replicaSet": "repl0", "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/two-results-nonstandard-port.yml b/testdata/initial-dns-seedlist-discovery/replica-set/two-results-nonstandard-port.yml index 7185f52cd6..fe66308111 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/two-results-nonstandard-port.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/two-results-nonstandard-port.yml @@ -9,3 +9,4 @@ hosts: options: replicaSet: repl0 ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-ssl-option.json b/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-ssl-option.json index 0ebc737bd5..3d84cfe446 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-ssl-option.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-ssl-option.json @@ -12,5 +12,6 @@ "replicaSet": "repl0", "authSource": "thisDB", "ssl": false - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-ssl-option.yml b/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-ssl-option.yml index 2a922aa234..8d1a46c396 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-ssl-option.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-ssl-option.yml @@ -9,3 +9,4 @@ options: replicaSet: repl0 authSource: thisDB ssl: false +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-uri-option.json b/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-uri-option.json index 2626ba6083..1a5a240680 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-uri-option.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-uri-option.json @@ -12,5 +12,6 @@ "replicaSet": "repl0", "authSource": "otherDB", "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-uri-option.yml b/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-uri-option.yml index a9015599e7..200ac6803e 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-uri-option.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/txt-record-with-overridden-uri-option.yml @@ -9,3 +9,4 @@ options: replicaSet: repl0 authSource: otherDB ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-admin-database.json b/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-admin-database.json index 32710d75f7..c5513a0dad 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-admin-database.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-admin-database.json @@ -15,5 +15,6 @@ }, "parsed_options": { "auth_database": "adminDB" - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-admin-database.yml b/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-admin-database.yml index fb714bde0e..012e9a023e 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-admin-database.yml +++ b/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-admin-database.yml @@ -11,3 +11,4 @@ options: ssl: true parsed_options: auth_database: adminDB +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-auth.json b/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-auth.json new file mode 100644 index 0000000000..872f997cc7 --- /dev/null +++ b/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-auth.json @@ -0,0 +1,22 @@ +{ + "uri": "mongodb+srv://auser:apass@test1.test.build.10gen.cc/?replicaSet=repl0", + "seeds": [ + "localhost.test.build.10gen.cc:27017", + "localhost.test.build.10gen.cc:27018" + ], + "hosts": [ + "localhost:27017", + "localhost:27018", + "localhost:27019" + ], + "options": { + "replicaSet": "repl0", + "ssl": true + }, + "parsed_options": { + "user": "auser", + "password": "apass" + }, + "ping": false, + "comment": "Should preserve auth credentials" +} diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-auth.yml b/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-auth.yml new file mode 100644 index 0000000000..95f9b96426 --- /dev/null +++ b/testdata/initial-dns-seedlist-discovery/replica-set/uri-with-auth.yml @@ -0,0 +1,19 @@ +uri: "mongodb+srv://auser:apass@test1.test.build.10gen.cc/?replicaSet=repl0" +seeds: + - localhost.test.build.10gen.cc:27017 + - localhost.test.build.10gen.cc:27018 +hosts: + - localhost:27017 + - localhost:27018 + - localhost:27019 +options: + replicaSet: repl0 + ssl: true +parsed_options: + user: auser + password: apass +# Don't run a ping for URIs that include userinfo. Ping doesn't require authentication, so missing +# userinfo isn't a problem, but some drivers will fail handshake on a connection if userinfo is +# provided but incorrect. +ping: false +comment: Should preserve auth credentials diff --git a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-equal_to_srv_records.json b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-equal_to_srv_records.json index 46390726f0..7d2f9a6bf8 100644 --- a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-equal_to_srv_records.json +++ b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-equal_to_srv_records.json @@ -12,5 +12,6 @@ "options": { "srvMaxHosts": 2, "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-equal_to_srv_records.yml b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-equal_to_srv_records.yml index 89692308b6..84aeac9aec 100644 --- a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-equal_to_srv_records.yml +++ b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-equal_to_srv_records.yml @@ -11,3 +11,4 @@ hosts: options: srvMaxHosts: 2 ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-greater_than_srv_records.json b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-greater_than_srv_records.json index e02d72bf28..452c7b54db 100644 --- a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-greater_than_srv_records.json +++ b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-greater_than_srv_records.json @@ -11,5 +11,6 @@ "options": { "srvMaxHosts": 3, "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-greater_than_srv_records.yml b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-greater_than_srv_records.yml index 860dfacbb4..8195fd0d33 100644 --- a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-greater_than_srv_records.yml +++ b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-greater_than_srv_records.yml @@ -10,3 +10,4 @@ hosts: options: srvMaxHosts: 3 ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-less_than_srv_records.json b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-less_than_srv_records.json index fdcc1692c0..cd3bf65117 100644 --- a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-less_than_srv_records.json +++ b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-less_than_srv_records.json @@ -5,5 +5,6 @@ "options": { "srvMaxHosts": 1, "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-less_than_srv_records.yml b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-less_than_srv_records.yml index 31849524df..e33429b67a 100644 --- a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-less_than_srv_records.yml +++ b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-less_than_srv_records.yml @@ -8,3 +8,4 @@ numHosts: 1 options: srvMaxHosts: 1 ssl: true +ping: true diff --git a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-zero.json b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-zero.json index 10ab9e656d..f289628c9c 100644 --- a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-zero.json +++ b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-zero.json @@ -11,5 +11,6 @@ "options": { "srvMaxHosts": 0, "ssl": true - } + }, + "ping": true } diff --git a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-zero.yml b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-zero.yml index 9043409dfd..5692ed09b8 100644 --- a/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-zero.yml +++ b/testdata/initial-dns-seedlist-discovery/sharded/srvMaxHosts-zero.yml @@ -9,3 +9,4 @@ hosts: options: srvMaxHosts: 0 ssl: true +ping: true From 0884cb332f581c56aca7f741b18473ae727aeeb1 Mon Sep 17 00:00:00 2001 From: Preston Vasquez <24281431+prestonvasquez@users.noreply.github.com> Date: Mon, 7 Nov 2022 19:36:18 -0700 Subject: [PATCH 2/9] GODRIVER-2333 mod direct-connection-false.json --- .../replica-set/direct-connection-false.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/direct-connection-false.json b/testdata/initial-dns-seedlist-discovery/replica-set/direct-connection-false.json index 8c90a4a0a0..3f14ff94e7 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/direct-connection-false.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/direct-connection-false.json @@ -4,7 +4,9 @@ "localhost.test.build.10gen.cc:27017" ], "hosts": [ - "mongo-rs-ssl1:27017" + "localhost:27017", + "localhost:27018", + "localhost:27019" ], "options": { "ssl": true, From 67e7f5b80fc5368163d2a7a65e82bb95cb8b4447 Mon Sep 17 00:00:00 2001 From: Preston Vasquez <24281431+prestonvasquez@users.noreply.github.com> Date: Wed, 9 Nov 2022 14:17:08 -0700 Subject: [PATCH 3/9] GODRIVER-2333 add authenticatable routine --- x/mongo/driver/topology/topology_options.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/x/mongo/driver/topology/topology_options.go b/x/mongo/driver/topology/topology_options.go index 98b71ea383..fe02c7e88a 100644 --- a/x/mongo/driver/topology/topology_options.go +++ b/x/mongo/driver/topology/topology_options.go @@ -50,6 +50,16 @@ func ConvertToDriverAPIOptions(s *options.ServerAPIOptions) *driver.ServerAPIOpt return driverOpts } +// authenticatable will return true if the authentication credentials are configured in a way that would require the +// handshaker to authenticate. +func authenticatable(cred *options.Credential) bool { + if cred == nil { + return false + } + + return cred.Username != "" || cred.AuthMechanism == auth.MongoDBX509 || cred.AuthMechanism == auth.GSSAPI +} + // NewConfig will translate data from client options into a topology config for building non-default deployments. // Server and topoplogy options are not honored if a custom deployment is used. func NewConfig(co *options.ClientOptions, clock *session.ClusterClock) (*Config, error) { @@ -139,8 +149,10 @@ func NewConfig(co *options.ClientOptions, clock *session.ClusterClock) (*Config, return operation.NewHello().AppName(appName).Compressors(comps).ClusterClock(clock). ServerAPI(serverAPI).LoadBalanced(loadBalanced) } + // Auth & Database & Password & Username - if co.Auth != nil { + // cs.Username != "" || cs.AuthMechanism == auth.MongoDBX509 || cs.AuthMechanism == auth.GSSAPI + if authenticatable(co.Auth) { cred := &auth.Cred{ Username: co.Auth.Username, Password: co.Auth.Password, @@ -148,6 +160,7 @@ func NewConfig(co *options.ClientOptions, clock *session.ClusterClock) (*Config, Props: co.Auth.AuthMechanismProperties, Source: co.Auth.AuthSource, } + mechanism := co.Auth.AuthMechanism if len(cred.Source) == 0 { @@ -178,6 +191,7 @@ func NewConfig(co *options.ClientOptions, clock *session.ClusterClock) (*Config, // Required for SASL mechanism negotiation during handshake handshakeOpts.DBUser = cred.Source + "." + cred.Username } + if co.AuthenticateToAnything != nil && *co.AuthenticateToAnything { // Authenticate arbiters handshakeOpts.PerformAuthentication = func(serv description.Server) bool { @@ -189,7 +203,9 @@ func NewConfig(co *options.ClientOptions, clock *session.ClusterClock) (*Config, return auth.Handshaker(nil, handshakeOpts) } } + connOpts = append(connOpts, WithHandshaker(handshaker)) + // ConnectTimeout if co.ConnectTimeout != nil { serverOpts = append(serverOpts, WithHeartbeatTimeout( From 9099b05a7b4907dbe8683c6916fd3f4a40bcc451 Mon Sep 17 00:00:00 2001 From: Preston Vasquez <24281431+prestonvasquez@users.noreply.github.com> Date: Thu, 10 Nov 2022 15:03:55 -0700 Subject: [PATCH 4/9] GODRIVER-2333 add logic to use topolog server selection desc --- .../initial_dns_seedlist_discovery_test.go | 9 +++- .../replica-set/encoded-userinfo-and-db.json | 42 +++++++++---------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/mongo/integration/initial_dns_seedlist_discovery_test.go b/mongo/integration/initial_dns_seedlist_discovery_test.go index adcd08684e..15006a1dc0 100644 --- a/mongo/integration/initial_dns_seedlist_discovery_test.go +++ b/mongo/integration/initial_dns_seedlist_discovery_test.go @@ -67,7 +67,7 @@ func runSeedlistDiscoveryDirectory(mt *mtest.T, subdirectory string) { } } -// runSeedListDiscoverPingTest will create a new connection using the test URI and ping the server. +// runSeedListDiscoverPingTest will create a new connection using the test URI and attempt to "ping" the server. func runSeedListDiscoveryPingTest(mt *mtest.T, tcase seedlistTest) { mt.Parallel() @@ -269,6 +269,13 @@ func getServerByAddress(address string, topo *topology.Topology) (description.Se return description.Server{}, err } + // If the selected server is a topology.SelectedServer, then we can get the description without creating a + // connect pool. + topologySelectedServer, ok := selectedServer.(*topology.SelectedServer) + if ok { + return topologySelectedServer.Description().Server, nil + } + selectedServerConnection, err := selectedServer.Connection(context.Background()) if err != nil { return description.Server{}, err diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json b/testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json index 4493628be9..eca4d194a1 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json @@ -1,22 +1,22 @@ { - "uri": "mongodb+srv://b*b%40f3tt%3D:%244to%40L8%3DMC@test3.test.build.10gen.cc/mydb%3F?replicaSet=repl0", - "seeds": [ - "localhost.test.build.10gen.cc:27017" - ], - "hosts": [ - "localhost:27017", - "localhost:27018", - "localhost:27019" - ], - "options": { - "replicaSet": "repl0", - "ssl": true - }, - "parsed_options": { - "user": "b*b@f3tt=", - "password": "$4to@L8=MC", - "db": "mydb?" - }, - "ping": false, - "comment": "Encoded user, pass, and DB parse correctly" -} + "uri": "mongodb+srv://b*b%40f3tt%3D:%244to%40L8%3DMC@test3.test.build.10gen.cc/mydb%3F?replicaSet=repl0", + "seeds": [ + "localhost.test.build.10gen.cc:27017" + ], + "hosts": [ + "localhost:27017", + "localhost:27018", + "localhost:27019" + ], + "options": { + "replicaSet": "repl0", + "ssl": true + }, + "parsed_options": { + "user": "b*b@f3tt=", + "password": "$4to@L8=MC", + "db": "mydb?" + }, + "ping": true, + "comment": "Encoded user, pass, and DB parse correctly" + } From 625fdda0b1560a037e544f64ea73572ede440854 Mon Sep 17 00:00:00 2001 From: Preston Vasquez <24281431+prestonvasquez@users.noreply.github.com> Date: Thu, 10 Nov 2022 16:40:13 -0700 Subject: [PATCH 5/9] GODRIVER-2333 sync replica_set/encoded-userinfo-and-db.json --- .../replica-set/encoded-userinfo-and-db.json | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json b/testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json index eca4d194a1..4493628be9 100644 --- a/testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json +++ b/testdata/initial-dns-seedlist-discovery/replica-set/encoded-userinfo-and-db.json @@ -1,22 +1,22 @@ { - "uri": "mongodb+srv://b*b%40f3tt%3D:%244to%40L8%3DMC@test3.test.build.10gen.cc/mydb%3F?replicaSet=repl0", - "seeds": [ - "localhost.test.build.10gen.cc:27017" - ], - "hosts": [ - "localhost:27017", - "localhost:27018", - "localhost:27019" - ], - "options": { - "replicaSet": "repl0", - "ssl": true - }, - "parsed_options": { - "user": "b*b@f3tt=", - "password": "$4to@L8=MC", - "db": "mydb?" - }, - "ping": true, - "comment": "Encoded user, pass, and DB parse correctly" - } + "uri": "mongodb+srv://b*b%40f3tt%3D:%244to%40L8%3DMC@test3.test.build.10gen.cc/mydb%3F?replicaSet=repl0", + "seeds": [ + "localhost.test.build.10gen.cc:27017" + ], + "hosts": [ + "localhost:27017", + "localhost:27018", + "localhost:27019" + ], + "options": { + "replicaSet": "repl0", + "ssl": true + }, + "parsed_options": { + "user": "b*b@f3tt=", + "password": "$4to@L8=MC", + "db": "mydb?" + }, + "ping": false, + "comment": "Encoded user, pass, and DB parse correctly" +} From 35f19c2971680ce7bfa6c2c86431cff898f07acf Mon Sep 17 00:00:00 2001 From: Preston Vasquez <24281431+prestonvasquez@users.noreply.github.com> Date: Fri, 11 Nov 2022 09:02:08 -0700 Subject: [PATCH 6/9] GODRIVER-2333 remove auth comment --- x/mongo/driver/topology/topology_options.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/mongo/driver/topology/topology_options.go b/x/mongo/driver/topology/topology_options.go index fe02c7e88a..36553c3e10 100644 --- a/x/mongo/driver/topology/topology_options.go +++ b/x/mongo/driver/topology/topology_options.go @@ -151,7 +151,6 @@ func NewConfig(co *options.ClientOptions, clock *session.ClusterClock) (*Config, } // Auth & Database & Password & Username - // cs.Username != "" || cs.AuthMechanism == auth.MongoDBX509 || cs.AuthMechanism == auth.GSSAPI if authenticatable(co.Auth) { cred := &auth.Cred{ Username: co.Auth.Username, From 04098c3acfeb0562e66fd665e5be26ff9f32f6ba Mon Sep 17 00:00:00 2001 From: Preston Vasquez <24281431+prestonvasquez@users.noreply.github.com> Date: Mon, 14 Nov 2022 14:00:12 -0700 Subject: [PATCH 7/9] GODRIVER-2333 pr requests and suggests --- .../initial_dns_seedlist_discovery_test.go | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/mongo/integration/initial_dns_seedlist_discovery_test.go b/mongo/integration/initial_dns_seedlist_discovery_test.go index 15006a1dc0..40cdc3a0f4 100644 --- a/mongo/integration/initial_dns_seedlist_discovery_test.go +++ b/mongo/integration/initial_dns_seedlist_discovery_test.go @@ -48,12 +48,18 @@ func TestInitialDNSSeedlistDiscoverySpec(t *testing.T) { defer mt.Close() mt.RunOpts("replica set", mtest.NewOptions().Topologies(mtest.ReplicaSet).CreateClient(false), func(mt *mtest.T) { + mt.Parallel() + runSeedlistDiscoveryDirectory(mt, "replica-set") }) mt.RunOpts("sharded", mtest.NewOptions().Topologies(mtest.Sharded).CreateClient(false), func(mt *mtest.T) { + mt.Parallel() + runSeedlistDiscoveryDirectory(mt, "sharded") }) mt.RunOpts("load balanced", mtest.NewOptions().Topologies(mtest.LoadBalanced).CreateClient(false), func(mt *mtest.T) { + mt.Parallel() + runSeedlistDiscoveryDirectory(mt, "load-balanced") }) } @@ -68,27 +74,13 @@ func runSeedlistDiscoveryDirectory(mt *mtest.T, subdirectory string) { } // runSeedListDiscoverPingTest will create a new connection using the test URI and attempt to "ping" the server. -func runSeedListDiscoveryPingTest(mt *mtest.T, tcase seedlistTest) { - mt.Parallel() - - if !tcase.Ping { - return - } - - // Create a new connection using the test URI. - opts := options.Client().ApplyURI(tcase.URI) - - // If the test case expects SSL, set the CA file. - if tlsConfig := getSSLSettings(mt, tcase); tlsConfig != nil { - opts.SetTLSConfig(tlsConfig) - } - +func runSeedListDiscoveryPingTest(mt *mtest.T, clientOpts *options.ClientOptions) { ctx := context.Background() - client, err := mongo.Connect(ctx, opts) + client, err := mongo.Connect(ctx, clientOpts) assert.Nil(mt, err, "Connect error: %v", err) - mt.Cleanup(func() { _ = client.Disconnect(ctx) }) + defer func() { _ = client.Disconnect(ctx) }() // Create a context with a timeout to prevent the ping operation from blocking indefinitely. pingCtx, cancel := context.WithTimeout(ctx, 1*time.Second) @@ -168,7 +160,9 @@ func runSeedlistDiscoveryTest(mt *mtest.T, file string) { assert.Nil(mt, err, "error finding host %q: %v", host, err) } - runSeedListDiscoveryPingTest(mt, test) + if test.Ping { + runSeedListDiscoveryPingTest(mt, opts) + } } func buildSet(list []string) map[string]struct{} { From 5f9fa2d12f6cc6ec536788bfdd57de83d9b48603 Mon Sep 17 00:00:00 2001 From: Preston Vasquez <24281431+prestonvasquez@users.noreply.github.com> Date: Tue, 15 Nov 2022 09:44:09 -0700 Subject: [PATCH 8/9] GODRIVER-2333 no ping only when false --- .../integration/initial_dns_seedlist_discovery_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mongo/integration/initial_dns_seedlist_discovery_test.go b/mongo/integration/initial_dns_seedlist_discovery_test.go index 40cdc3a0f4..3e4ef08d5d 100644 --- a/mongo/integration/initial_dns_seedlist_discovery_test.go +++ b/mongo/integration/initial_dns_seedlist_discovery_test.go @@ -40,7 +40,7 @@ type seedlistTest struct { NumHosts *int `bson:"numHosts"` Error bool `bson:"error"` Options bson.Raw `bson:"options"` - Ping bool `bson:"ping"` + Ping *bool `bson:"ping"` } func TestInitialDNSSeedlistDiscoverySpec(t *testing.T) { @@ -73,8 +73,8 @@ func runSeedlistDiscoveryDirectory(mt *mtest.T, subdirectory string) { } } -// runSeedListDiscoverPingTest will create a new connection using the test URI and attempt to "ping" the server. -func runSeedListDiscoveryPingTest(mt *mtest.T, clientOpts *options.ClientOptions) { +// runSeedlistDiscoveryPingTest will create a new connection using the test URI and attempt to "ping" the server. +func runSeedlistDiscoveryPingTest(mt *mtest.T, clientOpts *options.ClientOptions) { ctx := context.Background() client, err := mongo.Connect(ctx, clientOpts) @@ -160,8 +160,8 @@ func runSeedlistDiscoveryTest(mt *mtest.T, file string) { assert.Nil(mt, err, "error finding host %q: %v", host, err) } - if test.Ping { - runSeedListDiscoveryPingTest(mt, opts) + if ping := test.Ping; ping == nil || *ping { + runSeedlistDiscoveryPingTest(mt, opts) } } From b528e6cec8c2e940461d86bc9dbaca2ee77bdc58 Mon Sep 17 00:00:00 2001 From: Preston Vasquez <24281431+prestonvasquez@users.noreply.github.com> Date: Tue, 15 Nov 2022 11:28:02 -0700 Subject: [PATCH 9/9] GODRIVER-2333 revert auth validation --- x/mongo/driver/topology/topology_options.go | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/x/mongo/driver/topology/topology_options.go b/x/mongo/driver/topology/topology_options.go index 36553c3e10..98b71ea383 100644 --- a/x/mongo/driver/topology/topology_options.go +++ b/x/mongo/driver/topology/topology_options.go @@ -50,16 +50,6 @@ func ConvertToDriverAPIOptions(s *options.ServerAPIOptions) *driver.ServerAPIOpt return driverOpts } -// authenticatable will return true if the authentication credentials are configured in a way that would require the -// handshaker to authenticate. -func authenticatable(cred *options.Credential) bool { - if cred == nil { - return false - } - - return cred.Username != "" || cred.AuthMechanism == auth.MongoDBX509 || cred.AuthMechanism == auth.GSSAPI -} - // NewConfig will translate data from client options into a topology config for building non-default deployments. // Server and topoplogy options are not honored if a custom deployment is used. func NewConfig(co *options.ClientOptions, clock *session.ClusterClock) (*Config, error) { @@ -149,9 +139,8 @@ func NewConfig(co *options.ClientOptions, clock *session.ClusterClock) (*Config, return operation.NewHello().AppName(appName).Compressors(comps).ClusterClock(clock). ServerAPI(serverAPI).LoadBalanced(loadBalanced) } - // Auth & Database & Password & Username - if authenticatable(co.Auth) { + if co.Auth != nil { cred := &auth.Cred{ Username: co.Auth.Username, Password: co.Auth.Password, @@ -159,7 +148,6 @@ func NewConfig(co *options.ClientOptions, clock *session.ClusterClock) (*Config, Props: co.Auth.AuthMechanismProperties, Source: co.Auth.AuthSource, } - mechanism := co.Auth.AuthMechanism if len(cred.Source) == 0 { @@ -190,7 +178,6 @@ func NewConfig(co *options.ClientOptions, clock *session.ClusterClock) (*Config, // Required for SASL mechanism negotiation during handshake handshakeOpts.DBUser = cred.Source + "." + cred.Username } - if co.AuthenticateToAnything != nil && *co.AuthenticateToAnything { // Authenticate arbiters handshakeOpts.PerformAuthentication = func(serv description.Server) bool { @@ -202,9 +189,7 @@ func NewConfig(co *options.ClientOptions, clock *session.ClusterClock) (*Config, return auth.Handshaker(nil, handshakeOpts) } } - connOpts = append(connOpts, WithHandshaker(handshaker)) - // ConnectTimeout if co.ConnectTimeout != nil { serverOpts = append(serverOpts, WithHeartbeatTimeout(