-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
107 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
defmodule DocumentViewerWeb.AuthControllerTest do | ||
use DocumentViewerWeb.ConnCase | ||
# This is not async because we change the logger level in here which could lead to | ||
# flaky tests elsewhere. | ||
use DocumentViewerWeb.ConnCase, async: false | ||
use Plug.Test | ||
import ExUnit.CaptureLog | ||
|
||
@mock_auth %Ueberauth.Auth{ | ||
uid: "[email protected]", | ||
credentials: %Ueberauth.Auth.Credentials{ | ||
expires_at: System.system_time(:second) + 1_000, | ||
other: %{roles: ["test-group"]} | ||
} | ||
} | ||
|
||
describe "GET /auth/:provider" do | ||
test "redirects to the callback", %{conn: conn} do | ||
conn = get(conn, ~p"/auth/keycloak") | ||
|
@@ -22,9 +16,7 @@ defmodule DocumentViewerWeb.AuthControllerTest do | |
@tag capture_log: true | ||
test "redirects to the index page for an ueberauth auth", %{conn: conn} do | ||
conn = conn |> get(~p"/auth/keycloak") | ||
|
||
assert "/auth/keycloak/callback?state=" <> _state = path = redirected_to(conn) | ||
|
||
conn = conn |> get(path) | ||
|
||
assert %{ | ||
|
@@ -41,15 +33,17 @@ defmodule DocumentViewerWeb.AuthControllerTest do | |
end | ||
|
||
test "logs a successful login", %{conn: conn} do | ||
Logger.configure(level: :info) | ||
|
||
log = | ||
capture_log(fn -> | ||
conn = conn |> get(~p"/auth/keycloak") | ||
path = conn |> redirected_to() | ||
assert "/auth/keycloak/callback?state=" <> _state = path = redirected_to(conn) | ||
get(conn, path) | ||
end) | ||
|
||
assert log =~ "username=\"[email protected]\"" | ||
assert log =~ "action=:login" | ||
assert log =~ "User action: action=:login, username=\"fake_uid\"" | ||
Logger.configure(level: :warning) | ||
end | ||
|
||
@tag capture_log: true | ||
|
@@ -68,15 +62,10 @@ defmodule DocumentViewerWeb.AuthControllerTest do | |
test "logs ueberauth failures", %{conn: conn} do | ||
log = | ||
capture_log(fn -> | ||
conn | ||
|> Plug.Test.init_test_session(%{username: "[email protected]"}) | ||
|> assign(:ueberauth_failure, %Ueberauth.Failure{ | ||
errors: [%Ueberauth.Failure.Error{message: "failed"}] | ||
}) | ||
|> get(~p"/auth/keycloak/callback") | ||
conn |> get(~p"/auth/keycloak/callback") | ||
end) | ||
|
||
assert log =~ "Ueberauth error: failed" | ||
assert log =~ "Ueberauth error: Cross-Site Request Forgery attack" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters