""" Absolute URLs come from SITE_URL, not the request (v2.0.1) Behind a reverse proxy the app is reached over plain HTTP, so URLs built from the request said http:// on an https site. """ import pytest from starpunk import create_app from starpunk.notes import create_note @pytest.fixture def app(tmp_path): data = tmp_path / "data" return create_app( { "TESTING": True, "SITE_URL": "https://blog.example.com", "ADMIN_ME": "https://example.com", "SESSION_SECRET": "test-secret", "DATA_PATH": data, "NOTES_PATH": data / "notes", "DATABASE_PATH": data / "starpunk.db", } ) def test_pages_use_site_url_behind_http_proxy(app): with app.app_context(): note = create_note(content="Hello over the proxy", published=True, tags=["proxy"]) client = app.test_client() pages = ["/", f"/note/{note.slug}", "/tag/proxy"] for path in pages: # The test client makes plain http://localhost requests, like Caddy does response = client.get(path) assert response.status_code == 200, path html = response.data.decode() assert "http://localhost" not in html, path home = client.get("/").data.decode() assert 'href="https://blog.example.com/feed"' in home assert 'href="https://blog.example.com/opml.xml"' in home note_html = client.get(f"/note/{note.slug}").data.decode() assert f'href="https://blog.example.com/note/{note.slug}"' in note_html