add test for secret route validation

This commit is contained in:
robs 2024-12-30 20:14:50 +01:00
parent 349795d012
commit 03e9a0b840
2 changed files with 15 additions and 3 deletions

View file

@ -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

View file

@ -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