-
Notifications
You must be signed in to change notification settings - Fork 918
GODRIVER-3284 Allow valid SRV hostnames with less than 3 parts. #1898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
x/mongo/driver/connstring/initial_dns_seedlist_discovery_prose_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // Copyright (C) MongoDB, Inc. 2024-present. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
| // not use this file except in compliance with the License. You may obtain | ||
| // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| package connstring | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net" | ||
| "testing" | ||
|
|
||
| "go.mongodb.org/mongo-driver/v2/internal/assert" | ||
| "go.mongodb.org/mongo-driver/v2/x/mongo/driver/dns" | ||
| ) | ||
|
|
||
| func TestInitialDNSSeedlistDiscoveryProse(t *testing.T) { | ||
| newTestParser := func(record string) *parser { | ||
| return &parser{&dns.Resolver{ | ||
| LookupSRV: func(_, _, _ string) (string, []*net.SRV, error) { | ||
| return "", []*net.SRV{ | ||
| { | ||
| Target: record, | ||
| Port: 27017, | ||
| }, | ||
| }, nil | ||
| }, | ||
| LookupTXT: func(string) ([]string, error) { | ||
| return nil, nil | ||
| }, | ||
| }} | ||
| } | ||
|
|
||
| t.Run("1. Allow SRVs with fewer than 3 . separated parts", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| cases := []struct { | ||
| record string | ||
| uri string | ||
| }{ | ||
| {"test_1.localhost", "mongodb+srv://localhost"}, | ||
| {"test_1.mongo.local", "mongodb+srv://mongo.local"}, | ||
| } | ||
| for _, c := range cases { | ||
| c := c | ||
| t.Run(c.uri, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| _, err := newTestParser(c.record).parse(c.uri) | ||
| assert.NoError(t, err, "expected no URI parsing error, got %v", err) | ||
| }) | ||
| } | ||
| }) | ||
| t.Run("2. Throw when return address does not end with SRV domain", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| cases := []struct { | ||
| record string | ||
| uri string | ||
| }{ | ||
| {"localhost.mongodb", "mongodb+srv://localhost"}, | ||
| {"test_1.evil.local", "mongodb+srv://mongo.local"}, | ||
| {"blogs.evil.com", "mongodb+srv://blogs.mongodb.com"}, | ||
| } | ||
| for _, c := range cases { | ||
| c := c | ||
| t.Run(c.uri, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| _, err := newTestParser(c.record).parse(c.uri) | ||
| assert.ErrorContains(t, err, "Domain suffix from SRV record not matched input domain") | ||
| }) | ||
| } | ||
| }) | ||
| t.Run("3. Throw when return address is identical to SRV hostname", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| cases := []struct { | ||
| record string | ||
| uri string | ||
| labels int | ||
| }{ | ||
| {"localhost", "mongodb+srv://localhost", 2}, | ||
| {"mongo.local", "mongodb+srv://mongo.local", 3}, | ||
| } | ||
| for _, c := range cases { | ||
| c := c | ||
| t.Run(c.uri, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| _, err := newTestParser(c.record).parse(c.uri) | ||
| assert.ErrorContains(t, err, fmt.Sprintf("DNS name must contain at least %d labels", c.labels)) | ||
| }) | ||
| } | ||
| }) | ||
| t.Run("4. Throw when return address does not contain . separating shared part of domain", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| cases := []struct { | ||
| record string | ||
| uri string | ||
| }{ | ||
| {"test_1.cluster_1localhost", "mongodb+srv://localhost"}, | ||
| {"test_1.my_hostmongo.local", "mongodb+srv://mongo.local"}, | ||
| {"cluster.testmongodb.com", "mongodb+srv://blogs.mongodb.com"}, | ||
| } | ||
| for _, c := range cases { | ||
| c := c | ||
| t.Run(c.uri, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| _, err := newTestParser(c.record).parse(c.uri) | ||
| assert.ErrorContains(t, err, "Domain suffix from SRV record not matched input domain") | ||
| }) | ||
| } | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error is sort of ambiguous to me. What are your thoughts on matching what node.js does? https://github.com/mongodb/node-mongodb-native/pull/4197/files#diff-39b2554fd18da165b59a6351b1aafff3714e2a80c1435f2de9706355b4d32351R1181