Skip to content

Commit

Permalink
bumped 0.7.3, added support for OTP 24
Browse files Browse the repository at this point in the history
  • Loading branch information
zookzook committed May 29, 2021
1 parent 18c7777 commit 8857943
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 22 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.7.3

* Enhancements
* added support for OTP 24
* Add support for tls setting in connection string (tschmittni)
* Replace deprecated functions (OTP 24) (aenglisc )

## 0.7.2

* Enhancements
Expand Down
36 changes: 26 additions & 10 deletions lib/mongo/auth/scram.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,33 @@ defmodule Mongo.Auth.SCRAM do
Mongo.PBKDF2Cache.pbkdf2(password, salt, iterations, digest)
end

defp generate_proof(salted_password, auth_message, digest) do
client_key = :crypto.mac(:hmac, digest, salted_password, "Client Key")
stored_key = :crypto.hash(digest, client_key)
signature = :crypto.mac(:hmac, digest, stored_key, auth_message)
client_proof = xor_keys(client_key, signature, "")
"p=#{Base.encode64(client_proof)}"
end
## support for OTP 22.x
if Code.ensure_loaded?(:crypto) and function_exported?(:crypto, :hmac, 3) do
defp generate_proof(salted_password, auth_message, digest) do
client_key = :crypto.hmac(digest, salted_password, "Client Key")
stored_key = :crypto.hash(digest, client_key)
signature = :crypto.hmac(digest, stored_key, auth_message)
client_proof = xor_keys(client_key, signature, "")
"p=#{Base.encode64(client_proof)}"
end

defp generate_signature(salted_password, auth_message, digest) do
server_key = :crypto.hmac(digest, salted_password, "Server Key")
:crypto.hmac(digest, server_key, auth_message)
end
else
defp generate_proof(salted_password, auth_message, digest) do
client_key = :crypto.mac(:hmac, digest, salted_password, "Client Key")
stored_key = :crypto.hash(digest, client_key)
signature = :crypto.mac(:hmac, digest, stored_key, auth_message)
client_proof = xor_keys(client_key, signature, "")
"p=#{Base.encode64(client_proof)}"
end

defp generate_signature(salted_password, auth_message, digest) do
server_key = :crypto.mac(:hmac, digest, salted_password, "Server Key")
:crypto.mac(:hmac, digest, server_key, auth_message)
defp generate_signature(salted_password, auth_message, digest) do
server_key = :crypto.mac(:hmac, digest, salted_password, "Server Key")
:crypto.mac(:hmac, digest, server_key, auth_message)
end
end

defp xor_keys("", "", result), do: result
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule Mongodb.Mixfile do
{:excoveralls, "~> 0.12.1", only: :test},
{:benchee, "~> 1.0", only: :dev},
{:jason, "~> 1.2", only: :test},
{:ex_doc, "~> 0.20.1 ", only: :dev},
{:ex_doc, "~> 0.24 ", only: :dev},
{:earmark, ">= 0.0.0", only: :dev},
{:dialyxir, "~> 0.5", only: [:dev], runtime: false}
]
Expand Down
12 changes: 7 additions & 5 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm", "6c32a70ed5d452c6650916555b1f96c79af5fc4bf286997f8b15f213de786f73"},
"earmark": {:hex, :earmark, "1.4.0", "397e750b879df18198afc66505ca87ecf6a96645545585899f6185178433cc09", [:mix], [], "hexpm", "4bedcec35de03b5f559fd2386be24d08f7637c374d3a85d3fe0911eecdae838a"},
"earmark": {:hex, :earmark, "1.4.15", "2c7f924bf495ec1f65bd144b355d0949a05a254d0ec561740308a54946a67888", [:mix], [{:earmark_parser, ">= 1.4.13", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "3b1209b85bc9f3586f370f7c363f6533788fb4e51db23aa79565875e7f9999ee"},
"earmark_parser": {:hex, :earmark_parser, "1.4.13", "0c98163e7d04a15feb62000e1a891489feb29f3d10cb57d4f845c405852bbef8", [:mix], [], "hexpm", "d602c26af3a0af43d2f2645613f65841657ad6efc9f0e361c3b6c06b578214ba"},
"elixir_uuid": {:hex, :elixir_uuid, "1.2.0", "ff26e938f95830b1db152cb6e594d711c10c02c6391236900ddd070a6b01271d", [:mix], [], "hexpm"},
"erlex": {:hex, :erlex, "0.1.6", "c01c889363168d3fdd23f4211647d8a34c0f9a21ec726762312e08e083f3d47e", [:mix], [], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "8e24fc8ff9a50b9f557ff020d6c91a03cded7e59ac3e0eec8a27e771430c7d27"},
"ex_doc": {:hex, :ex_doc, "0.24.2", "e4c26603830c1a2286dae45f4412a4d1980e1e89dc779fcd0181ed1d5a05c8d9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e134e1d9e821b8d9e4244687fb2ace58d479b67b282de5158333b0d57c6fb7da"},
"excoveralls": {:hex, :excoveralls, "0.12.1", "a553c59f6850d0aff3770e4729515762ba7c8e41eedde03208182a8dc9d0ce07", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "5c1f717066a299b1b732249e736c5da96bb4120d1e55dc2e6f442d251e18a812"},
"hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "e0100f8ef7d1124222c11ad362c857d3df7cb5f4204054f9f0f4a728666591fc"},
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "4bdd305eb64e18b0273864920695cb18d7a2021f31a11b9c5fbcd9a253f936e2"},
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
"makeup": {:hex, :makeup, "1.0.0", "671df94cf5a594b739ce03b0d0316aa64312cee2574b6a44becb83cd90fb05dc", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "a10c6eb62cca416019663129699769f0c2ccf39428b3bb3c0cb38c718a0c186d"},
"makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "d4b316c7222a85bbaa2fd7c6e90e37e953257ad196dc229505137c5e505e9eff"},
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.1", "c90796ecee0289dbb5ad16d3ad06f957b0cd1199769641c961cfe0b97db190e0", [:mix], [], "hexpm", "00e3ebdc821fb3a36957320d49e8f4bfa310d73ea31c90e5f925dc75e030da8f"},
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},
"poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm", "13104d7897e38ed7f044c4de953a6c28597d1c952075eb2e328bc6d6f2bfc496"},
Expand Down
2 changes: 1 addition & 1 deletion test/mongo/change_stream_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ defmodule Mongo.ChangeStreamTest do
assert {:ok, %Mongo.InsertOneResult{}} = Mongo.insert_one(top, "users", %{name: "Greta"})

