-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #993 from hartwork/serve-security-txt
Serve file `/.well-known/security.txt` (RFC 9116)
- Loading branch information
Showing
4 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Contact: mailto:sebastian@pipping.org | ||
Expires: 9999-12-31T23:59:59.999Z | ||
Preferred-Languages: en, de |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (c) 2024 Sebastian Pipping <sebastian@pipping.org> | ||
# Licensed under GNU Affero GPL v3 or later | ||
|
||
import pkg_resources | ||
from django.urls import re_path | ||
from django.views.static import serve | ||
|
||
|
||
def security_txt_urlpatterns(name='security_txt'): | ||
return [ | ||
re_path('^(?:\\.well-known/)?(?P<path>security\\.txt)$', | ||
serve, | ||
kwargs={ | ||
'document_root': pkg_resources.resource_filename('wnpp_debian_net', | ||
'static/well-known'), | ||
}, | ||
name=name), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright (c) 2024 Sebastian Pipping <sebastian@pipping.org> | ||
# Licensed under GNU Affero GPL v3 or later | ||
|
||
from django.http import FileResponse | ||
from django.test import TestCase | ||
from django.urls import reverse_lazy | ||
from parameterized import parameterized | ||
|
||
|
||
class SecurityTxtTest(TestCase): | ||
|
||
@parameterized.expand([ | ||
( | ||
'default location', | ||
'/.well-known/security.txt', | ||
), | ||
( | ||
'legacy location', | ||
'/security.txt', | ||
), | ||
( | ||
'through reverse', | ||
reverse_lazy('security_txt', kwargs={'path': 'security.txt'}), | ||
), | ||
]) | ||
def test_file_served_properly(self, _label, url): | ||
self.assertTrue(url.endswith('/security.txt')) | ||
|
||
response = self.client.get(url) | ||
|
||
self.assertIsInstance(response, FileResponse) | ||
self.assertEqual(response.headers['Content-Type'], 'text/plain') |