fix: tests and flash layout
This commit is contained in:
parent
a25263b721
commit
002d723d0e
6 changed files with 85 additions and 15 deletions
|
|
@ -6,7 +6,10 @@ defmodule MvWeb.AuthControllerTest do
|
|||
# Helper to create an unauthenticated conn (preserves sandbox metadata)
|
||||
defp build_unauthenticated_conn(authenticated_conn) do
|
||||
# Create new conn but preserve sandbox metadata for database access
|
||||
new_conn = build_conn()
|
||||
new_conn =
|
||||
build_conn()
|
||||
|> init_test_session(%{})
|
||||
|> fetch_flash()
|
||||
|
||||
# Copy sandbox metadata from authenticated conn
|
||||
if authenticated_conn.private[:ecto_sandbox] do
|
||||
|
|
@ -255,29 +258,41 @@ defmodule MvWeb.AuthControllerTest do
|
|||
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"}
|
||||
# Create a mock Assent.ServerUnreachableError struct with required fields
|
||||
error = %Assent.ServerUnreachableError{
|
||||
http_adapter: Assent.HTTPAdapter.Finch,
|
||||
request_url: "https://auth.example.com/callback?token=secret123",
|
||||
reason: %Mint.TransportError{reason: :econnrefused}
|
||||
}
|
||||
|
||||
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."
|
||||
|
||||
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
|
||||
# Create a mock Assent.InvalidResponseError struct with required field
|
||||
# InvalidResponseError only has :response field (HTTPResponse struct)
|
||||
error = %Assent.InvalidResponseError{
|
||||
response: %{status_code: 400, body: "invalid_request"},
|
||||
request_url: "https://auth.example.com/callback"
|
||||
response: %Assent.HTTPAdapter.HTTPResponse{
|
||||
status: 400,
|
||||
headers: [],
|
||||
body: "invalid_request"
|
||||
}
|
||||
}
|
||||
|
||||
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."
|
||||
|
||||
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", %{
|
||||
|
|
@ -289,7 +304,9 @@ defmodule MvWeb.AuthControllerTest do
|
|||
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."
|
||||
|
||||
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