Skip to content

Commit

Permalink
fix test failed
Browse files Browse the repository at this point in the history
Signed-off-by: Chang-Ning Tsai <changnit@amazon.com>
  • Loading branch information
Chang-Ning Tsai committed Dec 19, 2023
1 parent dcdee62 commit 709f797
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 5 additions & 7 deletions app.py
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
"""
This is a simple cheatsheet webapp.
"""
"""This is a simple cheatsheet webapp."""

import os
from flask import Flask, abort, send_from_directory, render_template
Expand Down Expand Up @@ -77,12 +75,12 @@ def page_not_found(e):
def static_proxy(path):
"""Find static files safely."""
try:
safe_path = safe_join(ROOT, path)
return send_from_directory(ROOT, safe_path)
except (FileNotFoundError, IsADirectoryError):
return send_from_directory(ROOT, path)
except NotFound:
# Handle file not found or directory errors
return render_template("404.html"), 404


@app.route("/")
def index_redirection():
"""Redirecting index file."""
Expand All @@ -101,4 +99,4 @@ def acme(token):

if __name__ == "__main__":
# Only run the app in debug mode during development
app.run(debug=os.environ.get("FLASK_ENV") == "development")
app.run(debug=os.environ.get("FLASK_ENV") == "development")
4 changes: 4 additions & 0 deletions app_test.py
Expand Up @@ -138,6 +138,10 @@ def test_static_proxy(self):
self.assertEqual(resp.status_code, 200)
resp.close()

u = "notes/../conf.py"
_, code = static_proxy(u)
self.assertEqual(code, 404)

def test_page_not_found(self):
"""Test page not found."""
html, status_code = page_not_found(None)
Expand Down

0 comments on commit 709f797

Please sign in to comment.