Private
Public Access
Fix logout 405 — Django's LogoutView only accepts POST
The sidebar's "Log out" was a plain <a href> GET link. Django 5's LogoutView stopped accepting GET (CSRF hardening — a bare link or even an <img> tag could otherwise log someone out), so clicking it 405'd instead of logging out. Changed it to a POST form, matching every other state-changing action in the sidebar/app (unsubscribe, delete tag, etc.). Extended .sidebar-top-nav's styling to cover a <button> the same as an <a>, so the form-submit button looks identical to the other nav items. No existing test exercised logout at all — added one for the POST case and one confirming GET now correctly 405s, then verified end-to-end against the running dev server (login, POST /logout/, confirm the session is gone). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b08a78e747
commit
1a8ae95db0
3 files changed
+38
-3
No files matched your search
@@ -72,6 +72,30 @@ def test_setup_rejects_mismatched_passwords(client):
|
||||
assert not User.objects.exists()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_logout_via_post_logs_the_user_out(client):
|
||||
User.objects.create_user("keith", password="pw-keith-123")
|
||||
client.login(username="keith", password="pw-keith-123")
|
||||
|
||||
response = client.post(reverse("accounts:logout"))
|
||||
assert response.status_code == 302
|
||||
|
||||
stream_response = client.get(reverse("reader:stream"))
|
||||
assert stream_response.status_code == 302
|
||||
assert stream_response.url.startswith(reverse("accounts:login"))
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_logout_rejects_get(client):
|
||||
# Django's LogoutView only accepts POST (see templates/core/_sidebar.html,
|
||||
# which submits it as a form rather than a plain link).
|
||||
User.objects.create_user("keith", password="pw-keith-123")
|
||||
client.login(username="keith", password="pw-keith-123")
|
||||
|
||||
response = client.get(reverse("accounts:logout"))
|
||||
assert response.status_code == 405
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_non_admin_cannot_manage_users(client):
|
||||
User.objects.create_user("regular", password="pw-regular-123")
|
||||
|
||||
Reference in new issue
Block a user