[Bugfix] Improve OPML route security (#535)

* WIP - moved plugs; set up a new token-protected route plug

* Added a route_token column to settings model

* Hooked up token_protected_route plug to database

* Hooked up new OPML route to UI; turned RSS and OPML feed buttons into links

* Docs, tests

* Added a note about the phoenix bug
This commit is contained in:
Kieran
2024-12-30 17:40:23 -08:00
committed by GitHub
parent 246ca3b299
commit f51b219860
12 changed files with 295 additions and 158 deletions
@@ -4,17 +4,34 @@ defmodule PinchflatWeb.PodcastControllerTest do
import Pinchflat.MediaFixtures
import Pinchflat.SourcesFixtures
alias Pinchflat.Settings
describe "opml_feed" do
test "renders the XML document", %{conn: conn} do
source = source_fixture()
route_token = Settings.get!(:route_token)
conn = get(conn, ~p"/sources/opml" <> ".xml")
conn = get(conn, ~p"/sources/opml.xml?#{[route_token: route_token]}")
assert conn.status == 200
assert {"content-type", "application/opml+xml; charset=utf-8"} in conn.resp_headers
assert {"content-disposition", "inline"} in conn.resp_headers
assert conn.resp_body =~ ~s"http://www.example.com/sources/#{source.uuid}/feed.xml"
assert conn.resp_body =~ "text=\"Cool and good internal name!\""
assert conn.resp_body =~ "text=\"#{source.custom_name}\""
end
test "returns 401 if the route token is incorrect", %{conn: conn} do
conn = get(conn, ~p"/sources/opml.xml?route_token=incorrect")
assert conn.status == 401
assert conn.resp_body == "Unauthorized"
end
test "returns 401 if the route token is missing", %{conn: conn} do
conn = get(conn, ~p"/sources/opml.xml")
assert conn.status == 401
assert conn.resp_body == "Unauthorized"
end
end