From 04bf470f6e7e06615be453e1adfe7c656bc5f153 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Thu, 1 Feb 2018 16:51:36 -0800 Subject: Add workaround for bpo-32713 Signed-off-by: Joffrey F --- tests/unit/utils_test.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/unit/utils_test.py') diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index 1f9daf6..1558891 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -995,6 +995,18 @@ class TarTest(unittest.TestCase): tar_data = tarfile.open(fileobj=archive) assert sorted(tar_data.getnames()) == ['bar', 'foo'] + def tar_test_negative_mtime_bug(self): + base = tempfile.mkdtemp() + filename = os.path.join(base, 'th.txt') + self.addCleanup(shutil.rmtree, base) + with open(filename, 'w') as f: + f.write('Invisible Full Moon') + os.utime(filename, (12345, -3600.0)) + with tar(base) as archive: + tar_data = tarfile.open(fileobj=archive) + assert tar_data.getnames() == ['th.txt'] + assert tar_data.getmember('th.txt').mtime == -3600 + class ShouldCheckDirectoryTest(unittest.TestCase): exclude_patterns = [ -- cgit v1.2.1 From 58639aecfa50e0bcfbd1415dc8bab2b4448f4d81 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Mon, 5 Feb 2018 13:11:19 -0800 Subject: Rewrite access check in create_archive with EAFP Signed-off-by: Joffrey F --- tests/unit/utils_test.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests/unit/utils_test.py') diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index 1f9daf6..3139a97 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -933,7 +933,10 @@ class TarTest(unittest.TestCase): tar_data = tarfile.open(fileobj=archive) assert sorted(tar_data.getnames()) == ['bar', 'foo'] - @pytest.mark.skipif(IS_WINDOWS_PLATFORM, reason='No chmod on Windows') + @pytest.mark.skipif( + IS_WINDOWS_PLATFORM or os.geteuid() == 0, + reason='root user always has access ; no chmod on Windows' + ) def test_tar_with_inaccessible_file(self): base = tempfile.mkdtemp() full_path = os.path.join(base, 'foo') @@ -944,8 +947,9 @@ class TarTest(unittest.TestCase): with pytest.raises(IOError) as ei: tar(base) - assert 'Can not access file in context: {}'.format(full_path) in \ + assert 'Can not read file in context: {}'.format(full_path) in ( ei.exconly() + ) @pytest.mark.skipif(IS_WINDOWS_PLATFORM, reason='No symlinks on Windows') def test_tar_with_file_symlinks(self): -- cgit v1.2.1 From 34d50483e20e86cb7ab22700e036a5c4d319268a Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Mon, 12 Feb 2018 14:59:41 -0800 Subject: Correctly support absolute paths in .dockerignore Signed-off-by: Joffrey F --- tests/unit/utils_test.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'tests/unit/utils_test.py') diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index eedcf71..e144b7b 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -876,6 +876,13 @@ class ExcludePathsTest(unittest.TestCase): ) ) + def test_exclude_include_absolute_path(self): + base = make_tree([], ['a.py', 'b.py']) + assert exclude_paths( + base, + ['/*', '!' + os.path.join(base, '*.py')] + ) == set(['a.py', 'b.py']) + class TarTest(unittest.TestCase): def test_tar_with_excludes(self): @@ -1026,52 +1033,52 @@ class ShouldCheckDirectoryTest(unittest.TestCase): def test_should_check_directory_not_excluded(self): assert should_check_directory( - 'not_excluded', self.exclude_patterns, self.include_patterns + 'not_excluded', self.exclude_patterns, self.include_patterns, '.' ) assert should_check_directory( convert_path('dir/with'), self.exclude_patterns, - self.include_patterns + self.include_patterns, '.' ) def test_shoud_check_parent_directories_of_excluded(self): assert should_check_directory( - 'dir', self.exclude_patterns, self.include_patterns + 'dir', self.exclude_patterns, self.include_patterns, '.' ) assert should_check_directory( convert_path('dir/with'), self.exclude_patterns, - self.include_patterns + self.include_patterns, '.' ) def test_should_not_check_excluded_directories_with_no_exceptions(self): assert not should_check_directory( 'exclude_rather_large_directory', self.exclude_patterns, - self.include_patterns + self.include_patterns, '.' ) assert not should_check_directory( convert_path('dir/with/subdir_excluded'), self.exclude_patterns, - self.include_patterns + self.include_patterns, '.' ) def test_should_check_excluded_directory_with_exceptions(self): assert should_check_directory( convert_path('dir/with/exceptions'), self.exclude_patterns, - self.include_patterns + self.include_patterns, '.' ) assert should_check_directory( convert_path('dir/with/exceptions/in'), self.exclude_patterns, - self.include_patterns + self.include_patterns, '.' ) def test_should_not_check_siblings_of_exceptions(self): assert not should_check_directory( convert_path('dir/with/exceptions/but_not_here'), - self.exclude_patterns, self.include_patterns + self.exclude_patterns, self.include_patterns, '.' ) def test_should_check_subdirectories_of_exceptions(self): assert should_check_directory( convert_path('dir/with/exceptions/like_this_one/subdir'), - self.exclude_patterns, self.include_patterns + self.exclude_patterns, self.include_patterns, '.' ) -- cgit v1.2.1 From 181c1c8eb970ae11a707b6b6c3d1e4d546504ccf Mon Sep 17 00:00:00 2001 From: mefyl Date: Fri, 16 Feb 2018 11:03:35 +0100 Subject: Revert "Correctly support absolute paths in .dockerignore" This reverts commit 34d50483e20e86cb7ab22700e036a5c4d319268a. Signed-off-by: mefyl --- tests/unit/utils_test.py | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'tests/unit/utils_test.py') diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index e144b7b..eedcf71 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -876,13 +876,6 @@ class ExcludePathsTest(unittest.TestCase): ) ) - def test_exclude_include_absolute_path(self): - base = make_tree([], ['a.py', 'b.py']) - assert exclude_paths( - base, - ['/*', '!' + os.path.join(base, '*.py')] - ) == set(['a.py', 'b.py']) - class TarTest(unittest.TestCase): def test_tar_with_excludes(self): @@ -1033,52 +1026,52 @@ class ShouldCheckDirectoryTest(unittest.TestCase): def test_should_check_directory_not_excluded(self): assert should_check_directory( - 'not_excluded', self.exclude_patterns, self.include_patterns, '.' + 'not_excluded', self.exclude_patterns, self.include_patterns ) assert should_check_directory( convert_path('dir/with'), self.exclude_patterns, - self.include_patterns, '.' + self.include_patterns ) def test_shoud_check_parent_directories_of_excluded(self): assert should_check_directory( - 'dir', self.exclude_patterns, self.include_patterns, '.' + 'dir', self.exclude_patterns, self.include_patterns ) assert should_check_directory( convert_path('dir/with'), self.exclude_patterns, - self.include_patterns, '.' + self.include_patterns ) def test_should_not_check_excluded_directories_with_no_exceptions(self): assert not should_check_directory( 'exclude_rather_large_directory', self.exclude_patterns, - self.include_patterns, '.' + self.include_patterns ) assert not should_check_directory( convert_path('dir/with/subdir_excluded'), self.exclude_patterns, - self.include_patterns, '.' + self.include_patterns ) def test_should_check_excluded_directory_with_exceptions(self): assert should_check_directory( convert_path('dir/with/exceptions'), self.exclude_patterns, - self.include_patterns, '.' + self.include_patterns ) assert should_check_directory( convert_path('dir/with/exceptions/in'), self.exclude_patterns, - self.include_patterns, '.' + self.include_patterns ) def test_should_not_check_siblings_of_exceptions(self): assert not should_check_directory( convert_path('dir/with/exceptions/but_not_here'), - self.exclude_patterns, self.include_patterns, '.' + self.exclude_patterns, self.include_patterns ) def test_should_check_subdirectories_of_exceptions(self): assert should_check_directory( convert_path('dir/with/exceptions/like_this_one/subdir'), - self.exclude_patterns, self.include_patterns, '.' + self.exclude_patterns, self.include_patterns ) -- cgit v1.2.1 From c8f5a5ad4040560ce62d53002ecec12485b531f7 Mon Sep 17 00:00:00 2001 From: mefyl Date: Fri, 16 Feb 2018 11:22:29 +0100 Subject: Fix dockerignore handling of absolute path exceptions. Signed-off-by: mefyl --- tests/unit/utils_test.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/unit/utils_test.py') diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index eedcf71..0ee041a 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -758,6 +758,13 @@ class ExcludePathsTest(unittest.TestCase): self.all_paths - set(['foo/a.py']) ) + def test_exclude_include_absolute_path(self): + base = make_tree([], ['a.py', 'b.py']) + assert exclude_paths( + base, + ['/*', '!/*.py'] + ) == set(['a.py', 'b.py']) + def test_single_subdir_with_path_traversal(self): assert self.exclude(['foo/whoops/../a.py']) == convert_paths( self.all_paths - set(['foo/a.py']) -- cgit v1.2.1 From bb3ad64060b1f1136a6a42ed4d2018f71ebd371d Mon Sep 17 00:00:00 2001 From: mefyl Date: Fri, 16 Feb 2018 16:08:11 +0100 Subject: Fix .dockerignore: accept wildcard in inclusion pattern, honor last line precedence. Signed-off-by: mefyl --- tests/unit/utils_test.py | 84 ++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 64 deletions(-) (limited to 'tests/unit/utils_test.py') diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index 0ee041a..8a4b193 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -23,7 +23,6 @@ from docker.utils import ( decode_json_header, tar, split_command, parse_devices, update_headers, ) -from docker.utils.build import should_check_directory from docker.utils.ports import build_port_bindings, split_port from docker.utils.utils import format_environment @@ -883,6 +882,26 @@ class ExcludePathsTest(unittest.TestCase): ) ) + def test_include_wildcard(self): + base = make_tree(['a'], ['a/b.py']) + assert exclude_paths( + base, + ['*', '!*/b.py'] + ) == convert_paths(['a/b.py']) + + def test_last_line_precedence(self): + base = make_tree( + [], + ['garbage.md', + 'thrash.md', + 'README.md', + 'README-bis.md', + 'README-secret.md']) + assert exclude_paths( + base, + ['*.md', '!README*.md', 'README-secret.md'] + ) == set(['README.md', 'README-bis.md']) + class TarTest(unittest.TestCase): def test_tar_with_excludes(self): @@ -1019,69 +1038,6 @@ class TarTest(unittest.TestCase): assert tar_data.getmember('th.txt').mtime == -3600 -class ShouldCheckDirectoryTest(unittest.TestCase): - exclude_patterns = [ - 'exclude_rather_large_directory', - 'dir/with/subdir_excluded', - 'dir/with/exceptions' - ] - - include_patterns = [ - 'dir/with/exceptions/like_this_one', - 'dir/with/exceptions/in/descendents' - ] - - def test_should_check_directory_not_excluded(self): - assert should_check_directory( - 'not_excluded', self.exclude_patterns, self.include_patterns - ) - assert should_check_directory( - convert_path('dir/with'), self.exclude_patterns, - self.include_patterns - ) - - def test_shoud_check_parent_directories_of_excluded(self): - assert should_check_directory( - 'dir', self.exclude_patterns, self.include_patterns - ) - assert should_check_directory( - convert_path('dir/with'), self.exclude_patterns, - self.include_patterns - ) - - def test_should_not_check_excluded_directories_with_no_exceptions(self): - assert not should_check_directory( - 'exclude_rather_large_directory', self.exclude_patterns, - self.include_patterns - ) - assert not should_check_directory( - convert_path('dir/with/subdir_excluded'), self.exclude_patterns, - self.include_patterns - ) - - def test_should_check_excluded_directory_with_exceptions(self): - assert should_check_directory( - convert_path('dir/with/exceptions'), self.exclude_patterns, - self.include_patterns - ) - assert should_check_directory( - convert_path('dir/with/exceptions/in'), self.exclude_patterns, - self.include_patterns - ) - - def test_should_not_check_siblings_of_exceptions(self): - assert not should_check_directory( - convert_path('dir/with/exceptions/but_not_here'), - self.exclude_patterns, self.include_patterns - ) - - def test_should_check_subdirectories_of_exceptions(self): - assert should_check_directory( - convert_path('dir/with/exceptions/like_this_one/subdir'), - self.exclude_patterns, self.include_patterns - ) - - class FormatEnvironmentTest(unittest.TestCase): def test_format_env_binary_unicode_value(self): env_dict = { -- cgit v1.2.1