Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic fail2ban support #847

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions bookmarks/tests/test_login_view.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
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
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/")
Expand Down
5 changes: 5 additions & 0 deletions siteroot/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def get_context_data(self, **kwargs):
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),
Expand Down