From 65a7ce2461db43a4e35e1803775092cf925f45e1 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 9 Jan 2025 09:45:40 +0100 Subject: [PATCH] sources: relax "mirror" regexp to follow upstream repo ID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit relaxes the "mirror" schema regex from only allow hashes to the repo ID regex as described in https://dnf.readthedocs.io/en/latest/conf_ref.html#description This is needed because in e.g. bootc-image-builder we use "SetRootDir()" to get the repository information from an existing bootc image and there the repo_id (that is then used as the mirror_id) is written in a human friendly way instead of hex. Thanks to Tomáš Hozza for the suggestions and background info, see https://github.com/osbuild/osbuild/pull/1974#issuecomment-2579325272 --- sources/org.osbuild.librepo | 5 ++++- sources/test/test_librepo.py | 11 +++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sources/org.osbuild.librepo b/sources/org.osbuild.librepo index 19acbd2a..ade596ae 100755 --- a/sources/org.osbuild.librepo +++ b/sources/org.osbuild.librepo @@ -22,6 +22,9 @@ from osbuild.util.rhsm import Subscriptions # NOTE: The top level schema properties are limited to items and options by the # v2 schema definition +# +# "mirror" pattern follows dnf repo_id as described in: +# https://dnf.readthedocs.io/en/latest/conf_ref.html#description SCHEMA_2 = """ "properties": { "items": { @@ -57,7 +60,7 @@ SCHEMA_2 = """ "type": "object", "additionalProperties": false, "patternProperties": { - "^[0-9a-f]+$": { + "^[0-9a-zA-Z-._:]+$": { "required": [ "url", "type" diff --git a/sources/test/test_librepo.py b/sources/test/test_librepo.py index 42a52b44..78529f40 100644 --- a/sources/test/test_librepo.py +++ b/sources/test/test_librepo.py @@ -140,9 +140,9 @@ def test_librepo_secrets_mtls(mocked_download_pkgs, sources_service, monkeypatch @pytest.mark.parametrize("test_mirrors,expected_err", [ # bad ( - # only hashes supported for mirror_ids - {"bad_mirror_id": {"url": "http://example.com", "type": "mirrorlist"}}, - "'bad_mirror_id' does not match any of the regexes: '^[0-9a-f]+$'", + # no spaces in mirror_id + {"bad mirror": {"url": "http://example.com", "type": "mirrorlist"}}, + "'bad mirror' does not match any of the regexes: ", ), ( {"0123456789abcdef": {"type": "mirrorlist"}}, @@ -168,7 +168,10 @@ def test_librepo_secrets_mtls(mocked_download_pkgs, sources_service, monkeypatch ), ( {"0123": {"url": "http://example.com", "type": "baseurl"}}, "", - ) + ), + ( + {"Com_plex:id.": {"url": "http://x.com", "type": "baseurl"}}, "", + ), ]) def test_schema_validation(sources_schema, test_mirrors, expected_err): test_input = {