Add basic fail2ban support (#847)

This commit is contained in:
Sascha Ißbrücker 2024-09-23 16:20:55 +02:00 committed by GitHub
parent 67f237c1de
commit f5708594a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 2 deletions

View file

@ -1,7 +1,7 @@
from django.test import TestCase, override_settings
from django.urls import path, include
from bookmarks.tests.helpers import HtmlTestMixin
from bookmarks.tests.helpers import BookmarkFactoryMixin, HtmlTestMixin
from siteroot.urls import urlpatterns as base_patterns
# Register OIDC urls for this test, otherwise login template can not render when OIDC is enabled
@ -9,7 +9,19 @@ urlpatterns = base_patterns + [path("oidc/", include("mozilla_django_oidc.urls")
@override_settings(ROOT_URLCONF=__name__)
class LoginViewTestCase(TestCase, HtmlTestMixin):
class LoginViewTestCase(TestCase, BookmarkFactoryMixin, HtmlTestMixin):
def test_failed_login_should_return_401(self):
response = self.client.post("/login/", {"username": "test", "password": "test"})
self.assertEqual(response.status_code, 401)
def test_successful_login_should_redirect(self):
user = self.setup_user(name="test")
user.set_password("test")
user.save()
response = self.client.post("/login/", {"username": "test", "password": "test"})
self.assertEqual(response.status_code, 302)
def test_should_not_show_oidc_login_by_default(self):
response = self.client.get("/login/")

View file

@ -34,6 +34,11 @@ class LinkdingLoginView(auth_views.LoginView):
context["enable_oidc"] = settings.LD_ENABLE_OIDC
return context
def form_invalid(self, form):
response = super().form_invalid(form)
response.status_code = 401
return response
urlpatterns = [
path("admin/", linkding_admin_site.urls),