diff --git a/mwscan/scan.py b/mwscan/scan.py index 35a0823..f702759 100755 --- a/mwscan/scan.py +++ b/mwscan/scan.py @@ -150,8 +150,11 @@ def find_targets(root_path, required_extensions=None, if required_extensions and myfile.split('.')[-1] not in required_extensions: continue - if os.path.islink(path) and not follow_symlinks: - continue + if os.path.islink(path): + if not follow_symlinks: + continue + if not os.path.exists(path): + continue if [x for x in exclude_patterns if re.search(x, path)]: continue diff --git a/mwscan/tests/test_mwscan.py b/mwscan/tests/test_mwscan.py index a3ce300..3907ed6 100644 --- a/mwscan/tests/test_mwscan.py +++ b/mwscan/tests/test_mwscan.py @@ -85,9 +85,15 @@ def test_find_targets_will_exclude_patterns(self): files = list(scan.find_targets(self.target_path, exclude_patterns=p)) assert files == [], files - def test_that_symlinks_are_followed(self): + def test_that_symlinks_are_properly_followed(self): paths = scan.find_targets(self.target_path, follow_symlinks=True) - files = map(os.path.basename, paths) + files = list(map(os.path.basename, paths)) + + + # py3 returns map whereas py2 returns list, + # map can only be iterated once + assert len(files) > 5, 'bogus files obj' + assert 'im_a_symlink' in files, \ 'no symlink found in results' assert 'recursive_symlink' not in files, \