Skip to content

Commit e85a3b3

Browse files
committed
Replace os.sep with '/' in _check_path()
Use a hard-coded unix separator ('/') so that an exception is also raised for paths starting with '/' when executing on Windows systems. Update test_check_path to explicitly test invalid paths starting with Windows style separator. Signed-off-by: Teodora Sechkova <[email protected]>
1 parent 87e1e11 commit e85a3b3

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

tests/test_repository_tool.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,10 +1677,6 @@ def test_add_paths(self):
16771677
# paths, which it previously did.
16781678
self.targets_object.add_paths(['non-existent'], 'tuf')
16791679

1680-
# add_paths() should not raise an exception for paths that
1681-
# are not located in the repository's targets directory
1682-
repository_directory = os.path.join('repository_data', 'repository')
1683-
self.targets_object.add_paths([repository_directory], 'tuf')
16841680

16851681

16861682

@@ -1724,11 +1720,16 @@ def test_check_path(self):
17241720
self.assertRaises(securesystemslib.exceptions.FormatError,
17251721
self.targets_object._check_path, 3)
17261722

1727-
# Test invalid pathname - starting with os separator
1723+
# Test invalid pathname
1724+
# Starting with os separator
17281725
self.assertRaises(tuf.exceptions.InvalidNameError,
17291726
self.targets_object._check_path, '/file1.txt')
17301727

1731-
# Test invalid pathname - using '\' as os separator
1728+
# Starting with Windows-style separator
1729+
self.assertRaises(tuf.exceptions.InvalidNameError,
1730+
self.targets_object._check_path, '\\file1.txt')
1731+
1732+
# Using Windows-style separator ('\')
17321733
self.assertRaises(tuf.exceptions.InvalidNameError,
17331734
self.targets_object._check_path, 'subdir\\non-existent')
17341735

tuf/repository_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2784,7 +2784,7 @@ def _check_path(self, pathname):
27842784
raise tuf.exceptions.InvalidNameError('Path ' + repr(pathname)
27852785
+ ' does not use the forward slash (/) as directory separator.')
27862786

2787-
if pathname.startswith(os.sep):
2787+
if pathname.startswith('/'):
27882788
raise tuf.exceptions.InvalidNameError('Path ' + repr(pathname)
27892789
+ ' starts with a directory separator. All paths should be relative'
27902790
' to targets directory.')

0 commit comments

Comments
 (0)