-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Live endpoints that require authentication are piped through the :pro…
…tected pipeline (#498) * Add :protected to protected live view routes * Add test for /microblog/preferences * Add additional authentication tests * Add test for editing password * Undo errorneous delete
- Loading branch information
1 parent
ed73402
commit 016c005
Showing
13 changed files
with
244 additions
and
35 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
16 changes: 16 additions & 0 deletions
16
test/teiserver_web/controllers/account/security_controller_test.exs
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule TeiserverWeb.Account.SecurityControllerTest do | ||
use TeiserverWeb.ConnCase | ||
|
||
alias Central.Helpers.GeneralTestLib | ||
|
||
test "redirected to edit password once logged in" do | ||
{:ok, kw} = GeneralTestLib.conn_setup([], [:no_login]) | ||
{:ok, conn} = Keyword.fetch(kw, :conn) | ||
{:ok, user} = Keyword.fetch(kw, :user) | ||
|
||
conn = get(conn, ~p"/teiserver/account/security/edit_password") | ||
assert redirected_to(conn) == ~p"/login" | ||
conn = GeneralTestLib.login(conn, user.email) | ||
assert redirected_to(conn) == ~p"/teiserver/account/security/edit_password" | ||
end | ||
end |
27 changes: 27 additions & 0 deletions
27
test/teiserver_web/live/account/relationship/index_live_test.exs
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule TeiserverWeb.Account.RelationshipLive.IndexLiveTest do | ||
use TeiserverWeb.ConnCase, async: true | ||
|
||
alias Central.Helpers.GeneralTestLib | ||
|
||
test "account relationship endpoints requires authentication" do | ||
{:ok, kw} = | ||
GeneralTestLib.conn_setup([], [:no_login]) | ||
|> Teiserver.TeiserverTestLib.conn_setup() | ||
|
||
{:ok, conn} = Keyword.fetch(kw, :conn) | ||
|
||
conn = get(conn, ~p"/account/relationship") | ||
assert redirected_to(conn) == ~p"/login" | ||
end | ||
|
||
test "can access account relationship when authenticated" do | ||
{:ok, kw} = | ||
GeneralTestLib.conn_setup() | ||
|> Teiserver.TeiserverTestLib.conn_setup() | ||
|
||
{:ok, conn} = Keyword.fetch(kw, :conn) | ||
|
||
conn = get(conn, ~p"/account/relationship") | ||
html_response(conn, 200) | ||
end | ||
end |
27 changes: 27 additions & 0 deletions
27
test/teiserver_web/live/account/settings/index_live_test.exs
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule TeiserverWeb.Account.SettingsLive.IndexLiveTest do | ||
use TeiserverWeb.ConnCase, async: true | ||
|
||
alias Central.Helpers.GeneralTestLib | ||
|
||
test "account settings endpoints requires authentication" do | ||
{:ok, kw} = | ||
GeneralTestLib.conn_setup([], [:no_login]) | ||
|> Teiserver.TeiserverTestLib.conn_setup() | ||
|
||
{:ok, conn} = Keyword.fetch(kw, :conn) | ||
|
||
conn = get(conn, ~p"/account/settings") | ||
assert redirected_to(conn) == ~p"/login" | ||
end | ||
|
||
test "can access account settings when authenticated" do | ||
{:ok, kw} = | ||
GeneralTestLib.conn_setup() | ||
|> Teiserver.TeiserverTestLib.conn_setup() | ||
|
||
{:ok, conn} = Keyword.fetch(kw, :conn) | ||
|
||
conn = get(conn, ~p"/account/settings") | ||
html_response(conn, 200) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule TeiserverWeb.Admin.ChatLive.IndexLiveTest do | ||
use TeiserverWeb.ConnCase, async: true | ||
|
||
alias Central.Helpers.GeneralTestLib | ||
|
||
test "cannot access admin chat without authenticating" do | ||
{:ok, kw} = GeneralTestLib.conn_setup([], [:no_login]) | ||
{:ok, conn} = Keyword.fetch(kw, :conn) | ||
conn = get(conn, ~p"/admin/chat") | ||
assert redirected_to(conn) == ~p"/login" | ||
end | ||
|
||
test "cannot access admin chat when unauthorized" do | ||
{:ok, kw} = GeneralTestLib.conn_setup() | ||
{:ok, conn} = Keyword.fetch(kw, :conn) | ||
conn = get(conn, ~p"/admin/chat") | ||
assert redirected_to(conn) == ~p"/" | ||
end | ||
|
||
test "can access admin chat when authorized" do | ||
{:ok, kw} = GeneralTestLib.conn_setup(["Reviewer"]) | ||
{:ok, conn} = Keyword.fetch(kw, :conn) | ||
conn = get(conn, ~p"/admin/chat") | ||
html_response(conn, 200) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule TeiserverWeb.Battle.MatchLive.ChatLiveTest do | ||
use TeiserverWeb.ConnCase | ||
import Phoenix.LiveViewTest | ||
|
||
alias Central.Helpers.GeneralTestLib | ||
|
||
setup do | ||
{:ok, kw} = GeneralTestLib.conn_setup(["Overwatch"], [:no_login]) | ||
|
||
{:ok, user} = Keyword.fetch(kw, :user) | ||
|
||
battle = | ||
Teiserver.TeiserverTestLib.make_battle(%{ | ||
name: "LiveBattle", | ||
founder_id: user.id, | ||
founder_name: user.name | ||
}) | ||
|
||
{:ok, kw ++ [battle: battle]} | ||
end | ||
|
||
test "battle chat endpoints requires authentication", %{conn: conn, battle: battle} do | ||
conn = get(conn, ~p"/battle/chat/#{battle.id}") | ||
assert redirected_to(conn) == ~p"/login" | ||
end | ||
|
||
test "can access battle chat when authenticated", %{conn: conn, battle: battle, user: user} do | ||
conn = GeneralTestLib.login(conn, user.email) | ||
conn = get(conn, ~p"/battle/chat/#{battle.id}") | ||
html_response(conn, 200) | ||
end | ||
|
||
test "unauthorized user cannot access battle chat", %{conn: conn, battle: battle} do | ||
user = GeneralTestLib.make_user() | ||
conn = GeneralTestLib.login(conn, user.email) | ||
conn = get(conn, ~p"/battle/chat/#{battle.id}") | ||
assert redirected_to(conn) == ~p"/" | ||
end | ||
end |
27 changes: 27 additions & 0 deletions
27
test/teiserver_web/live/battles/match/ratings_live_test.exs
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule TeiserverWeb.Battle.MatchLive.RatingsLiveTest do | ||
use TeiserverWeb.ConnCase, async: true | ||
|
||
alias Central.Helpers.GeneralTestLib | ||
|
||
test "battle ratings endpoints requires authentication" do | ||
{:ok, kw} = | ||
GeneralTestLib.conn_setup([], [:no_login]) | ||
|> Teiserver.TeiserverTestLib.conn_setup() | ||
|
||
{:ok, conn} = Keyword.fetch(kw, :conn) | ||
|
||
conn = get(conn, ~p"/battle/ratings") | ||
assert redirected_to(conn) == ~p"/login" | ||
end | ||
|
||
test "can access battle ratings when authenticated" do | ||
{:ok, kw} = | ||
GeneralTestLib.conn_setup() | ||
|> Teiserver.TeiserverTestLib.conn_setup() | ||
|
||
{:ok, conn} = Keyword.fetch(kw, :conn) | ||
|
||
conn = get(conn, ~p"/battle/ratings") | ||
html_response(conn, 200) | ||
end | ||
end |
19 changes: 19 additions & 0 deletions
19
test/teiserver_web/live/communication/chat/index_live_test.exs
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule TeiserverWeb.Communication.ChatLive.IndexLiveTest do | ||
use TeiserverWeb.ConnCase, async: true | ||
|
||
alias Central.Helpers.GeneralTestLib | ||
|
||
test "cannot access chat without authenticating" do | ||
{:ok, kw} = GeneralTestLib.conn_setup([], [:no_login]) | ||
{:ok, conn} = Keyword.fetch(kw, :conn) | ||
conn = get(conn, ~p"/chat") | ||
assert redirected_to(conn) == ~p"/login" | ||
end | ||
|
||
test "can access chat once authenticated" do | ||
{:ok, kw} = GeneralTestLib.conn_setup() | ||
{:ok, conn} = Keyword.fetch(kw, :conn) | ||
conn = get(conn, ~p"/chat") | ||
html_response(conn, 200) | ||
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
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