Skip to content

Commit

Permalink
Use empty string to indicate unrecognized scheme
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Styk <[email protected]>
  • Loading branch information
StykMartin committed Dec 24, 2023
1 parent 1308016 commit 3b14e3e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Server/bkr/server/distrotrees.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,13 @@ def add_distro_urls(distro_tree, lab_controller, urls):
Adds supplied URLs to specific distro tree under specific lab controller.
Old URL will be replaced if new URL uses the same scheme
"""
unrecognized_scheme = ''
new_urls_by_scheme = dict(
(urlparse.urlparse(url, scheme=None).scheme, url) for url in urls)
if None in new_urls_by_scheme:
raise ValueError('URL %r is not absolute' % new_urls_by_scheme[None])
(urlparse.urlparse(url, scheme=unrecognized_scheme).scheme, url) for url in urls)

if unrecognized_scheme in new_urls_by_scheme:
raise ValueError('URL %s is not absolute' % new_urls_by_scheme[unrecognized_scheme])

for lca in distro_tree.lab_controller_assocs:
if lca.lab_controller == lab_controller:
scheme = urlparse.urlparse(lca.url).scheme
Expand Down
22 changes: 22 additions & 0 deletions Server/bkr/server/tests/test_distrotrees.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright Contributors to the Beaker project.
# SPDX-License-Identifier: GPL-2.0-or-later

import unittest

from bkr.server.distrotrees import DistroTrees


class CheckDistroTreeImportUnitTest(unittest.TestCase):

def test_undefined_schema_in_url(self):
t_url = [
"https://example.com/RHEL11-Server/x86_64/os",
"example.com/RHEL11-Server/x86_64/ppc64",
"example.com/RHEL11-Server/x86_64/aarch64"
]
t_distro_tree, t_lab_controller = None, None

with self.assertRaises(ValueError) as context:
DistroTrees.add_distro_urls(t_distro_tree, t_lab_controller, t_url)

self.assertTrue('URL {} is not absolute'.format(t_url[2]) in context.exception)

0 comments on commit 3b14e3e

Please sign in to comment.