Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-s76 committed May 13, 2024
1 parent 32f23fb commit 8a42a35
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions config/releases.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ config :recognizer,
hal_token: recognizer_config["HAL_TOKEN"]

config :recognizer, RecognizerWeb.Endpoint,
url: [host: System.get_env("DOMAIN")],
secret_key_base: recognizer_config["SECRET_KEY_BASE"]
url: [host: System.get_env("DOMAIN")],
secret_key_base: recognizer_config["SECRET_KEY_BASE"]

config :recognizer, Recognizer.Repo,
username: recognizer_config["DB_USER"],
Expand Down
2 changes: 1 addition & 1 deletion lib/recognizer_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule RecognizerWeb do

# Import convenience functions from controllers
import Phoenix.Controller,
only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1]
only: [view_module: 1, view_template: 1]

# Include shared imports and aliases for views
unquote(view_helpers())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ defmodule RecognizerWeb.Accounts.UserOauthControllerTest do
|> assign(:ueberauth_auth, auth)
|> UserOAuthController.callback(%{})

assert get_flash(conn, :error) ==
assert Flash.get(conn.assigns.flash, :error) ==
"An error occurred. This may indicate you have previously created an account using the email and password combination."
end

Expand All @@ -89,7 +89,7 @@ defmodule RecognizerWeb.Accounts.UserOauthControllerTest do
|> assign(:ueberauth_auth, auth)
|> UserOAuthController.callback(%{})

assert get_flash(conn, :error) == "An error occurred. Please contact support."
assert Flash.get(conn.assigns.flash, :error) == "An error occurred. Please contact support."
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule RecognizerWeb.Accounts.UserRecoveryCodeControllerTest do
})

assert redirected_to(conn) == "/recovery-code"
assert get_flash(conn, :error) =~ "invalid"
assert Flash.get(conn.assigns.flash, :error) =~ "invalid"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule RecognizerWeb.Accounts.UserResetPasswordControllerTest do
})

assert redirected_to(conn) == Routes.user_session_path(conn, :create)
assert get_flash(conn, :info) =~ "If your email is in our system"
assert Flash.get(conn.assigns.flash, :info) =~ "If your email is in our system"
end

test "rate limit new reset password tokens", %{conn: conn, user: user} do
Expand Down Expand Up @@ -57,7 +57,7 @@ defmodule RecognizerWeb.Accounts.UserResetPasswordControllerTest do
})

assert redirected_to(conn) == Routes.user_session_path(conn, :create)
assert get_flash(conn, :info) =~ "If your email is in our system"
assert Flash.get(conn.assigns.flash, :info) =~ "If your email is in our system"
end

test "does not send reset password token if email is invalid", %{conn: conn} do
Expand All @@ -67,7 +67,7 @@ defmodule RecognizerWeb.Accounts.UserResetPasswordControllerTest do
})

assert redirected_to(conn) == Routes.user_session_path(conn, :create)
assert get_flash(conn, :info) =~ "If your email is in our system"
assert Flash.get(conn.assigns.flash, :info) =~ "If your email is in our system"
end
end

Expand All @@ -89,7 +89,7 @@ defmodule RecognizerWeb.Accounts.UserResetPasswordControllerTest do
test "does not render reset password with invalid token", %{conn: conn} do
conn = get(conn, Routes.user_reset_password_path(conn, :edit, "oops"))
assert redirected_to(conn) == Routes.user_reset_password_path(conn, :create)
assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired"
assert Flash.get(conn.assigns.flash, :error) =~ "Reset password link is invalid or it has expired"
end
end

Expand All @@ -114,7 +114,7 @@ defmodule RecognizerWeb.Accounts.UserResetPasswordControllerTest do

assert redirected_to(conn) == Routes.user_session_path(conn, :new)
refute get_session(conn, :user_token)
assert get_flash(conn, :info) =~ "Password reset successfully"
assert Flash.get(conn.assigns.flash, :info) =~ "Password reset successfully"
assert Accounts.get_user_by_email_and_password(user.email, "n@wvAli4dPassw!d")
end

Expand All @@ -136,7 +136,7 @@ defmodule RecognizerWeb.Accounts.UserResetPasswordControllerTest do
test "does not reset password with invalid token", %{conn: conn} do
conn = put(conn, Routes.user_reset_password_path(conn, :update, "oops"))
assert redirected_to(conn) == Routes.user_reset_password_path(conn, :create)
assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired"
assert Flash.get(conn.assigns.flash, :error) =~ "Reset password link is invalid or it has expired"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule RecognizerWeb.Accounts.UserSettingsControllerTest do
})

assert redirected_to(new_password_conn) == Routes.user_settings_path(conn, :edit)
assert get_flash(new_password_conn, :info) =~ "Password updated successfully"
assert Flash.get(new_password_conn.assigns.flash, :info) =~ "Password updated successfully"
assert Accounts.get_user_by_email_and_password(user.email, "NeWVa3!pa33wor@d")
end

