Skip to content

Commit

Permalink
Add basic test for in_directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Oct 25, 2017
1 parent 899b0d8 commit 4b5dc39
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/galaxy/util/__init__.py
Expand Up @@ -609,6 +609,20 @@ def in_directory( file, directory, local_path_module=os.path ):
local_path_module is used by Pulsar to check Windows paths while running on
a POSIX-like system.
>>> base_dir = tempfile.mkdtemp()
>>> safe_dir = os.path.join(base_dir, "user")
>>> os.mkdir(safe_dir)
>>> good_file = os.path.join(safe_dir, "1")
>>> with open(good_file, "w") as f: f.write("hello")
>>> in_directory(good_file, safe_dir)
True
>>> in_directory("/other/file/is/here.txt", safe_dir)
False
>>> unsafe_link = os.path.join(safe_dir, "2")
>>> os.symlink("/other/file/bad.fasta", unsafe_link)
>>> in_directory(unsafe_link, safe_dir)
False
"""
if local_path_module != os.path:
_safe_contains = importlib.import_module('galaxy.util.path.%s' % local_path_module.__name__).safe_contains
Expand Down

0 comments on commit 4b5dc39

Please sign in to comment.