Skip to content
Myr

Add tests for safe_join

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Giampaolo Eusebi · committed by Giampaolo Eusebi · parent 03ea11f · Browse files · 1 file+43 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+43 added−1 removed

  • tests:+43 added−1 removed

1 file+43 added−1 removed

modified:tests/test_helpers.py+43 added-1 removed
13 unmodified lines
14import os15import datetime16import flask17from logging import StreamHandler18from werkzeug.exceptions import BadRequest18from werkzeug.exceptions import BadRequest, NotFound19from werkzeug.http import parse_cache_control_header, parse_options_header20from werkzeug.http import http_date21from flask._compat import StringIO, text_type22
698 unmodified lines
721 c = app.test_client()722 rv = c.get('/?name=World')723 assert rv.data == b'Hello World!'724 assert called == [42]725726727class TestSafeJoin(object):728729 def test_safe_join(self):730 # Valid combinations of *args and expected joined paths.731 passing = (732 (('a/b/c', ), 'a/b/c'),733 (('/', 'a/', 'b/', 'c/', ), '/a/b/c'),734 (('a', 'b', 'c', ), 'a/b/c'),735 (('/a', 'b/c', ), '/a/b/c'),736 (('a/b', 'X/../c'), 'a/b/c', ),737 (('/a/b', 'c/X/..'), '/a/b/c', ),738 # If last path is '' add a slash739 (('/a/b/c', '', ), '/a/b/c/', ),740 # Preserve dot slash741 (('/a/b/c', './', ), '/a/b/c/.', ),742 (('a/b/c', 'X/..'), 'a/b/c/.', ),743 # Base directory is always considered safe744 (('../', 'a/b/c'), '../a/b/c'),745 (('/..', ), '/..'),746 )747748 for args, expected in passing:749 assert flask.safe_join(*args) == expected750751 def test_safe_join_exceptions(self):752 # Should raise werkzeug.exceptions.NotFound on unsafe joins.753 failing = (754 # path.isabs and ``..'' checks755 ('/a', 'b', '/c'),756 ('/a', '../b/c', ),757 ('/a', '..', 'b/c'),758 # Boundaries violations after path normalization759 ('/a', 'b/../b/../../c', ),760 ('/a', 'b', 'c/../..'),761 ('/a', 'b/../../c', ),762 )763764 for args in failing:765 with pytest.raises(NotFound):766 print(flask.safe_join(*args))