Move test for unsigned packages with pkgset_koji_scratch_tasks to PkgsetPhase class.

Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
This commit is contained in:
Jan Kaluza 2020-06-10 12:01:02 +02:00 committed by lsedlar
parent 4a15d1351a
commit e35c250700
3 changed files with 38 additions and 10 deletions

View File

@ -22,8 +22,9 @@ class PkgsetPhase(PhaseBase):
name = "pkgset"
def __init__(self, *args, **kwargs):
super(PkgsetPhase, self).__init__(*args, **kwargs)
def __init__(self, compose, *args, **kwargs):
super(PkgsetPhase, self).__init__(compose, *args, **kwargs)
self.compose = compose
self.package_sets = []
self.path_prefix = None
@ -36,3 +37,12 @@ class PkgsetPhase(PhaseBase):
container = PkgsetSourceContainer()
SourceClass = container[pkgset_source]
self.package_sets, self.path_prefix = SourceClass(self.compose)()
def validate(self):
extra_tasks = self.compose.conf.get("pkgset_koji_scratch_tasks", None)
sigkeys = tuple(self.compose.conf["sigkeys"] or [None])
if extra_tasks is not None and None not in sigkeys and "" not in sigkeys:
raise ValueError(
"Unsigned packages must be allowed to use the "
'"pkgset_koji_scratch_tasks" option'
)

View File

@ -497,15 +497,9 @@ class KojiPackageSet(PackageSetBase):
rpm_info, build_info = queue_item
# Check if this RPM is comming from scratch task. In this case, we already
# know the path and we must ensure unsigned packages are allowed.
# know the path.
if "path_from_task" in rpm_info:
if None in self.sigkey_ordering or "" in self.sigkey_ordering:
return rpm_info["path_from_task"]
else:
self.log_error(
"Scratch RPM %s cannot be used in signed compose." % (rpm_info)
)
return None
return rpm_info["path_from_task"]
pathinfo = self.koji_wrapper.koji_module.pathinfo
paths = []

View File

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from pungi.phases import pkgset
from tests import helpers
class TestPkgsetPhase(helpers.PungiTestCase):
def test_validates_pkgset_koji_scratch_tasks_only_signed(self):
cfg = {"pkgset_koji_scratch_tasks": ["123"], "sigkeys": ["sigkey"]}
compose = helpers.DummyCompose(self.topdir, cfg)
phase = pkgset.PkgsetPhase(compose)
with self.assertRaises(ValueError) as ctx:
phase.validate()
self.assertIn("Unsigned packages must be allowed", str(ctx.exception))
def test_validates_pkgset_koji_scratch_tasks_unsigned(self):
for unsigned_obj in ["", None]:
cfg = {
"pkgset_koji_scratch_tasks": ["123"],
"sigkeys": ["sigkey", unsigned_obj],
}
compose = helpers.DummyCompose(self.topdir, cfg)
phase = pkgset.PkgsetPhase(compose)
phase.validate()