Skip to content

Commit

Permalink
test: Add tests to check non-standard-dir-perm
Browse files Browse the repository at this point in the history
See #1196
  • Loading branch information
danigm authored and Conan-Kudo committed Feb 22, 2024
1 parent 41b9725 commit 8c1b637
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
10 changes: 9 additions & 1 deletion rpmlint/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,9 @@ def _mock_file(self, path, attrs):
self.add_dir(str(i))
metadata = attrs.get('metadata', None)

if attrs.get('is_dir', False):
self.add_dir(path, metadata=metadata)

content = ''
if 'content-path' in attrs:
content = open(attrs['content-path'], 'rb')
Expand Down Expand Up @@ -873,11 +876,16 @@ def create_files(self, files):
for path, file in files.items():
self._mock_file(path, file)

def add_dir(self, path):
def add_dir(self, path, metadata=None):
pkgdir = PkgFile(path)
pkgdir.magic = 'directory'
pkgdir.path = path
self.files[path] = pkgdir

if metadata:
for k, v in metadata.items():
setattr(pkgdir, k, v)

return pkgdir

def add_file_with_content(self, name, content, metadata=None, **flags):
Expand Down
Binary file not shown.
33 changes: 33 additions & 0 deletions test/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,36 @@ def test_shebang_ok(package, output, test):
test.check(package)
out = output.print_results(output.results)
assert 'W: symlink-to-binary-with-shebang /usr/bin/testlink' not in out


@pytest.mark.parametrize('package', [
get_tested_mock_package(
header={'requires': []},
files={
'/etc/raddb/mods-config/sql/moonshot-targeted-ids/mysql': {
'is_dir': True,
'metadata': {'mode': 0o640 | stat.S_IFDIR},
},
'/etc/raddb/mods-config/sql/moonshot-targeted-ids/postgresql': {
'is_dir': True,
'metadata': {'mode': 0o640 | stat.S_IFDIR},
},
'/etc/raddb/mods-config/sql/moonshot-targeted-ids/sqlite': {
'is_dir': True,
'metadata': {'mode': 0o640 | stat.S_IFDIR},
},
},
),
])
def test_directory_without_x_permission(package, output, test):
test.check(package)
out = output.print_results(output.results)
assert 'E: non-standard-dir-perm' in out


@pytest.mark.parametrize('package', ['binary/freeradius-server'])
def test_directory_without_x_permission2(tmp_path, package, filescheck):
output, test = filescheck
test.check(get_tested_package(package, tmp_path))
out = output.print_results(output.results)
assert 'E: non-standard-dir-perm' in out

0 comments on commit 8c1b637

Please sign in to comment.