summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPierre de Lacroix <pierre@pdelacroix.com>2020-12-01 13:08:29 +0000
committerPierre de Lacroix <pierre@pdelacroix.com>2020-12-01 13:08:29 +0000
commit8a05e93e1a660cc0707430cbff811fafc7716340 (patch)
tree2656048c6d4eb0ea134779a85bb6bd41a1466207 /test
parentUpdate README.md (diff)
add endpoint handled by the library
Diffstat (limited to 'test')
-rw-r--r--test/matrix_app_service_web/auth_plug_test.exs24
-rw-r--r--test/support/conn_case.ex4
-rw-r--r--test/support/test_endpoint.ex25
-rw-r--r--test/support/test_router.ex10
4 files changed, 13 insertions, 50 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
diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex
index bc28d10..e1ce056 100644
--- a/test/support/conn_case.ex
+++ b/test/support/conn_case.ex
@@ -24,10 +24,10 @@ defmodule MatrixAppServiceWeb.ConnCase do
import Phoenix.ConnTest
import MatrixAppServiceWeb.ConnCase
- alias MatrixAppServiceWeb.TestRouter.Helpers, as: Routes
+ alias MatrixAppServiceWeb.Router.Helpers, as: Routes
# The default endpoint for testing
- @endpoint MatrixAppServiceWeb.TestEndpoint
+ @endpoint MatrixAppServiceWeb.Endpoint
end
end
diff --git a/test/support/test_endpoint.ex b/test/support/test_endpoint.ex
deleted file mode 100644
index 5112df8..0000000
--- a/test/support/test_endpoint.ex
+++ /dev/null
@@ -1,25 +0,0 @@
-defmodule MatrixAppServiceWeb.TestEndpoint do
- use Phoenix.Endpoint, otp_app: :matrix_app_service
-
- # The session will be stored in the cookie and signed,
- # this means its contents can be read but not tampered with.
- # Set :encryption_salt if you would also like to encrypt it.
- @session_options [
- store: :cookie,
- key: "_matrix_app_service_key",
- signing_salt: "zE7AHynD"
- ]
-
- plug Plug.RequestId
- # plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
-
- plug Plug.Parsers,
- parsers: [:urlencoded, :multipart, :json],
- pass: ["*/*"],
- json_decoder: Phoenix.json_library()
-
- plug Plug.MethodOverride
- plug Plug.Head
- plug Plug.Session, @session_options
- plug MatrixAppServiceWeb.TestRouter
-end
diff --git a/test/support/test_router.ex b/test/support/test_router.ex
deleted file mode 100644
index 3bbad03..0000000
--- a/test/support/test_router.ex
+++ /dev/null
@@ -1,10 +0,0 @@
-defmodule MatrixAppServiceWeb.TestRouter do
- require MatrixAppServiceWeb.Router
-
- use Phoenix.Router
-
- import Plug.Conn
- import Phoenix.Controller
-
- MatrixAppServiceWeb.Router.routes()
-end