summaryrefslogtreecommitdiff
path: root/test/matrix_app_service_web/auth_plug_test.exs
diff options
context:
space:
mode:
Diffstat (limited to 'test/matrix_app_service_web/auth_plug_test.exs')
-rw-r--r--test/matrix_app_service_web/auth_plug_test.exs24
1 files changed, 11 insertions, 13 deletions
diff --git a/test/matrix_app_service_web/auth_plug_test.exs b/test/matrix_app_service_web/auth_plug_test.exs
index 1293cec..8a2116b 100644
--- a/test/matrix_app_service_web/auth_plug_test.exs
+++ b/test/matrix_app_service_web/auth_plug_test.exs
@@ -5,19 +5,18 @@ defmodule MatrixAppServiceWeb.AuthPlugTest do
import ExUnit.CaptureLog
test "call with correct acces token returns conn unchanged" do
- Application.put_env(:matrix_app_service, :homeserver_token, "test_token")
-
- conn = conn(:get, "/users/2", %{"access_token" => "test_token"})
+ conn =
+ conn(:get, "/users/2", %{
+ "access_token" => "correct token"
+ })
- assert MatrixAppServiceWeb.AuthPlug.call(conn, nil) == conn
+ assert MatrixAppServiceWeb.AuthPlug.call(conn, "correct token") == conn
end
test "call with incorrect access token halts with error 403" do
- Application.put_env(:matrix_app_service, :homeserver_token, "test_token")
-
conn =
- conn(:get, "/users/2", %{"access_token" => "incorrect_token"})
- |> MatrixAppServiceWeb.AuthPlug.call(nil)
+ conn(:get, "/users/2", %{"access_token" => "incorrect token"})
+ |> MatrixAppServiceWeb.AuthPlug.call("correct token")
assert conn.status == 403
assert conn.private[:phoenix_template] == "403.json"
@@ -26,17 +25,16 @@ defmodule MatrixAppServiceWeb.AuthPlugTest do
end
test "call with incorrect access token gets logged" do
- Application.put_env(:matrix_app_service, :homeserver_token, "test_token")
- conn = conn(:get, "/users/2", %{"access_token" => "incorrect_token"})
+ conn = conn(:get, "/users/2", %{"access_token" => "incorrect token"})
- assert capture_log(fn -> MatrixAppServiceWeb.AuthPlug.call(conn, nil) end) =~
+ assert capture_log(fn -> MatrixAppServiceWeb.AuthPlug.call(conn, "correct token") end) =~
"Received invalid homeserver token"
end
test "call without access token halts with error 401" do
conn =
conn(:get, "/users/2")
- |> MatrixAppServiceWeb.AuthPlug.call(nil)
+ |> MatrixAppServiceWeb.AuthPlug.call("correct token")
assert conn.status == 401
assert conn.private[:phoenix_template] == "401.json"
@@ -47,7 +45,7 @@ defmodule MatrixAppServiceWeb.AuthPlugTest do
test "call without access token gets logged" do
conn = conn(:get, "user/3")
- assert capture_log(fn -> MatrixAppServiceWeb.AuthPlug.call(conn, nil) end) =~
+ assert capture_log(fn -> MatrixAppServiceWeb.AuthPlug.call(conn, "correct token") end) =~
"No homeserver token provided"
end
end