From 8a42a35b8c418d286a3e25f40bf6722df0bd036b Mon Sep 17 00:00:00 2001 From: Andrew Hebert Date: Mon, 13 May 2024 12:37:34 -0400 Subject: [PATCH] more cleanup --- config/releases.exs | 4 ++-- lib/recognizer_web.ex | 2 +- .../accounts/user_oauth_controller_test.exs | 4 ++-- .../user_recovery_code_controller_test.exs | 2 +- .../user_reset_password_controller_test.exs | 12 ++++++------ .../accounts/user_settings_controller_test.exs | 18 +++++++++--------- .../user_two_factor_controller_test.exs | 6 +++--- test/support/conn_case.ex | 1 + 8 files changed, 25 insertions(+), 24 deletions(-) diff --git a/config/releases.exs b/config/releases.exs index 52a79a7..33aaaef 100644 --- a/config/releases.exs +++ b/config/releases.exs @@ -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"], diff --git a/lib/recognizer_web.ex b/lib/recognizer_web.ex index 9fcaa0d..678e80e 100644 --- a/lib/recognizer_web.ex +++ b/lib/recognizer_web.ex @@ -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()) diff --git a/test/recognizer_web/controllers/accounts/user_oauth_controller_test.exs b/test/recognizer_web/controllers/accounts/user_oauth_controller_test.exs index a27a2d0..8a8ad29 100644 --- a/test/recognizer_web/controllers/accounts/user_oauth_controller_test.exs +++ b/test/recognizer_web/controllers/accounts/user_oauth_controller_test.exs @@ -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 @@ -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 diff --git a/test/recognizer_web/controllers/accounts/user_recovery_code_controller_test.exs b/test/recognizer_web/controllers/accounts/user_recovery_code_controller_test.exs index 799f747..da17491 100644 --- a/test/recognizer_web/controllers/accounts/user_recovery_code_controller_test.exs +++ b/test/recognizer_web/controllers/accounts/user_recovery_code_controller_test.exs @@ -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 diff --git a/test/recognizer_web/controllers/accounts/user_reset_password_controller_test.exs b/test/recognizer_web/controllers/accounts/user_reset_password_controller_test.exs index 5c16501..d344e60 100644 --- a/test/recognizer_web/controllers/accounts/user_reset_password_controller_test.exs +++ b/test/recognizer_web/controllers/accounts/user_reset_password_controller_test.exs @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/test/recognizer_web/controllers/accounts/user_settings_controller_test.exs b/test/recognizer_web/controllers/accounts/user_settings_controller_test.exs index 98e4fb8..2d00366 100644 --- a/test/recognizer_web/controllers/accounts/user_settings_controller_test.exs +++ b/test/recognizer_web/controllers/accounts/user_settings_controller_test.exs @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/test/recognizer_web/controllers/accounts/user_two_factor_controller_test.exs b/test/recognizer_web/controllers/accounts/user_two_factor_controller_test.exs index 4ada773..f91ad7d 100644 --- a/test/recognizer_web/controllers/accounts/user_two_factor_controller_test.exs +++ b/test/recognizer_web/controllers/accounts/user_two_factor_controller_test.exs @@ -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 @@ -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 @@ -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 diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index d385eca..094f148 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -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