Skip to content

Commit

Permalink
Merge pull request #95 from ni-kismet/tls-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
zookzook committed May 29, 2021
2 parents 21315d6 + fd6d671 commit 18c7777
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/mongo/mongo_db_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule Mongo.MongoDBConnection do
auth_mechanism: opts[:auth_mechanism] || nil,
connection_type: Keyword.fetch!(opts, :connection_type),
topology_pid: Keyword.fetch!(opts, :topology_pid),
ssl: opts[:ssl] || false
ssl: opts[:ssl] || opts[:tls] || false
}
connect(opts, state)
end
Expand Down
1 change: 1 addition & 0 deletions lib/mongo/url_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ defmodule Mongo.UrlParser do
"serverSelectionTryOnce" => ["true", "false"],
"heartbeatFrequencyMS" => :number,
"retryWrites" => ["true", "false"],
"tls" => ["true", "false"],
"uuidRepresentation" => ["standard", "csharpLegacy", "javaLegacy", "pythonLegacy"],
# Elixir Driver options
"type" => ["unknown", "single", "replicaSetNoPrimary", "sharded"]
Expand Down
22 changes: 21 additions & 1 deletion test/mongo/url_parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Mongo.UrlParserTest do
assert UrlParser.parse_url(url: "mongodb://localhost:27017") == [seeds: ["localhost:27017"]]
end

test "cluster url" do
test "cluster url with ssl" do
url =
"mongodb://user:password@seed1.domain.com:27017,seed2.domain.com:27017,seed3.domain.com:27017/db_name?ssl=true&replicaSet=set-name&authSource=admin&maxPoolSize=5"

Expand All @@ -29,6 +29,26 @@ defmodule Mongo.UrlParserTest do
]
end

test "cluster url with tls" do
url =
"mongodb://user:password@seed1.domain.com:27017,seed2.domain.com:27017,seed3.domain.com:27017/db_name?tls=true&replicaSet=set-name&authSource=admin&maxPoolSize=5"

assert UrlParser.parse_url(url: url) |> Keyword.drop([:pw_safe]) == [
password: "*****",
username: "user",
database: "db_name",
pool_size: 5,
auth_source: "admin",
set_name: "set-name",
tls: true,
seeds: [
"seed1.domain.com:27017",
"seed2.domain.com:27017",
"seed3.domain.com:27017"
]
]
end

test "merge options" do
assert UrlParser.parse_url(url: "mongodb://localhost:27017", name: :test, seeds: ["1234"]) ==
[seeds: ["localhost:27017"], name: :test]
Expand Down

0 comments on commit 18c7777

Please sign in to comment.