Skip to content

Commit

Permalink
[irods#3988] iput/irsync - file system loop prevention - symbolic links
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Kelly committed Jul 13, 2018
1 parent 7ecc922 commit 1712fa8
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions scripts/irods/test/test_icommands_file_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,15 +936,18 @@ def test_iput_r_symlink_issue_4009_4013_with_no_symlinks(self):
self.user0.assert_icommand('imkdir {target_collection}'.format(**locals()))

# make file
file_name = os.path.join(local_dir, 'the_file')
the_file_str = 'the_file'
file_name = os.path.join(local_dir, the_file_str)
lib.make_file(file_name, 10)

# make symlink with relative path
link_path_1 = os.path.join(local_dir, 'link1')
lib.execute_command(['ln', '-s', 'the_file', link_path_1])
link1_str = 'link1'
link_path_1 = os.path.join(local_dir, link1_str)
lib.execute_command(['ln', '-s', the_file_str, link_path_1])

# make symlink with fully qualified path
link_path_2 = os.path.join(local_dir, 'link2')
link2_str = 'link2'
link_path_2 = os.path.join(local_dir, link2_str)
lib.execute_command(['ln', '-s', file_name, link_path_2])

# create the other dir which we will link to
Expand Down Expand Up @@ -984,16 +987,16 @@ def test_iput_r_symlink_issue_4009_4013_with_no_symlinks(self):
needle = '{target_collection_path}:'.format(**locals())
self.assertIn(needle, stdout, '{0}: Expected stdout: "...{1}...", got: "{2}"'.format(cmd, needle, stdout))

self.assertIn('& the_file', stdout,
'{0}: Expected stdout: "...{1}...", got: "{2}"'.format(cmd, '& the_file', stdout))
self.assertIn('& '+the_file_str, stdout,
'{0}: Expected stdout: "...{1}...", got: "{2}"'.format(cmd, '& '+the_file_str, stdout))

# Now make sure the links were not copied:

self.assertNotIn('& link1', stdout,
'{0}: Not expected in stdout: "...{1}...", got: "{2}"'.format(cmd, '& link1', stdout))
self.assertNotIn('& '+link1_str, stdout,
'{0}: Not expected in stdout: "...{1}...", got: "{2}"'.format(cmd, '& '+link1_str, stdout))

self.assertNotIn('& link2', stdout,
'{0}: Not expected in stdout: "...{1}...", got: "{2}"'.format(cmd, '& link2', stdout))
self.assertNotIn('& '+link2_str, stdout,
'{0}: Not expected in stdout: "...{1}...", got: "{2}"'.format(cmd, '& '+link2_str, stdout))

needle = 'C- {target_collection_path}/{base_name}/anotherdirsym1'.format(**locals())
self.assertNotIn(needle, stdout, '{0}: Not expected stdout:\n"{1}"\nGot:\n"{2}"\n'.format(cmd, needle, stdout))
Expand Down Expand Up @@ -1029,15 +1032,18 @@ def test_iput_r_symlink_issue_4009_4013_with_symlinks(self):
self.user0.assert_icommand('imkdir {target_collection_path}'.format(**locals()))

# make file
file_name = os.path.join(local_dir, 'the_file')
the_file_str = 'the_file'
file_name = os.path.join(local_dir, the_file_str)
lib.make_file(file_name, 10)

# make symlink with relative path
link_path_1 = os.path.join(local_dir, 'link1')
lib.execute_command(['ln', '-s', 'the_file', link_path_1])
link1_str = 'link1'
link_path_1 = os.path.join(local_dir, link1_str)
lib.execute_command(['ln', '-s', the_file_str, link_path_1])

# make symlink with fully qualified path
link_path_2 = os.path.join(local_dir, 'link2')
link2_str = 'link2'
link_path_2 = os.path.join(local_dir, link2_str)
lib.execute_command(['ln', '-s', file_name, link_path_2])

# create the other dir which we will link to
Expand Down Expand Up @@ -1075,14 +1081,14 @@ def test_iput_r_symlink_issue_4009_4013_with_symlinks(self):
needle = '{target_collection_path}:'.format(**locals())
self.assertIn(needle, stdout, '{0}: Expected stdout: "...{1}...", got: "{2}"'.format(cmd, needle, stdout))

self.assertIn('& link1', stdout,
'{0}: Expected stdout: "...{1}...", got: "{2}"'.format(cmd, '& link1', stdout))
self.assertIn('& '+link1_str, stdout,
'{0}: Expected stdout: "...{1}...", got: "{2}"'.format(cmd, '& '+link1_str, stdout))

self.assertIn('& link2', stdout,
'{0}: Expected stdout: "...{1}...", got: "{2}"'.format(cmd, '& link2', stdout))
self.assertIn('& '+link2_str, stdout,
'{0}: Expected stdout: "...{1}...", got: "{2}"'.format(cmd, '& '+link2_str, stdout))

self.assertIn('& the_file', stdout,
'{0}: Expected stdout: "...{1}...", got: "{2}"'.format(cmd, '& the_file', stdout))
self.assertIn('& '+the_file_str, stdout,
'{0}: Expected stdout: "...{1}...", got: "{2}"'.format(cmd, '& '+the_file_str, stdout))

needle = 'C- {target_collection_path}/{base_name}/anotherdirsym1'.format(**locals())
self.assertIn(needle, stdout, '{0}: Expected stdout:\n"{1}"\nGot:\n"{2}"\n'.format(cmd, needle, stdout))
Expand Down Expand Up @@ -1766,7 +1772,7 @@ def test_iput_irsync_symlink_loop_general(self):
target_collection = 'target_' + base_name

try:
collection_path, stderr, rc = self.user0.run_icommand('ipwd')
collection_path, stderr, rc = self.admin.run_icommand('ipwd')

# The ipwd comes back with a newline for some reason
collection_path = collection_path.rstrip()
Expand All @@ -1776,7 +1782,7 @@ def test_iput_irsync_symlink_loop_general(self):
# Create the file system directory heirarchy
########
lib.make_dir_p(local_dir)
self.user0.assert_icommand('imkdir {target_collection_path}'.format(**locals()))
self.admin.assert_icommand('imkdir {target_collection_path}'.format(**locals()))

dirname1 = os.path.join(local_dir, 'dir1')
dirname2 = os.path.join(local_dir, 'dir2')
Expand Down Expand Up @@ -1826,7 +1832,7 @@ def test_iput_irsync_symlink_loop_general(self):

# Make sure the loop links are nowhere in this collection tree:
cmd = 'ils -lr {collection_path}'.format(**locals())
self.user0.assert_icommand_fail( cmd, 'STDOUT_SINGLELINE', 'symtodir' );
self.admin.assert_icommand_fail( cmd, 'STDOUT_SINGLELINE', 'symtodir' );

finally:
shutil.rmtree(os.path.abspath(dirname1), ignore_errors=True)
Expand Down

0 comments on commit 1712fa8

Please sign in to comment.