fix: adds user friendly flas message
This commit is contained in:
parent
2b1f49d60a
commit
a25263b721
7 changed files with 163 additions and 12 deletions
|
|
@ -248,4 +248,48 @@ defmodule MvWeb.AuthControllerTest do
|
|||
|
||||
assert to =~ "/auth/user/password/sign_in_with_token"
|
||||
end
|
||||
|
||||
# OIDC/Rauthy error handling tests
|
||||
describe "handle_rauthy_failure/2" do
|
||||
test "Assent.ServerUnreachableError redirects to sign-in with error flash", %{
|
||||
conn: authenticated_conn
|
||||
} do
|
||||
conn = build_unauthenticated_conn(authenticated_conn)
|
||||
# Create a mock Assent.ServerUnreachableError struct
|
||||
error = %Assent.ServerUnreachableError{request_url: "https://auth.example.com/callback?token=secret123"}
|
||||
|
||||
conn = MvWeb.AuthController.failure(conn, {:rauthy, :callback}, error)
|
||||
|
||||
assert redirected_to(conn) == ~p"/sign-in"
|
||||
assert get_flash(conn, :error) == "The authentication server is currently unavailable. Please try again later."
|
||||
end
|
||||
|
||||
test "Assent.InvalidResponseError redirects to sign-in with error flash", %{
|
||||
conn: authenticated_conn
|
||||
} do
|
||||
conn = build_unauthenticated_conn(authenticated_conn)
|
||||
# Create a mock Assent.InvalidResponseError struct
|
||||
error = %Assent.InvalidResponseError{
|
||||
response: %{status_code: 400, body: "invalid_request"},
|
||||
request_url: "https://auth.example.com/callback"
|
||||
}
|
||||
|
||||
conn = MvWeb.AuthController.failure(conn, {:rauthy, :callback}, error)
|
||||
|
||||
assert redirected_to(conn) == ~p"/sign-in"
|
||||
assert get_flash(conn, :error) == "Authentication configuration error. Please contact the administrator."
|
||||
end
|
||||
|
||||
test "unknown reason triggers catch-all and redirects to sign-in with error flash", %{
|
||||
conn: authenticated_conn
|
||||
} do
|
||||
conn = build_unauthenticated_conn(authenticated_conn)
|
||||
unknown_reason = :oops
|
||||
|
||||
conn = MvWeb.AuthController.failure(conn, {:rauthy, :callback}, unknown_reason)
|
||||
|
||||
assert redirected_to(conn) == ~p"/sign-in"
|
||||
assert get_flash(conn, :error) == "Unable to authenticate with OIDC. Please try again."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue