Skip to content

Commit 03bd369

Browse files
✨(web-presentation) add a security.txt URL
1 parent ee3b2aa commit 03bd369

5 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/web/config/settings/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@
187187
# Default primary key field type
188188
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
189189

190+
SECURITY_CONTACT_EMAIL = "ops.csplab@beta.gouv.fr"
191+
190192
# Maximum CV size in cv upload flow
191193
CV_MAX_SIZE_MB = 5
192194

src/web/config/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
from presentation.candidate import urls as candidate_urls
88
from presentation.ingestion import urls as ingestion_urls
99
from presentation.pages import urls as pages_urls
10+
from presentation.pages.views import security_txt
1011
from presentation.users import urls as users_urls
1112

1213
urlpatterns: list[URLPattern | URLResolver] = [
14+
path(".well-known/security.txt", security_txt),
1315
path("", include(pages_urls)),
1416
path("api/", include(api_urls)),
1517
path("admin/", admin.site.urls),

src/web/presentation/pages/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
LegalNoticesView,
99
PrivacyView,
1010
TermsView,
11+
security_txt,
1112
)
1213

1314
app_name = "pages"

src/web/presentation/pages/views.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from django.conf import settings
2+
from django.http import HttpResponse
13
from django.views.generic import TemplateView
24

35

@@ -19,3 +21,8 @@ class PrivacyView(TemplateView):
1921

2022
class LegalNoticesView(TemplateView):
2123
template_name = "pages/legal_notices.html"
24+
25+
26+
def security_txt(request):
27+
content = f"Contact: mailto:{settings.SECURITY_CONTACT_EMAIL}\nPreferred-Languages: fr, en\n"
28+
return HttpResponse(content, content_type="text/plain; charset=utf-8")

src/web/tests/candidate/presentation/views/test_static_pages_view.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55
from pytest_django.asserts import assertTemplateUsed
66

77

8+
class TestSecurityTxtView:
9+
def test_returns_ok(self, client, db):
10+
response = client.get("/.well-known/security.txt")
11+
assert response.status_code == HTTPStatus.OK
12+
13+
def test_content_type(self, client, db):
14+
response = client.get("/.well-known/security.txt")
15+
assert "text/plain" in response["Content-Type"]
16+
17+
def test_content(self, client, db):
18+
response = client.get("/.well-known/security.txt")
19+
content = response.content.decode()
20+
assert "Contact: mailto:ops.csplab@beta.gouv.fr" in content
21+
assert "Preferred-Languages: fr, en" in content
22+
23+
824
@pytest.mark.parametrize(
925
("url_name", "template_name"),
1026
[

0 commit comments

Comments
 (0)