add test for secret route validation
This commit is contained in:
parent
349795d012
commit
03e9a0b840
2 changed files with 15 additions and 3 deletions
|
|
@ -29,7 +29,6 @@ defmodule PinchflatWeb.Router do
|
|||
|
||||
scope "/secret/:secret", PinchflatWeb do
|
||||
pipe_through :secret
|
||||
# has to match before /sources/:id
|
||||
get "/opml/feed", Podcasts.PodcastController, :opml_feed
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -5,10 +5,23 @@ defmodule PinchflatWeb.PodcastControllerTest do
|
|||
import Pinchflat.SourcesFixtures
|
||||
|
||||
describe "opml_feed" do
|
||||
|
||||
test "unauthorized when no secret set", %{conn: conn} do
|
||||
Application.put_env(:pinchflat, :route_secret, "")
|
||||
conn = get(conn, ~p"/secret/the-secret/opml/feed" <> ".xml")
|
||||
assert conn.status == 401
|
||||
end
|
||||
|
||||
test "unauthorized when secret incorrect", %{conn: conn} do
|
||||
Application.put_env(:pinchflat, :route_secret, "test-secret")
|
||||
conn = get(conn, ~p"/secret/invalid-secret/opml/feed" <> ".xml")
|
||||
assert conn.status == 401
|
||||
end
|
||||
|
||||
test "renders the XML document", %{conn: conn} do
|
||||
source = source_fixture()
|
||||
|
||||
conn = get(conn, ~p"/sources/opml" <> ".xml")
|
||||
Application.put_env(:pinchflat, :route_secret, "test-secret")
|
||||
conn = get(conn, ~p"/secret/test-secret/opml/feed" <> ".xml")
|
||||
|
||||
assert conn.status == 200
|
||||
assert {"content-type", "application/opml+xml; charset=utf-8"} in conn.resp_headers
|
||||
|
|
|
|||
Loading…
Reference in a new issue