-
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.
Showing
4 changed files
with
118 additions
and
15 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
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 |
---|---|---|
|
@@ -65,6 +65,40 @@ defmodule ConciergeSite.Web.AuthControllerTest do | |
} = Guardian.Plug.current_resource(conn) | ||
end | ||
|
||
test "can use mbta_uuid user", | ||
%{conn: conn, rider: %User{id: id, email: email, phone_number: phone_number}} do | ||
auth = auth_for(nil, email, phone_number, ["user"], id) | ||
|
||
conn = | ||
conn | ||
|> assign(:ueberauth_auth, auth) | ||
|> get("/auth/keycloak/callback") | ||
|
||
assert %User{id: ^id, email: ^email, phone_number: ^phone_number} = | ||
Guardian.Plug.current_resource(conn) | ||
end | ||
|
||
@tag capture_log: true | ||
test "redirects if we somehow get 2 users", | ||
%{conn: conn, rider: %User{id: id, email: email, phone_number: phone_number}} do | ||
user2 = | ||
Repo.insert!(%User{ | ||
email: "[email protected]", | ||
phone_number: "5551234567", | ||
role: "user" | ||
}) | ||
|
||
auth = auth_for(id, email, phone_number, ["user"], user2.id) | ||
|
||
conn = | ||
conn | ||
|> assign(:ueberauth_auth, auth) | ||
|> get("/auth/keycloak/callback") | ||
|
||
assert is_nil(Guardian.Plug.current_resource(conn)) | ||
assert redirected_to(conn) == "/" | ||
end | ||
|
||
test "doesn't allow admin access if the token says they are now just a user", | ||
%{conn: conn} do | ||
was_an_admin = | ||
|
@@ -110,7 +144,7 @@ defmodule ConciergeSite.Web.AuthControllerTest do | |
end | ||
|
||
@spec auth_for(User.id(), String.t(), String.t() | nil) :: Auth.t() | ||
defp auth_for(id, email, phone_number, roles \\ ["user"]) do | ||
defp auth_for(id, email, phone_number, roles \\ ["user"], mbta_uuid \\ nil) do | ||
%Auth{ | ||
uid: email, | ||
provider: :keycloak, | ||
|
@@ -147,6 +181,7 @@ defmodule ConciergeSite.Web.AuthControllerTest do | |
"name" => "John Rider", | ||
"phone_number" => phone_number, | ||
"preferred_username" => email, | ||
"mbta_uuid" => mbta_uuid, | ||
"resource_access" => %{ | ||
"t-alerts" => %{ | ||
"roles" => roles | ||
|