Skip to content

Commit

Permalink
Merge pull request #59 from jkfran/security-txt
Browse files Browse the repository at this point in the history
Added support for security.txt files
  • Loading branch information
jkfran authored Apr 26, 2022
2 parents 90a5ff7 + 0ac93ba commit 34b5868
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 1.0.4 (2022-04-26)

Added support for security.txt files

# 1.0.3 (2022-03-29)

Fix dependencies for Flask 1.1.x: jinja2

# 1.0.2 (2022-03-21)

Pass through error messages from flask.abort to 404.html and 500.html templates
Expand Down
7 changes: 7 additions & 0 deletions canonicalwebteam/flask_base/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def favicon():

robots_path = os.path.join(self.root_path, "..", "robots.txt")
humans_path = os.path.join(self.root_path, "..", "humans.txt")
security_path = os.path.join(self.root_path, "..", "security.txt")

if os.path.isfile(robots_path):

Expand All @@ -289,3 +290,9 @@ def robots():
@self.route("/humans.txt")
def humans():
return flask.send_file(humans_path)

if os.path.isfile(security_path):

@self.route("/.well-known/security.txt")
def security():
return flask.send_file(security_path)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="canonicalwebteam.flask-base",
version="1.0.3",
version="1.0.4",
description=(
"Flask extension that applies common configurations"
"to all of webteam's flask apps."
Expand Down
1 change: 1 addition & 0 deletions tests/test_app/security.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
security is very important!
11 changes: 8 additions & 3 deletions tests/test_flask_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,25 @@ def test_favicon_serve(self):
response = client.get("/favicon.ico")
self.assertEqual(200, response.status_code)

def test_robots_humans(self):
def test_text_files(self):
"""
If `robots.txt` and `humans.txt` are provided at the root of the
project, check requests to `/robots.txt` load the content
If `robots.txt`, `humans.txt`, `security.txt` are provided at the root
of the project, check requests to `/robots.txt` load the content
"""

with create_test_app().test_client() as client:
warnings.simplefilter("ignore", ResourceWarning)
robots_response = client.get("robots.txt")
humans_response = client.get("humans.txt")
security_response = client.get("/.well-known/security.txt")
self.assertEqual(200, robots_response.status_code)
self.assertEqual(200, humans_response.status_code)
self.assertEqual(200, security_response.status_code)
self.assertEqual(robots_response.data, b"robots!")
self.assertEqual(humans_response.data, b"humans!")
self.assertEqual(
security_response.data, b"security is very important!"
)

def test_error_pages(self):
"""
Expand Down

0 comments on commit 34b5868

Please sign in to comment.