And after doctest. it stayed at "*" after the last test anyway, letting the doctest fail. doctests are not recommended for side effectful tests anyway https://hexdocs.pm/ex_unit/main/ExUnit.DocTest.html
34 lines
1023 B
Elixir
34 lines
1023 B
Elixir
defmodule BasicSignupWhitelist do
|
|
import FunCore.BasicSignupWhitelist
|
|
|
|
@moduledoc """
|
|
Checks if an email address is allowed based on the SIGNUP_ALLOWED_EMAILS env variable.
|
|
"""
|
|
|
|
@doc """
|
|
Checks if an email address is allowed based on the SIGNUP_ALLOWED_EMAILS env variable.
|
|
|
|
Rules:
|
|
- Returns true if ALLOWED_EMAILS == "*" (all emails allowed)
|
|
- Returns true if email matches any entry in the comma-separated list
|
|
- Returns false if:
|
|
* Environment variable doesn't exist
|
|
* Environment variable is empty string
|
|
* Email not found in whitelist
|
|
|
|
## Examples
|
|
|
|
iex> System.delete_env("SIGNUP_ALLOWED_EMAILS")
|
|
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
|
false
|
|
iex> System.put_env("SIGNUP_ALLOWED_EMAILS","*")
|
|
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
|
true
|
|
|
|
"""
|
|
def mail_whitelisted(email) do
|
|
env_value = System.get_env("SIGNUP_ALLOWED_EMAILS")
|
|
mail_whitelisted_fun(env_value, email)
|
|
end
|
|
end
|