Skip prefix validation for modules in allowed_privileged_module_names and base_module_names

Signed-off-by: Valerij Maljulin <vmaljuli@redhat.com>
This commit is contained in:
Valerij Maljulin
2019-08-02 17:08:15 +02:00
parent 2690af4142
commit e5735efc76
2 changed files with 24 additions and 0 deletions

View File

@@ -230,6 +230,16 @@ def validate_koji_tag(tag_arg_names, pre="", post="-", dict_key="name"):
def wrapper(*args, **kwargs):
call_args = inspect.getcallargs(function, *args, **kwargs)
# if module name is in allowed_privileged_module_names or base_module_names lists
# we don't have to validate it since they could use an arbitrary Koji tag
try:
if call_args['self'].module_str in \
conf.allowed_privileged_module_names + conf.base_module_names:
# skip validation
return function(*args, **kwargs)
except (AttributeError, KeyError):
pass
for tag_arg_name in tag_arg_names:
err_subject = "Koji tag validation:"

View File

@@ -759,6 +759,20 @@ class TestUtils:
validate_koji_tag_is_None(None)
assert str(cm.value).endswith(" No value provided.") is True
@patch(
"module_build_service.config.Config.allowed_privileged_module_names",
new_callable=mock.PropertyMock,
return_value=["testmodule"],
)
def test_validate_koji_tag_previleged_module_name(self, conf_apmn):
@module_build_service.utils.validate_koji_tag("tag_arg")
def validate_koji_tag_priv_mod_name(self, tag_arg):
pass
builder = mock.MagicMock()
builder.module_str = 'testmodule'
validate_koji_tag_priv_mod_name(builder, "abc")
@patch("module_build_service.scm.SCM")
def test_record_component_builds_duplicate_components(self, mocked_scm, db_session):
clean_database()