Replace NoActor runtime Mix.env with compile-time config

Use Application.compile_env for release-safety.
Config only set in test.exs (defaults to false).
This commit is contained in:
Moritz 2026-01-22 22:37:04 +01:00
parent 811a276d92
commit 05c71132e4
3 changed files with 26 additions and 42 deletions

View file

@ -11,7 +11,7 @@ defmodule Mv.Authorization.Checks.NoActorTest do
describe "match?/3" do
test "returns true when actor is nil in test environment" do
# In test environment, NoActor should allow operations
# In test environment (config :allow_no_actor_bypass = true), NoActor allows operations
result = NoActor.match?(nil, %{}, [])
assert result == true
end
@ -22,46 +22,31 @@ defmodule Mv.Authorization.Checks.NoActorTest do
assert result == false
end
test "has compile-time guard preventing production use" do
# The @allow_no_actor_bypass module attribute is set at compile time
# In test: true, in prod/dev: false
# This test verifies the guard exists (compile-time check)
# Runtime check is verified by the fact that match? checks Mix.env()
test "uses compile-time config (not runtime Mix.env)" do
# The @allow_no_actor_bypass is set via Application.compile_env at compile time
# In test.exs: config :mv, :allow_no_actor_bypass, true
# In prod/dev: not set (defaults to false)
# This ensures the check is release-safe (no runtime Mix.env dependency)
result = NoActor.match?(nil, %{}, [])
# In test environment, should allow
if Mix.env() == :test do
assert result == true
else
# In other environments, should deny
assert result == false
end
end
# In test environment (as compiled), should allow
assert result == true
test "has runtime guard preventing production use" do
# The match? function checks Mix.env() at runtime
# This provides defense in depth against config drift
result = NoActor.match?(nil, %{}, [])
# Should match compile-time guard
if Mix.env() == :test do
assert result == true
else
assert result == false
end
# Note: We cannot test "production mode" here because the flag is compile-time.
# Production safety is guaranteed by:
# 1. Config only set in test.exs
# 2. Default is false (fail-closed)
# 3. No runtime environment checks
end
end
describe "describe/1" do
test "returns description based on environment" do
test "returns description based on compile-time config" do
description = NoActor.describe([])
assert is_binary(description)
if Mix.env() == :test do
assert description =~ "test environment"
else
assert description =~ "production/dev"
end
# In test environment (compiled with :allow_no_actor_bypass = true)
assert description =~ "test environment"
end
end
end