Skip to content

Commit

Permalink
change use of whitelist to allowlist (hashrocket#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
supersimple committed Jun 24, 2020
1 parent ef78533 commit 4187b29
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export DEFAULT_TWITTER_HANDLE=
export ENABLE_BASIC_AUTH=
export GOOGLE_CLIENT_ID=
export GOOGLE_CLIENT_SECRET=
export GUEST_AUTHOR_WHITELIST=
export GUEST_AUTHOR_ALLOWLIST=
export HOSTED_DOMAIN=
export IMGUR_CLIENT_ID=
export ORGANIZATION_NAME=
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ $ PORT=4444 mix phx.server

Authentication is managed by Ueberauth and Google. See the [ueberauth_google
README][ueberauth_google] and [Google Oauth 2 docs][oauth_google] for
instructions. To allow users from a domain and/or comma-separated whitelist,
instructions. To allow users from a domain and/or comma-separated allowlist,
set those configurations in your environment:

```shell
Expand All @@ -78,7 +78,7 @@ set those configurations in your environment:
export GOOGLE_CLIENT_ID="your-key.apps.googleusercontent.com"
export GOOGLE_CLIENT_SECRET="yoursecret"
export HOSTED_DOMAIN="your-domain.com"
export GUEST_AUTHOR_WHITELIST="[email protected], [email protected]"
export GUEST_AUTHOR_ALLOWLIST="[email protected], [email protected]"
```

Once set, visit http:https://localhost:4000/admin and log in with an email address
Expand Down
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ config :tilex, :canonical_domain, System.get_env("CANONICAL_DOMAIN")
config :tilex, :default_twitter_handle, System.get_env("DEFAULT_TWITTER_HANDLE")
config :tilex, :cors_origin, System.get_env("CORS_ORIGIN")
config :tilex, :hosted_domain, System.get_env("HOSTED_DOMAIN")
config :tilex, :guest_author_whitelist, System.get_env("GUEST_AUTHOR_WHITELIST")
config :tilex, :guest_author_allowlist, System.get_env("GUEST_AUTHOR_ALLOWLIST")
config :tilex, :date_display_tz, System.get_env("DATE_DISPLAY_TZ")
config :tilex, :imgur_client_id, System.get_env("IMGUR_CLIENT_ID")

Expand Down
10 changes: 5 additions & 5 deletions lib/tilex_web/controllers/auth_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ defmodule TilexWeb.AuthController do
defp authorized(email) do
cond do
String.match?(email, ~r/@#{hosted_domain()}$/) -> {:ok, email}
email in guest_whitelist() -> {:ok, email}
email in guest_allowlist() -> {:ok, email}
true -> {:error, email}
end
end

defp hosted_domain, do: Application.get_env(:tilex, :hosted_domain)

defp guest_whitelist do
with emails when is_binary(emails) <- Application.get_env(:tilex, :guest_author_whitelist),
whitelist <- String.split(emails, [",", " "], trim: true) do
whitelist
defp guest_allowlist do
with emails when is_binary(emails) <- Application.get_env(:tilex, :guest_author_allowlist),
allowlist <- String.split(emails, [",", " "], trim: true) do
allowlist
else
_ -> []
end
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/auth_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ defmodule Tilex.AuthControllerTest do
assert get_flash(conn, :info) == "oauth2 profile is missing a valid name"
end

test "GET /auth/google/callback with whitelisted email", %{conn: conn} do
Application.put_env(:tilex, :guest_author_whitelist, "[email protected], [email protected]")
test "GET /auth/google/callback with allowlisted email", %{conn: conn} do
Application.put_env(:tilex, :guest_author_allowlist, "[email protected], [email protected]")

ueberauth_auth =
ueberauth_struct("[email protected]", "Archibald Douglas", "186823978541230597895")
Expand Down

0 comments on commit 4187b29

Please sign in to comment.