Skip to content

Commit 465e3e5

Browse files
committed
fix!: don't encrypt attributes not in action accept list
fixes #133
1 parent 20cad13 commit 465e3e5

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

lib/ash_cloak/transformers/set_up_encryption.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ defmodule AshCloak.Transformers.SetupEncryption do
8888
defp rewrite_actions({:ok, dsl}, attr) do
8989
dsl
9090
|> Ash.Resource.Info.actions()
91-
|> Enum.filter(&(&1.type in [:create, :update, :destroy]))
91+
|> Enum.filter(&(&1.type in [:create, :update, :destroy] && attr.name in &1.accept))
9292
|> Enum.reduce_while({:ok, dsl}, fn action, {:ok, dsl} ->
9393
new_accept = action.accept -- [attr.name]
9494

test/ash_cloak_test.exs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,12 @@ defmodule AshCloakTest do
162162
assert decode(encrypted.encrypted_encrypted) == 14
163163
end
164164

165-
test "it encrypts even when the attribute is not in the accept list" do
166-
encrypted =
165+
test "it does not encrypt when the attribute is not in the accept list" do
166+
assert_raise Ash.Error.Invalid, ~r/attribute encrypted_encrypted_with_default is required/, fn ->
167167
AshCloak.Test.Resource
168168
|> Ash.Changeset.for_create(:change_without_accept)
169169
|> Ash.create!()
170-
171-
assert decode(encrypted.encrypted_encrypted) == 13
170+
end
172171
end
173172

174173
test "it encrypts with default value" do

0 commit comments

Comments
 (0)