mirror of
https://github.com/ash-project/ash.git
synced 2024-09-19 13:03:02 +12:00
test: Adds a test to ensure authorization occurs when the actor is set and authorization? is by_default (#813)
Co-authored-by: Rohan Relan <roresemail@gmail.com>
This commit is contained in:
parent
c7738255f0
commit
750dc17286
1 changed files with 25 additions and 0 deletions
|
@ -17,6 +17,14 @@ defmodule Ash.Test.Changeset.AuthorizerTest do
|
|||
|
||||
actions do
|
||||
defaults [:create, :read, :update, :destroy]
|
||||
|
||||
create :title_is_authorization do
|
||||
accept []
|
||||
|
||||
change fn changeset, context ->
|
||||
Ash.Changeset.change_attribute(changeset, :title, context.authorize?)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
attributes do
|
||||
|
@ -66,6 +74,23 @@ defmodule Ash.Test.Changeset.AuthorizerTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "authorize :by_default authorizes if actor is set" do
|
||||
Application.put_env(:ash, Api,
|
||||
authorization: [
|
||||
authorize: :by_default
|
||||
]
|
||||
)
|
||||
|
||||
start_supervised({Ash.Test.Authorizer, strict_check: :authorized})
|
||||
|
||||
post =
|
||||
Post
|
||||
|> Ash.Changeset.for_create(:title_is_authorization, %{}, actor: :an_actor)
|
||||
|> Api.create!()
|
||||
|
||||
assert post.title == "true"
|
||||
end
|
||||
|
||||
test "require_actor? requires an actor for all requests" do
|
||||
Application.put_env(:ash, Api,
|
||||
authorization: [
|
||||
|
|
Loading…
Reference in a new issue