Resolve "Logout leading to HTTP error 405" - closing #95

This commit is contained in:
Oliver Falk
2024-01-16 14:00:38 +00:00
parent 4eedb3e628
commit 8b0fc31f6a
4 changed files with 21 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ Test our views in ivatar.ivataraccount.views and ivatar.views
import os
import json
import django
from django.urls import reverse
from django.test import TestCase
from django.test import Client
from django.contrib.auth.models import User
@@ -76,3 +77,15 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods
j["unconfirmed_openids"], 0, "unconfirmed openids count incorrect"
)
self.assertEqual(j["avatars"], 0, "avatars count incorrect")
def test_logout(self):
"""
Test if logout works correctly
"""
self.login()
response = self.client.get(reverse("logout"), follow=True)
self.assertEqual(
response.status_code, 405, "logout with get should lead to http error 405"
)
response = self.client.post(reverse("logout"), follow=True)
self.assertEqual(response.status_code, 200, "logout with post should logout")

View File

@@ -18,7 +18,7 @@
<li><a href="{% url 'export' %}"><i class="fa fa-fw fa-file-archive-o" aria-hidden="true"></i> {% trans 'Download your libravatar data' %}</a></li>
<li><a href="{% url 'password_change' %}"><i class="fa fa-fw fa-key" aria-hidden="true"></i> {% trans 'Change password' %}</a></li>
<li><a href="{% url 'password_reset' %}"><i class="fa fa-fw fa-unlock-alt" aria-hidden="true"></i> {% trans 'Reset password' %}</a></li>
<li><a href="{% url 'logout' %}"><i class="fa fa-fw fa-sign-out" aria-hidden="true"></i> {% trans 'Logout' %}</a></li>
<li>{% include '_account_logout.html' %}</li>
{% else %}
<li><a href="{% url 'login' %}"><i class="fa fa-fw fa-sign-in" aria-hidden="true"></i> {% trans 'Local' %}</a></li>
<li><a href="{% url 'new_account' %}"><i class="fa fa-fw fa-user-plus" aria-hidden="true"></i> {% trans 'Create account' %}</a></li>

View File

@@ -0,0 +1,6 @@
{% load i18n %}
<form id="logoutform" method="POST" action="{% url 'logout' %}">
{% csrf_token %}
<input type="hidden"/>
</form>
<a href="#" onClick="document.getElementById('logoutform').submit()"><i class="fa fa-fw fa-sign-out" aria-hidden="true"></i> {% trans 'Logout' %}</a>

View File

@@ -28,7 +28,7 @@
<li><a href="{% url 'upload_export' %}"><i class="fa fa-fw fa-file-archive-o" aria-hidden="true"></i> {% trans 'Import libravatar XML export' %}</a></li>
<li><a href="{% url 'password_change' %}"><i class="fa fa-fw fa-key" aria-hidden="true"></i> {% trans 'Change password' %}</a></li>
<li><a href="{% url 'password_reset' %}"><i class="fa fa-fw fa-unlock-alt" aria-hidden="true"></i> {% trans 'Reset password' %}</a></li>
<li><a href="{% url 'logout' %}"><i class="fa fa-fw fa-sign-out" aria-hidden="true"></i> {% trans 'Logout' %}</a></li>
<li>{% include '_account_logout.html' %}</li>
{% if user.is_staff %}
<li>
<a href="{% url 'admin:index' %}" target="_new"><i class="fa fa-fw fa-user-secret" aria-hidden="true"></i> {% trans 'Admin' %}</a>