Compare commits
No commits in common. "464b96b656243630e19aeed023e10145fe97051a" and "135448398d8786d04fa08ecd86c6a637bff946a5" have entirely different histories.
464b96b656
...
135448398d
@ -1,18 +1,10 @@
|
|||||||
defmodule BasicSignupWhitelist do
|
defmodule BasicSignupWhitelist do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Checks if an email address is allowed based on the SIGNUP_ALLOWED_EMAILS env variable.
|
Documentation for `BasicSignupWhitelist`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Checks if an email address is allowed based on the SIGNUP_ALLOWED_EMAILS env variable.
|
false
|
||||||
|
|
||||||
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
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@ -1,57 +0,0 @@
|
|||||||
defmodule FunCore.BasicSignupWhitelistTest do
|
|
||||||
use ExUnit.Case
|
|
||||||
|
|
||||||
defp normalize(email) do
|
|
||||||
email |> String.trim() |> String.downcase()
|
|
||||||
end
|
|
||||||
|
|
||||||
defp addresses_as_list(addresses_str) do
|
|
||||||
addresses_str
|
|
||||||
|> String.split(",")
|
|
||||||
|> Enum.map(&normalize/1)
|
|
||||||
end
|
|
||||||
|
|
||||||
def mail_whitelisted_fun(signups_allowed, email_received) do
|
|
||||||
case signups_allowed do
|
|
||||||
nil -> false
|
|
||||||
"*" -> true
|
|
||||||
list_str -> normalize(email_received) in addresses_as_list(list_str)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test "addresses_as_list" do
|
|
||||||
assert addresses_as_list("joe@example.com, jane@example.com") == [
|
|
||||||
"joe@example.com",
|
|
||||||
"jane@example.com"
|
|
||||||
]
|
|
||||||
end
|
|
||||||
|
|
||||||
test "jane in list" do
|
|
||||||
lst = addresses_as_list("joe@example.com, jane@example.com")
|
|
||||||
assert "jane@example.com" in lst
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Not whitelisted when allowed list is" do
|
|
||||||
test "not set" do
|
|
||||||
refute(mail_whitelisted_fun(nil, "joe@example.com"))
|
|
||||||
end
|
|
||||||
|
|
||||||
test "empty" do
|
|
||||||
refute(mail_whitelisted_fun("j", "joe@example.com"))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Whitelisted when" do
|
|
||||||
test "*" do
|
|
||||||
assert(mail_whitelisted_fun("*", "jane@example.com"))
|
|
||||||
end
|
|
||||||
|
|
||||||
test "Multiple set and one match" do
|
|
||||||
assert(mail_whitelisted_fun("joe@example.com, jane@example.com", "jane@example.com"))
|
|
||||||
end
|
|
||||||
|
|
||||||
test "Matches with different casings" do
|
|
||||||
assert(mail_whitelisted_fun("joe@Example.com, jane@example.com", "Joe@example.com"))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Loading…
x
Reference in New Issue
Block a user