assert_receive {:token, _}, 5_000
assert_receive {:token, token}, 5_000
assert_receive {:token, _token}, 5_000
assert_receive {:insert, %{"fullDocument" => %{"name" => "Greta"}}}, 5_000

assert [{:getMore, ["ResumableChangeStreamError"]}] == EventCatcher.failed_events(catcher) |> Enum.map(fn event -> {event.command_name, event.failure.error_labels} end)
Expand Down
4 changes: 2 additions & 2 deletions test/mongo/topology_description_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ defmodule Mongo.TopologyDescriptionTest do
opts = [
read_preference: ReadPreference.primary(%{mode: :primary})
]
assert {:ok, {master, _}} = TopologyDescription.select_servers(repl_set_with_master(), :read, opts)
assert {:ok, {_master, _}} = TopologyDescription.select_servers(repl_set_with_master(), :read, opts)

opts = [
read_preference: ReadPreference.primary(%{mode: :primary_preferred})
]
assert {:ok, {master, _}} = TopologyDescription.select_servers(repl_set_with_master(), :read, opts)
assert {:ok, {_master, _}} = TopologyDescription.select_servers(repl_set_with_master(), :read, opts)

opts = [
read_preference: ReadPreference.primary(%{mode: :primary_preferred})
Expand Down
13 changes: 10 additions & 3 deletions test/mongo/transaction_retries_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ defmodule Mongo.TransactionRetriesTest do
assert :ok == Session.end_session(top, session)

assert [:commitTransaction, :commitTransaction, :commitTransaction] = EventCatcher.failed_events(catcher) |> Enum.map(fn event -> event.command_name end)
assert [:commitTransaction, :configureFailPoint, :insert, :create] = EventCatcher.succeeded_events(catcher) |> Enum.map(fn event -> event.command_name end)
assert [:commitTransaction, :configureFailPoint, :insert, :create] = get_succeeded_events(catcher)

end

Expand Down Expand Up @@ -125,7 +125,7 @@ defmodule Mongo.TransactionRetriesTest do

Mongo.admin_command(top, [configureFailPoint: "failCommand", mode: "off"])

assert [:configureFailPoint, :abortTransaction, :configureFailPoint, :insert, :create] = EventCatcher.succeeded_events(catcher) |> Enum.map(fn event -> event.command_name end)
assert [:configureFailPoint, :abortTransaction, :configureFailPoint, :insert, :create] = get_succeeded_events(catcher)

end

Expand All @@ -150,8 +150,15 @@ defmodule Mongo.TransactionRetriesTest do

Mongo.admin_command(top, [configureFailPoint: "failCommand", mode: "off"])

assert [:configureFailPoint, :abortTransaction, :insert, :configureFailPoint, :create] = EventCatcher.succeeded_events(catcher) |> Enum.map(fn event -> event.command_name end)
assert [:configureFailPoint, :abortTransaction, :insert, :configureFailPoint, :create] = get_succeeded_events(catcher)

end

defp get_succeeded_events(catcher) do
catcher
|> EventCatcher.succeeded_events()
|> Enum.map(fn event -> event.command_name end)
|> Enum.reject(fn event -> event == :isMaster end)
end

end

0 comments on commit 8857943

Please sign in to comment.