Skip to content

Commit

Permalink
Merge pull request #537 from danschultzer/fix-users-context-bug
Browse files Browse the repository at this point in the history
Ensure custom users context calls its own `get_by` method
  • Loading branch information
danschultzer committed Jun 22, 2020
2 parents 5db3b52 + e1d3480 commit 99e7f2e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

* [`PowEmailConfirmation.Ecto.Schema`] `PowEmailConfirmation.Ecto.Schema.changeset/3` no longer sets the email to the unconfirmed email when the same email change is set twice
* [`Pow.Extension.Phoenix.Messages`] Fixed fallback message dializer warning
* [`Pow.Ecto.Context`] Fixed bug where the macro didn't add `:users_context` to the Pow config in the module resulting in `Pow.Ecto.Context.get_by/2` being called instead of `get_by/1` in the custom context

## v1.0.20 (2020-04-22)

Expand Down
2 changes: 1 addition & 1 deletion lib/pow/ecto/context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ defmodule Pow.Ecto.Context do
quote do
@behaviour Context

@pow_config unquote(config)
@pow_config Keyword.put_new(unquote(config), :users_context, __MODULE__)

def authenticate(params), do: pow_authenticate(params)
def create(params), do: pow_create(params)
Expand Down
3 changes: 3 additions & 0 deletions test/pow/ecto/context_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ defmodule Pow.Ecto.ContextTest do
@username_config [repo: Repo, user: UsernameUser]

defmodule CustomUsers do
use Context, repo: Repo, user: User

def get_by([email: :test]), do: %User{email: :ok, password_hash: Password.pbkdf2_hash("secret1234")}
end

Expand Down Expand Up @@ -104,6 +106,7 @@ defmodule Pow.Ecto.ContextTest do
params = Map.put(@valid_params, "email", :test)

assert %User{email: :ok} = Context.authenticate(params, @config ++ [users_context: CustomUsers])
assert %User{email: :ok} = CustomUsers.authenticate(params)
end

test "prevents timing attack" do
Expand Down

0 comments on commit 99e7f2e

Please sign in to comment.