aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArthur Zamarin <arthurzam@gentoo.org>2022-10-30 20:36:27 +0200
committerArthur Zamarin <arthurzam@gentoo.org>2022-10-31 20:29:55 +0200
commit4e69c9d901c37d631cfff6316103e4be53b214c3 (patch)
treeeddcefb828b566bd6b0271edea5fc42b7f1257f8 /tests
parentDoCompressedFilesCheck: new check for compressed do calls (diff)
downloadpkgcheck-4e69c9d901c37d631cfff6316103e4be53b214c3.tar.gz
pkgcheck-4e69c9d901c37d631cfff6316103e4be53b214c3.tar.bz2
pkgcheck-4e69c9d901c37d631cfff6316103e4be53b214c3.zip
AcctCheck: use metadata/qa-policy.conf for dynamic id range
Load UID and GID range from metadata/qa-policy.conf under the repo, validate the format is as expected, and use the values to set expected ids. Resolves: https://github.com/pkgcore/pkgcheck/issues/356 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/checks/test_acct.py69
1 files changed, 62 insertions, 7 deletions
diff --git a/tests/checks/test_acct.py b/tests/checks/test_acct.py
index cd8f852f..57273705 100644
--- a/tests/checks/test_acct.py
+++ b/tests/checks/test_acct.py
@@ -1,4 +1,7 @@
-from pkgcheck.checks import acct
+import textwrap
+
+import pytest
+from pkgcheck.checks import acct, SkipCheck
from pkgcore.test.misc import FakeRepo
from snakeoil.cli import arghparse
@@ -11,17 +14,27 @@ class TestAcctUser(misc.ReportTestCase):
kind = 'user'
+ @pytest.fixture(autouse=True)
+ def _setup(self, tmp_path):
+ (metadata := tmp_path / 'metadata').mkdir()
+ (metadata / 'qa-policy.conf').write_text(textwrap.dedent("""\
+ [user-group-ids]
+ uid-range = 0-749,65534
+ gid-range = 0-749,65533,65534
+ """))
+ self.location = str(tmp_path)
+
def mk_check(self, pkgs):
- self.repo = FakeRepo(pkgs=pkgs, repo_id='test')
- check = self.check_kls(arghparse.Namespace(target_repo=self.repo, gentoo_repo=True))
+ repo = FakeRepo(pkgs=pkgs, repo_id='test', location=self.location)
+ check = self.check_kls(arghparse.Namespace(target_repo=repo, gentoo_repo=True))
return check
def mk_pkg(self, name, identifier, version=1, ebuild=None):
if ebuild is None:
- ebuild = f'''
-inherit acct-{self.kind}
-ACCT_{self.kind.upper()}_ID="{identifier}"
-'''
+ ebuild = textwrap.dedent(f'''\
+ inherit acct-{self.kind}
+ ACCT_{self.kind.upper()}_ID="{identifier}"
+ ''')
return misc.FakePkg(f'acct-{self.kind}/{name}-{version}', ebuild=ebuild)
def test_unmatching_pkgs(self):
@@ -33,6 +46,7 @@ ACCT_{self.kind.upper()}_ID="{identifier}"
def test_correct_ids(self):
pkgs = (self.mk_pkg('foo', 100),
self.mk_pkg('bar', 200),
+ self.mk_pkg('test', 749),
self.mk_pkg('nobody', 65534))
check = self.mk_check(pkgs)
self.assertNoReport(check, pkgs)
@@ -110,3 +124,44 @@ class TestAcctGroup(TestAcctUser):
pkg = self.mk_pkg('nogroup', 65533)
check = self.mk_check((pkg,))
self.assertNoReport(check, pkg)
+
+
+class TestQaPolicyValidation(misc.ReportTestCase):
+
+ def mk_check(self, tmp_path, content):
+ if content:
+ (metadata := tmp_path / 'metadata').mkdir()
+ (metadata / 'qa-policy.conf').write_text(textwrap.dedent(content))
+ repo = FakeRepo(repo_id='test', location=str(tmp_path))
+ return acct.AcctCheck(arghparse.Namespace(target_repo=repo, gentoo_repo=True))
+
+ def test_missing_qa_policy(self, tmp_path):
+ with pytest.raises(SkipCheck, match="failed loading 'metadata/qa-policy.conf'"):
+ self.mk_check(tmp_path, None)
+
+ def test_missing_section(self, tmp_path):
+ with pytest.raises(SkipCheck, match="missing section user-group-ids"):
+ self.mk_check(tmp_path, '''\
+ [random]
+ x = 5
+ ''')
+
+ def test_missing_config(self, tmp_path):
+ with pytest.raises(SkipCheck, match="missing value for gid-range"):
+ self.mk_check(tmp_path, '''\
+ [user-group-ids]
+ uid-range = 0-749
+ ''')
+
+ @pytest.mark.parametrize('value', (
+ 'start-end',
+ '0-749-1500',
+ ',150',
+ ))
+ def test_invalid_value(self, tmp_path, value):
+ with pytest.raises(SkipCheck, match="invalid value for uid-range"):
+ self.mk_check(tmp_path, f'''\
+ [user-group-ids]
+ uid-range = {value}
+ gid-range = 0-749
+ ''')