clarify name of request_path_to_instance_resource_path

This commit is contained in:
Brian S. Stephan 2021-02-20 17:53:32 -06:00
parent 6026c51490
commit 1c40f45ffd
2 changed files with 26 additions and 25 deletions

View File

@ -20,7 +20,7 @@ bp = Blueprint('pages', __name__, url_prefix='/')
def display_page(path):
"""Get the file contents of the requested path and render the file."""
try:
resolved_path = request_path_to_instance_resource(path)
resolved_path = request_path_to_instance_resource_path(path)
logger.debug("received request for path '%s', resolved to '%s'", path, resolved_path)
except PermissionError:
abort(400)
@ -71,7 +71,7 @@ def render(template_name_or_list, **context):
return resp
def request_path_to_instance_resource(path):
def request_path_to_instance_resource_path(path):
"""Turn a request URL path to the full page path.
flask.Flask.open_instance_resource will open a file like /etc/hosts if you tell it to,

View File

@ -2,7 +2,8 @@
import pytest
from werkzeug.http import dump_cookie
from incorporealcms.pages import generate_parent_navs, render, request_path_to_instance_resource, resolve_page_file
from incorporealcms.pages import (generate_parent_navs, render, request_path_to_instance_resource_path,
resolve_page_file)
def test_resolve_page_file_dir_to_index():
@ -77,71 +78,71 @@ def test_render_with_no_user_theme(app):
assert b'dark.css' not in render('base.html').data
def test_request_path_to_instance_resource(app):
def test_request_path_to_instance_resource_path(app):
"""Test a normal URL request is transformed into the file path."""
with app.test_request_context():
assert request_path_to_instance_resource('index') == 'pages/index.md'
assert request_path_to_instance_resource_path('index') == 'pages/index.md'
def test_request_path_to_instance_resource_direct_file(app):
def test_request_path_to_instance_resource_path_direct_file(app):
"""Test a normal URL request is transformed into the file path."""
with app.test_request_context():
assert request_path_to_instance_resource('no-title') == 'pages/no-title.md'
assert request_path_to_instance_resource_path('no-title') == 'pages/no-title.md'
def test_request_path_to_instance_resource_in_subdir(app):
def test_request_path_to_instance_resource_path_in_subdir(app):
"""Test a normal URL request is transformed into the file path."""
with app.test_request_context():
assert request_path_to_instance_resource('subdir/page') == 'pages/subdir/page.md'
assert request_path_to_instance_resource_path('subdir/page') == 'pages/subdir/page.md'
def test_request_path_to_instance_resource_subdir_index(app):
def test_request_path_to_instance_resource_path_subdir_index(app):
"""Test a normal URL request is transformed into the file path."""
with app.test_request_context():
assert request_path_to_instance_resource('subdir/') == 'pages/subdir/index.md'
assert request_path_to_instance_resource_path('subdir/') == 'pages/subdir/index.md'
def test_request_path_to_instance_resource_relatives_walked(app):
def test_request_path_to_instance_resource_path_relatives_walked(app):
"""Test a normal URL request is transformed into the file path."""
with app.test_request_context():
assert request_path_to_instance_resource('subdir/more-subdir/../../more-metadata') == 'pages/more-metadata.md'
assert request_path_to_instance_resource_path('subdir/more-subdir/../../more-metadata') == 'pages/more-metadata.md'
def test_request_path_to_instance_resource_relatives_walked_indexes_work_too(app):
def test_request_path_to_instance_resource_path_relatives_walked_indexes_work_too(app):
"""Test a normal URL request is transformed into the file path."""
with app.test_request_context():
assert request_path_to_instance_resource('subdir/more-subdir/../../') == 'pages/index.md'
assert request_path_to_instance_resource_path('subdir/more-subdir/../../') == 'pages/index.md'
def test_request_path_to_instance_resource_relatives_walked_into_subdirs_also_fine(app):
def test_request_path_to_instance_resource_path_relatives_walked_into_subdirs_also_fine(app):
"""Test a normal URL request is transformed into the file path."""
with app.test_request_context():
assert request_path_to_instance_resource('subdir/more-subdir/../../subdir/page') == 'pages/subdir/page.md'
assert request_path_to_instance_resource_path('subdir/more-subdir/../../subdir/page') == 'pages/subdir/page.md'
def test_request_path_to_instance_resource_permission_error_on_ref_above_pages(app):
def test_request_path_to_instance_resource_path_permission_error_on_ref_above_pages(app):
"""Test that attempts to get above the base dir ("/../../foo") fail."""
with app.test_request_context():
with pytest.raises(PermissionError):
assert request_path_to_instance_resource('../unreachable')
assert request_path_to_instance_resource_path('../unreachable')
def test_request_path_to_instance_resource_isadirectory_on_file_like_req_for_dir(app):
def test_request_path_to_instance_resource_path_isadirectory_on_file_like_req_for_dir(app):
"""Test that a request for e.g. '/foo' when foo is a dir indicate to redirect."""
with app.test_request_context():
with pytest.raises(IsADirectoryError):
assert request_path_to_instance_resource('subdir')
assert request_path_to_instance_resource_path('subdir')
def test_request_path_to_instance_resource_nonexistant_file_errors(app):
def test_request_path_to_instance_resource_path_nonexistant_file_errors(app):
"""Test that a request for something not on disk errors."""
with app.test_request_context():
with pytest.raises(FileNotFoundError):
assert request_path_to_instance_resource('nthanpthpnh')
assert request_path_to_instance_resource_path('nthanpthpnh')
def test_request_path_to_instance_resource_absolute_file_errors(app):
def test_request_path_to_instance_resource_path_absolute_file_errors(app):
"""Test that a request for something not on disk errors."""
with app.test_request_context():
with pytest.raises(PermissionError):
assert request_path_to_instance_resource('/etc/hosts')
assert request_path_to_instance_resource_path('/etc/hosts')