-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement: compile-time check to make sure that the configured `tok…
…en_resource` is an Ash.Resource (#749) * improvement(Tokens): improved compile-time validation of the token_resource option of the tokens DSL by checking that the passed value is an Ash.Resource. * improvement(Tokens): removed unnecessary stuff from the test file. * improvement(Tokens): fixed credo warning and changed some things after PR feedback
- Loading branch information
Showing
3 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
defmodule AshAuthentication.UserWithBadTokenTest do | ||
@moduledoc false | ||
|
||
use DataCase, async: true | ||
|
||
test "cannot compile with bad token_resource configured" do | ||
assert_raise Spark.Error.DslError, ~r/`BadToken` is not a valid token resource module name/, fn -> | ||
defmodule UserWithBadToken do | ||
@moduledoc false | ||
use Ash.Resource, | ||
data_layer: AshPostgres.DataLayer, | ||
extensions: [AshAuthentication], | ||
validate_domain_inclusion?: false, | ||
domain: Example | ||
|
||
attributes do | ||
uuid_primary_key :id, writable?: true | ||
attribute :email, :ci_string, allow_nil?: false, public?: true | ||
attribute :hashed_password, :string, allow_nil?: true, sensitive?: true, public?: false | ||
create_timestamp :created_at | ||
update_timestamp :updated_at | ||
end | ||
|
||
authentication do | ||
tokens do | ||
enabled? true | ||
token_resource BadToken | ||
signing_secret fn _, _ -> :dummy end | ||
end | ||
|
||
strategies do | ||
password do | ||
identity_field :email | ||
|
||
resettable do | ||
sender fn _user, _token, _opts -> :noop end | ||
end | ||
end | ||
end | ||
end | ||
|
||
actions do | ||
defaults [:create, :read, :update, :destroy] | ||
end | ||
|
||
identities do | ||
identity :email, [:email], eager_check_with: Example | ||
end | ||
|
||
postgres do | ||
table "user_with_bad_token_required" | ||
repo Example.Repo | ||
end | ||
end | ||
end | ||
end | ||
end |