diff options
author | Pierre de Lacroix <pierre@pdelacroix.com> | 2020-12-01 13:08:29 +0000 |
---|---|---|
committer | Pierre de Lacroix <pierre@pdelacroix.com> | 2020-12-01 13:08:29 +0000 |
commit | 407d202f4c5a094c5a2e991ab81064e060673905 (patch) | |
tree | 2656048c6d4eb0ea134779a85bb6bd41a1466207 /test/matrix_app_service_web/auth_plug_test.exs | |
parent | Update README.md (diff) | |
parent | add endpoint handled by the library (diff) |
Merge branch 'choose_endpoint' into 'master'
add endpoint handled by the libraryCloses #23
See merge request kazarma/matrix_app_service.ex!12
Diffstat (limited to 'test/matrix_app_service_web/auth_plug_test.exs')
-rw-r--r-- | test/matrix_app_service_web/auth_plug_test.exs | 24 |
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 |