Repository navigation
fix(mongodb): connection strings with several hosts work (#1309) - #1325
Merged
Merged
Conversation
mongodb://h1:27017,h2:27017/db?replicaSet=rs0 is valid MongoDB, but Dart's Uri reads the host list as a port: the URL import said Invalid URL/URI format, and connecting, opening another database and tunnelling threw FormatException. - MongoUri splits a MongoDB string without Uri.parse and is used for the database name, the per-database URI, the TLS parameters and the tunnel target. - Through an SSH tunnel the string becomes the one local endpoint with directConnection=true; a mongodb+srv:// string cannot be tunnelled and says so. - The URL import reads the first seed and keeps the whole string; the certificate paths of a host-list string are found.
3 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #1309
Problem:
mongodb://h1:27017,h2:27017/db?replicaSet=rs0is valid MongoDB, butUri.tryParsereturnsnullfor it (the port segment is27017,h2:27017) andUri.parsethrows.MongoConnectioncalledUri.parseon the saved string: connecting (_effectiveMongoUri), opening another database (buildUriForDatabase), the effective database name and the SSH tunnel override all threwFormatException. A replica-set string typed into the form's connection-string field could not connect.Uri.tryParsenull), so TLS files were silently ignored.mongodb+srv://and a tunnel,replace(host:, port:)made an SRV URI with a port, which is invalid.Fix
MongoUri(core/database/mongodb_uri.dart): scheme, user info (kept encoded), host list, path, query parameters;databaseName,firstHost,copyWith,forTunnel,toString.MongoConnectionuses it for the effective database, the per-database URI (authSource defaulting as before), the TLS parameters and the tunnel target (first seed).forTunnel: one local endpoint plusdirectConnection=true(unless the string sets it), because the tunnel reaches one server and discovery would otherwise go to the members' own addresses. Amongodb+srv://string cannot be tunnelled and gets an explanation instead of a malformed URI.MongoUriwhenUrifails: the first seed fills host / port, the row keeps the whole string.extractSslCertificatePathsFromStringreads the query of a stringUrirejects.Tests:
mongodb_uri_test.dart(parse, round trip, SRV, IPv6, tunnel, the connection's database / per-database URI / authSource default / tunnel / SRV refusal, certificate paths) and two URL-import tests.