Skip to content

Commit

Permalink
add authh header
Browse files Browse the repository at this point in the history
  • Loading branch information
im-blx committed Sep 11, 2023
1 parent 6bd1756 commit 025ee56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/gringotts/gateways/monei.ex
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,10 @@ defmodule Gringotts.Gateways.Monei do
]
end

defp auth_headers(opts) do
[{:Authorization, opts[:config][:password]} | @default_headers]
end

# Makes the request to MONEI's network.
@spec commit(atom, String.t(), keyword, keyword) :: {:ok | :error, Response.t()}
defp commit(:post, endpoint, params, opts) do
Expand All @@ -442,7 +446,7 @@ defmodule Gringotts.Gateways.Monei do
url
|> HTTPoison.post(
{:form, params ++ validated_params ++ auth_params(opts)},
@default_headers
auth_headers(opts)
)
|> respond
end
Expand Down
8 changes: 4 additions & 4 deletions test/gateways/monei_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ defmodule Gringotts.Gateways.MoneiTest do
test "that all auth info is picked.", %{bypass: bypass, auth: auth} do
Bypass.expect_once(bypass, "POST", "/v1/payments", fn conn ->
p_conn = parse(conn)
params = p_conn.body_params
assert params["authentication.entityId"] == "some_secret_entity_id"
assert params["authentication.password"] == "some_secret_password"
assert params["authentication.userId"] == "some_secret_user_id"
headers = p_conn.req_headers
auth_header = Enum.find(headers, &match?({"authorization", _}, &1))
refute is_nil(auth_header)
assert {"authorization", "some_secret_password"} == auth_header
Conn.resp(conn, 200, @auth_success)
end)

Expand Down

0 comments on commit 025ee56

Please sign in to comment.