Skip to content

Commit

Permalink
16721 FIX site management: Fix url validation
Browse files Browse the repository at this point in the history
This fix allows hostnames without TLD on URLs when creating a site using the site management endpoints

CMK-20952

Change-Id: Idd6fc33b031339750a9b6513079aac5d32012720
  • Loading branch information
lpetrora committed Jan 8, 2025
1 parent 5fabc35 commit 20aa599
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .werks/16721.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[//]: # (werk v2)
# site management: Fix url validation

key | value
---------- | ---
date | 2024-12-24T11:49:39+00:00
version | 2.3.0p25
class | fix
edition | cre
component | rest-api
level | 1
compatible | yes

This fix allows hostnames without TLD on URLs when creating a site using the site management endpoints

1 change: 1 addition & 0 deletions cmk/gui/fields/custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(
validator = validate.URL(
schemes=set(self.must_startwith_one),
error=self.error_messages["invalid"],
require_tld=False,
)
self.validators.insert(0, validator)

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/cmk/gui/openapi/test_site_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ def test_create_then_get_site_connection(clients: ClientRegistry) -> None:
assert resp.json["extensions"] == config


def test_create_site_connection_url_without_tld(clients: ClientRegistry) -> None:
config, site_id = _default_config_with_site_id()
url = "http://myhost:7323/myhost/check_mk/"

config["configuration_connection"]["url_of_remote_site"] = url
clients.SiteManagement.create(site_config=config)
resp = clients.SiteManagement.get(site_id=site_id)
assert resp.json["extensions"] == config


def test_update_site_connection(clients: ClientRegistry) -> None:
config, site_id = _default_config_with_site_id()
clients.SiteManagement.create(site_config=config)
Expand Down

0 comments on commit 20aa599

Please sign in to comment.