Files
Evection/apps/core/tests.py
T
ksmithandClaude Sonnet 5 3f6474ce94 Add hardening and deployment: admin dashboard, security headers, install docs
Adds an admin-only dashboard (apps/core) surfacing feeds that are failing to
fetch, with error messages, subscriber counts, and a one-click retry that
resets backoff and re-queues the fetch.

Hardens config/settings/prod.py with the remaining standard Django security
settings (HSTS preload, nosniff, referrer-policy, frame-options, SameSite
cookies) plus a Content-Security-Policy header via django-csp, as a second
layer behind nh3's HTML sanitization of feed content.

Adds docs/install.md (pip + gunicorn + systemd + nginx, SQLite and Postgres
both covered) plus the systemd units and nginx snippet it references,
LICENSE (AGPL-3.0-or-later, matching pyproject.toml), and an updated README.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-30 20:10:31 -06:00

61 lines
2.1 KiB
Python

from unittest.mock import patch
import pytest
from django.urls import reverse
from apps.feeds.models import Feed, Subscription
@pytest.mark.django_db
def test_dashboard_requires_staff(client, django_user_model):
django_user_model.objects.create_user("regular", password="pw-regular-123")
client.login(username="regular", password="pw-regular-123")
response = client.get(reverse("core:dashboard"))
assert response.status_code == 302
@pytest.mark.django_db
def test_dashboard_lists_erroring_feeds(client, django_user_model):
admin = django_user_model.objects.create_user("admin", password="pw-admin-123", is_staff=True)
client.login(username="admin", password="pw-admin-123")
ok_feed = Feed.objects.create(feed_url="https://ok.example.com/feed", title="OK Feed")
broken_feed = Feed.objects.create(
feed_url="https://broken.example.com/feed",
title="Broken Feed",
last_fetch_status=Feed.STATUS_ERROR,
fetch_error_count=3,
last_error_message="Connection timed out",
)
Subscription.objects.create(user=admin, feed=ok_feed)
Subscription.objects.create(user=admin, feed=broken_feed)
response = client.get(reverse("core:dashboard"))
assert response.status_code == 200
assert b"Broken Feed" in response.content
assert b"Connection timed out" in response.content
assert b"OK Feed" not in response.content
@pytest.mark.django_db
def test_retry_feed_resets_backoff_and_requeues(client, django_user_model):
django_user_model.objects.create_user("admin", password="pw-admin-123", is_staff=True)
client.login(username="admin", password="pw-admin-123")
feed = Feed.objects.create(
feed_url="https://broken.example.com/feed",
fetch_error_count=5,
last_fetch_status=Feed.STATUS_ERROR,
)
with (
patch("apps.core.views.reset_feed_backoff.delay") as mock_reset,
patch("apps.core.views.fetch_feed.delay") as mock_fetch,
):
response = client.post(reverse("core:retry_feed", args=[feed.id]))
assert response.status_code == 302
mock_reset.assert_called_once_with(feed.id)
mock_fetch.assert_called_once_with(feed.id)