Expand Down Expand Up @@ -84,7 +84,7 @@ defmodule RecognizerWeb.Accounts.UserSettingsControllerTest do
})

assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
assert get_flash(conn, :info) =~ "Your settings have been updated"
assert Flash.get(conn.assigns.flash, :info) =~ "Your settings have been updated"
refute Accounts.get_user_by_email(user.email)
end

Expand Down Expand Up @@ -135,7 +135,7 @@ defmodule RecognizerWeb.Accounts.UserSettingsControllerTest do
})

assert redirected_to(conn) =~ "/settings"
assert get_flash(conn, :error) =~ "Phone number required"
assert Flash.get(conn.assigns.flash, :error) =~ "Phone number required"
end

test "update two-factor allows app setup without a phone number", %{conn: conn, user: user} do
Expand All @@ -149,7 +149,7 @@ defmodule RecognizerWeb.Accounts.UserSettingsControllerTest do
})

assert redirected_to(conn) =~ "/settings/two-factor/review"
refute get_flash(conn, :error)
refute Flash.get(conn.assigns.flash, :error)
end
end

Expand All @@ -163,7 +163,7 @@ defmodule RecognizerWeb.Accounts.UserSettingsControllerTest do
test "review 2fa without cached codes is redirected with flash error", %{conn: conn} do
conn = get(conn, Routes.user_settings_path(conn, :review))
_response = html_response(conn, 302)
assert get_flash(conn, :error) == "Two factor setup expired or not yet initiated"
assert Flash.get(conn.assigns.flash, :error) == "Two factor setup expired or not yet initiated"
end
end

Expand All @@ -176,7 +176,7 @@ defmodule RecognizerWeb.Accounts.UserSettingsControllerTest do
assert html_response(result2, 200) =~ "Configure App"
result3 = get(conn, Routes.user_settings_path(conn, :two_factor_init))
assert html_response(result3, 200) =~ "Configure App"
refute get_flash(result3, :error)
refute Flash.get(result3.assigns.flash, :error)
end

test "/two-factor loads for text, limits retries", %{conn: conn, user: user} do
Expand All @@ -187,7 +187,7 @@ defmodule RecognizerWeb.Accounts.UserSettingsControllerTest do
assert html_response(result2, 200) =~ "Enter the provided 6-digit code"
result3 = get(conn, Routes.user_settings_path(conn, :two_factor_init))
assert html_response(result3, 200) =~ "Enter the provided 6-digit code"
assert get_flash(result3, :error) =~ "Too many requests"
assert Flash.get(result3.assigns.flash, :error) =~ "Too many requests"
end
end

Expand All @@ -201,7 +201,7 @@ defmodule RecognizerWeb.Accounts.UserSettingsControllerTest do
conn = post(conn, Routes.user_settings_path(conn, :two_factor_confirm), params)

assert redirected_to(conn) =~ "/settings"
assert get_flash(conn, :info) =~ "Two factor code verified"
assert Flash.get(conn.assigns.flash, :info) =~ "Two factor code verified"

%{recovery_codes: recovery_codes} =
User
Expand All @@ -220,7 +220,7 @@ defmodule RecognizerWeb.Accounts.UserSettingsControllerTest do
params = %{"two_factor_code" => token}
conn = post(conn, Routes.user_settings_path(conn, :two_factor_confirm), params)
assert redirected_to(conn) =~ "/two-factor"
assert get_flash(conn, :error) =~ "Two factor code is invalid"
assert Flash.get(conn.assigns.flash, :error) =~ "Two factor code is invalid"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule RecognizerWeb.Accounts.UserTwoFactorControllerTest do
})

assert redirected_to(conn) == "/two-factor"
assert get_flash(conn, :error) =~ "Invalid"
assert Flash.get(conn.assigns.flash, :error) =~ "Invalid"
end
end

Expand All @@ -57,7 +57,7 @@ defmodule RecognizerWeb.Accounts.UserTwoFactorControllerTest do
conn = post(conn, Routes.user_two_factor_path(conn, :resend))

assert redirected_to(conn) == "/two-factor"
assert get_flash(conn, :info) =~ "resent"
assert Flash.get(conn.assigns.flash, :info) =~ "resent"
end

test "rate limited", %{conn: conn} do
Expand All @@ -76,7 +76,7 @@ defmodule RecognizerWeb.Accounts.UserTwoFactorControllerTest do
conn = post(conn, Routes.user_two_factor_path(conn, :resend))

assert redirected_to(conn) == "/two-factor"
assert get_flash(conn, :info) =~ "resent"
assert Flash.get(conn.assigns.flash, :info) =~ "resent"
end
end
end
1 change: 1 addition & 0 deletions test/support/conn_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ defmodule RecognizerWeb.ConnCase do
import RecognizerWeb.ConnCase

alias RecognizerWeb.Router.Helpers, as: Routes
alias Phoenix.Flash

# The default endpoint for testing
@endpoint RecognizerWeb.Endpoint
Expand Down

0 comments on commit 8a42a35

Please sign in to comment.