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:
Rohan Relan 2023-12-27 07:27:22 -08:00 committed by GitHub
parent c7738255f0
commit 750dc17286
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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: [