Merge pull request 'Prepare Coulobre Core 1.5.2' (#280) from release/core-1.5.2 into main
Reviewed-on: #280
This commit is contained in:
commit
e29bf65427
4 files changed
+52
-5
No files matched your search
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "coulobre-panel"
|
name = "coulobre-panel"
|
||||||
version = "1.5.1"
|
version = "1.5.2"
|
||||||
description = "A web hosting control panel for hosting providers and resellers."
|
description = "A web hosting control panel for hosting providers and resellers."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
|
|||||||
@@ -61,8 +61,17 @@ class ServiceCredentialView(PermissionRequiredMixin, FormView):
|
|||||||
raise Http404
|
raise Http404
|
||||||
if getattr(request, "impersonation", None) is not None:
|
if getattr(request, "impersonation", None) is not None:
|
||||||
return self.handle_no_permission()
|
return self.handle_no_permission()
|
||||||
response = super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
response["Referrer-Policy"] = "no-referrer"
|
|
||||||
|
def render_to_response(self, context, **response_kwargs):
|
||||||
|
response = super().render_to_response(context, **response_kwargs)
|
||||||
|
# HTTPS form submissions need a referrer when Origin is absent.
|
||||||
|
# Never send referrers from pages displaying credentials.
|
||||||
|
response["Referrer-Policy"] = (
|
||||||
|
"no-referrer"
|
||||||
|
if context.get("fields") or context.get("rotation_problem")
|
||||||
|
else "same-origin"
|
||||||
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def has_permission(self):
|
def has_permission(self):
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from unittest.mock import patch
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.test import SimpleTestCase, TestCase, override_settings
|
from django.test import Client, SimpleTestCase, TestCase, override_settings
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
@@ -71,6 +71,42 @@ class CredentialRotationTests(TestCase):
|
|||||||
url, {"password": password, "ticket": ticket}, secure=True
|
url, {"password": password, "ticket": ticket}, secure=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@override_settings(
|
||||||
|
LOCAL_MAILBOX_PROVISIONING=True,
|
||||||
|
MAILBOX_PASSWORD_CHANGES=True,
|
||||||
|
)
|
||||||
|
def test_https_mailbox_rotation_accepts_the_same_origin_form(self):
|
||||||
|
MailboxProvisioning.objects.create(
|
||||||
|
mailbox=self.mailbox, finished_at=timezone.now()
|
||||||
|
)
|
||||||
|
client = Client(enforce_csrf_checks=True)
|
||||||
|
client.force_login(self.owner)
|
||||||
|
url = self.url("mailbox", self.mailbox)
|
||||||
|
reply = {"user": self.mailbox.spec.address, "password": REPLACEMENT}
|
||||||
|
with patch(
|
||||||
|
"coulobre.hosting.service_credentials.apply_on_local_node",
|
||||||
|
side_effect=[{"generation": None}, reply],
|
||||||
|
) as node:
|
||||||
|
page = client.get(url, secure=True)
|
||||||
|
self.assertEqual(page.headers["Referrer-Policy"], "same-origin")
|
||||||
|
self.assertNotContains(page, REPLACEMENT)
|
||||||
|
data = {
|
||||||
|
"csrfmiddlewaretoken": str(page.context["csrf_token"]),
|
||||||
|
"password": PASSWORD,
|
||||||
|
"ticket": page.context["form"]["ticket"].value(),
|
||||||
|
}
|
||||||
|
self.assertEqual(
|
||||||
|
client.post(url, data, secure=True).status_code, 403
|
||||||
|
)
|
||||||
|
self.assertEqual(node.call_count, 1)
|
||||||
|
result = client.post(
|
||||||
|
url, data, secure=True, HTTP_REFERER=f"https://testserver{url}"
|
||||||
|
)
|
||||||
|
self.assertContains(result, REPLACEMENT)
|
||||||
|
self.assertEqual(result.headers["Referrer-Policy"], "no-referrer")
|
||||||
|
self.assertIn("no-store", result.headers["Cache-Control"])
|
||||||
|
self.assertEqual(node.call_args.args[1], MAIL_PASSWORD_SOCKET)
|
||||||
|
|
||||||
def test_scope_confirmation_and_database_result(self):
|
def test_scope_confirmation_and_database_result(self):
|
||||||
database = self.database
|
database = self.database
|
||||||
url = self.url("database", database)
|
url = self.url("database", database)
|
||||||
|
|||||||
@@ -138,7 +138,9 @@ class ServiceCredentialAccessTests(TestCase):
|
|||||||
self.mailbox.spec,
|
self.mailbox.spec,
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
self.assertNotContains(self.client.get(url, secure=True), expected)
|
page = self.client.get(url, secure=True)
|
||||||
|
self.assertNotContains(page, expected)
|
||||||
|
self.assertEqual(page.headers["Referrer-Policy"], "same-origin")
|
||||||
with patch(
|
with patch(
|
||||||
"coulobre.hosting.credential_views.fetch_service_credentials",
|
"coulobre.hosting.credential_views.fetch_service_credentials",
|
||||||
return_value=reply,
|
return_value=reply,
|
||||||
|
|||||||
Reference in new issue
Block a user