rename environment variable
This commit is contained in:
		
							parent
							
								
									926ff822ec
								
							
						
					
					
						commit
						30548eae80
					
				@ -2,11 +2,11 @@ defmodule BasicSignupWhitelist do
 | 
				
			|||||||
  import FunCore.BasicSignupWhitelist
 | 
					  import FunCore.BasicSignupWhitelist
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @moduledoc """
 | 
					  @moduledoc """
 | 
				
			||||||
  Checks if an email address is allowed based on the SIGNUP_ALLOWED_EMAILS env variable.
 | 
					  Checks if an email address is allowed based on the SIGNUP_ALLOWLIST_EMAILS env variable.
 | 
				
			||||||
  """
 | 
					  """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @doc """
 | 
					  @doc """
 | 
				
			||||||
  Checks if an email address is allowed based on the SIGNUP_ALLOWED_EMAILS env variable.
 | 
					  Checks if an email address is allowed based on the SIGNUP_ALLOWLIST_EMAILS env variable.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Rules:
 | 
					  Rules:
 | 
				
			||||||
    - Returns true if ALLOWED_EMAILS == "*" (all emails allowed)
 | 
					    - Returns true if ALLOWED_EMAILS == "*" (all emails allowed)
 | 
				
			||||||
@ -18,16 +18,16 @@ defmodule BasicSignupWhitelist do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  ## Examples
 | 
					  ## Examples
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      iex> System.delete_env("SIGNUP_ALLOWED_EMAILS")
 | 
					      iex> System.delete_env("SIGNUP_ALLOWLIST_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> System.put_env("SIGNUP_ALLOWLIST_EMAILS","*")
 | 
				
			||||||
      iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
 | 
					      iex> BasicSignupWhitelist.mail_whitelisted("joe@example.com")
 | 
				
			||||||
      true
 | 
					      true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  """
 | 
					  """
 | 
				
			||||||
  def mail_whitelisted(email) do
 | 
					  def mail_whitelisted(email) do
 | 
				
			||||||
    env_value = System.get_env("SIGNUP_ALLOWED_EMAILS")
 | 
					    env_value = System.get_env("SIGNUP_ALLOWLIST_EMAILS")
 | 
				
			||||||
    mail_whitelisted_fun(env_value, email)
 | 
					    mail_whitelisted_fun(env_value, email)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -3,21 +3,21 @@ defmodule BasicSignupWhitelistTest do
 | 
				
			|||||||
  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_ALLOWLIST_EMAILS", whitelist)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  describe "setup in describe block" do
 | 
					  describe "setup in describe block" do
 | 
				
			||||||
    setup do
 | 
					    setup do
 | 
				
			||||||
      on_exit(fn ->
 | 
					      on_exit(fn ->
 | 
				
			||||||
        # resetting values did not work, so 'just' set it to the effect without this module configured.
 | 
					        # resetting values did not work, so 'just' set it to the effect without this module configured.
 | 
				
			||||||
        System.put_env("SIGNUP_ALLOWED_EMAILS", "*")
 | 
					        System.put_env("SIGNUP_ALLOWLIST_EMAILS", "*")
 | 
				
			||||||
      end)
 | 
					      end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      :ok
 | 
					      :ok
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    test "When not set, not whitelisted" do
 | 
					    test "When not set, not whitelisted" do
 | 
				
			||||||
      System.delete_env("SIGNUP_ALLOWED_EMAILS")
 | 
					      System.delete_env("SIGNUP_ALLOWLIST_EMAILS")
 | 
				
			||||||
      refute BasicSignupWhitelist.mail_whitelisted("joe@example.com")
 | 
					      refute BasicSignupWhitelist.mail_whitelisted("joe@example.com")
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user