From 750dc17286c8befc60119e0f4bf4ac1c7bcc37d1 Mon Sep 17 00:00:00 2001 From: Rohan Relan Date: Wed, 27 Dec 2023 07:27:22 -0800 Subject: [PATCH] test: Adds a test to ensure authorization occurs when the actor is set and authorization? is by_default (#813) Co-authored-by: Rohan Relan --- test/authorizer/authorizer_test.exs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/authorizer/authorizer_test.exs b/test/authorizer/authorizer_test.exs index 4424b454..35c3346d 100644 --- a/test/authorizer/authorizer_test.exs +++ b/test/authorizer/authorizer_test.exs @@ -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: [