mirror of
https://github.com/sissbruecker/linkding
synced 2024-11-21 19:03:02 +00:00
Add basic fail2ban support (#847)
This commit is contained in:
parent
67f237c1de
commit
f5708594a7
2 changed files with 19 additions and 2 deletions
|
@ -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/")
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue