Compare commits
No commits in common. "c848ca17ad05f781bd7f0fda47f697cd8e558978" and "5a7f6515477f59885b5418d36ae1fa562014c288" have entirely different histories.
c848ca17ad
...
5a7f651547
@ -18,12 +18,8 @@ defmodule BasicSignupWhitelist do
|
|||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
iex> System.delete_env("SIGNUP_ALLOWED_EMAILS")
|
|
||||||
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
||||||
false
|
false
|
||||||
iex> System.put_env("SIGNUP_ALLOWED_EMAILS","*")
|
|
||||||
iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
|
||||||
true
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def mail_whitelisted(email) do
|
def mail_whitelisted(email) do
|
||||||
|
|||||||
@ -1,29 +1,33 @@
|
|||||||
defmodule BasicSignupWhitelistTest do
|
defmodule BasicSignupWhitelistTest do
|
||||||
use ExUnit.Case, async: false
|
use ExUnit.Case
|
||||||
doctest BasicSignupWhitelist
|
doctest BasicSignupWhitelist
|
||||||
|
|
||||||
defp allow_signups_for(whitelist) do
|
defp allow_signups_for(whitelist) do
|
||||||
System.put_env("SIGNUP_ALLOWED_EMAILS", whitelist)
|
System.put_env("SIGNUP_ALLOWED_EMAILS", whitelist)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "setup in describe block" do
|
setup do
|
||||||
setup do
|
# Save original env var
|
||||||
on_exit(fn ->
|
original_env = System.get_env("SIGNUP_ALLOWED_EMAILS")
|
||||||
# resetting values did not work, so 'just' set it to the effect without this module configured.
|
|
||||||
System.put_env("SIGNUP_ALLOWED_EMAILS", "*")
|
|
||||||
end)
|
|
||||||
|
|
||||||
:ok
|
on_exit(fn ->
|
||||||
end
|
# Restore original env var after each test
|
||||||
|
case original_env do
|
||||||
|
nil -> System.delete_env("SIGNUP_ALLOWED_EMAILS")
|
||||||
|
value -> System.put_env("SIGNUP_ALLOWED_EMAILS", value)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
test "When not set, not whitelisted" do
|
:ok
|
||||||
System.delete_env("SIGNUP_ALLOWED_EMAILS")
|
end
|
||||||
refute BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
|
||||||
end
|
|
||||||
|
|
||||||
test "When set to star, whitelisted" do
|
test "When not set, not whitelisted" do
|
||||||
allow_signups_for("*")
|
System.delete_env("SIGNUP_ALLOWED_EMAILS")
|
||||||
assert BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
refute BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "When set to star, whitelisted" do
|
||||||
|
allow_signups_for("*")
|
||||||
|
assert BasicSignupWhitelist.mail_whitelisted("joe@example.com")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user