Skip to content

Commit 01c36da

Browse files
committed
frontend: allow dot and plus characters in chroot denylist
Fix fedora-copr#3012
1 parent fb58083 commit 01c36da

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

frontend/coprs_frontend/coprs/forms.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
FALSE_VALUES = {False, "false", ""}
2929
REGEX_BOOTSTRAP_IMAGE = r"^[-\./\w]+(:\w+)?$"
30+
REGEX_CHROOT_DENYLIST = r"^[a-z0-9-_*.+]+$"
3031

3132

3233
class NoneFilter():
@@ -823,9 +824,10 @@ def validate_chroot_denylist(_form, field):
823824
string = field.data
824825
items = [x.lstrip().rstrip() for x in string.split(',')]
825826
for item in items:
826-
pattern = r'^[a-z0-9-_*]+$'
827-
if not re.match(pattern, item):
828-
raise wtforms.ValidationError('Pattern "{0}" does not match "{1}"'.format(item, pattern))
827+
if not re.match(REGEX_CHROOT_DENYLIST, item):
828+
raise wtforms.ValidationError(
829+
'Pattern "{0}" does not match "{1}"'
830+
.format(item, REGEX_CHROOT_DENYLIST))
829831

830832
matched = set()
831833
all_chroots = MockChrootsLogic.active_names()

frontend/coprs_frontend/tests/test_forms.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
import flask
44
from tests.coprs_test_case import CoprsTestCase
55
from coprs import app
6-
from coprs.forms import PinnedCoprsForm, CoprFormFactory, CreateModuleForm, REGEX_BOOTSTRAP_IMAGE
6+
from coprs.forms import (
7+
PinnedCoprsForm,
8+
CoprFormFactory,
9+
CreateModuleForm,
10+
REGEX_BOOTSTRAP_IMAGE,
11+
REGEX_CHROOT_DENYLIST,
12+
)
713

814

915
class TestCoprsFormFactory(CoprsTestCase):
@@ -103,3 +109,21 @@ def test_form_regexes():
103109
assert re.match(REGEX_BOOTSTRAP_IMAGE, "registry.fedoraproject.org/fedora:rawhide")
104110
assert re.match(REGEX_BOOTSTRAP_IMAGE, "registry.fedoraproject.org/fedora")
105111
assert not re.match(REGEX_BOOTSTRAP_IMAGE, "docker://example.com/test:30")
112+
113+
items = [
114+
"fedora",
115+
"fedora-*-x86_64",
116+
"fedora-*-*",
117+
"fedora-39-x86_64",
118+
"fedora-rawhide-aarch64",
119+
"amazonlinux-2023-aarch64",
120+
"centos-stream+epel-next-9-x86_64",
121+
"openeuler-22.03-x86_64",
122+
"opensuse-leap-15.4-x86_64",
123+
"opensuse-leap-15.4-x86_64",
124+
]
125+
for item in items:
126+
assert re.match(REGEX_CHROOT_DENYLIST, item)
127+
128+
for item in ["fe|ora", "#fedora", "fedora/39", "fedora:39"]:
129+
assert not re.match(REGEX_CHROOT_DENYLIST, item)

0 commit comments

Comments
 (0)