diff --git a/plugins/atshosts/_shared.py b/plugins/atshosts/_shared.py index dfdd79e..280f5d5 100644 --- a/plugins/atshosts/_shared.py +++ b/plugins/atshosts/_shared.py @@ -54,24 +54,27 @@ def is_web_url(url: str) -> bool: def only(host: str) -> Callable[[str], bool]: """The allow-list of a board that is fetched from one host name only, - which is every host so far.""" - return lambda h: h == host + which is every host so far. A host name has no case, and a slug that + names one (`Acme` of acme.recruitee.com) may be written with capitals.""" + want = host.lower() + return lambda h: h.lower() == want +#: Matched whole (`fullmatch`, so not even a trailing newline slips past `$`). #: A slug that is one URL path segment: what the hosts that put the slug in #: the path accept, and nothing that could add a path, a query or a fragment. -_SEGMENT = re.compile(r"^[A-Za-z0-9._~%-]+$") +_SEGMENT = re.compile(r"[A-Za-z0-9._~%-]+") #: A slug that is one DNS label, for the hosts that put it in the host name. -_LABEL = re.compile(r"^[A-Za-z0-9-]+$") +_LABEL = re.compile(r"[A-Za-z0-9-]+") def path_slug_ok(slug: str) -> bool: - return bool(_SEGMENT.match(slug)) and slug not in (".", "..") + return bool(_SEGMENT.fullmatch(slug)) and slug not in (".", "..") def label_slug_ok(slug: str) -> bool: - return bool(_LABEL.match(slug)) + return bool(_LABEL.fullmatch(slug)) def parse_dt(value: Any) -> datetime | None: diff --git a/plugins/atshosts/teamtailor.py b/plugins/atshosts/teamtailor.py index 490fc50..0f0481e 100644 --- a/plugins/atshosts/teamtailor.py +++ b/plugins/atshosts/teamtailor.py @@ -39,7 +39,7 @@ PAGE_SIZE = 50 #: (`127.0.0.1`, `[::1]`) or a single word never names a host the fetch could #: be pointed at; `ats._get` still refuses every host but this one, redirects #: included. -_HOST = re.compile(r"^[a-z0-9-]+(\.[a-z0-9-]+)*$") +_HOST = re.compile(r"[a-z0-9-]+(\.[a-z0-9-]+)*") #: Teamtailor's own namespace in the feed, the `tt:` of `tt:locations`. _TT = "{https://teamtailor.com/locations}" @@ -60,7 +60,7 @@ def site(slug: str) -> str: def slug_ok(slug: str) -> bool: host = site(slug) - return bool(slug.strip()) and bool(_HOST.match(host)) \ + return bool(slug) and slug == slug.strip() and bool(_HOST.fullmatch(host)) \ and not host.rsplit(".", 1)[-1].isdigit() diff --git a/tests/test_atshosts.py b/tests/test_atshosts.py index 0e2248f..8b66a84 100644 --- a/tests/test_atshosts.py +++ b/tests/test_atshosts.py @@ -117,6 +117,21 @@ def test_the_contract_check_names_each_problem() -> None: assert "RANK is not an int" in found and "KEEP_CASE is not a bool" in found +@pytest.mark.parametrize("host", ["greenhouse", "lever", "ashby", "workable", "smartrecruiters", + "recruitee", "personio", "teamtailor"]) +def test_a_slug_is_matched_whole(host: str) -> None: + assert ats.is_known_target(f"{host}:acme") + for slug in ("acme\n", "acme\r\n", " acme", "acme ", "ac me", "acme/x", "acme?x", "acme#x"): + assert not ats.is_known_target(f"{host}:{slug}"), slug + + +def test_a_slug_in_the_host_name_is_allowed_whatever_its_case() -> None: + for host, api in (("recruitee", "acme.recruitee.com"), ("personio", "acme.jobs.personio.de")): + allow = ats._allowed_host(host, "Acme") + assert allow(api) and allow(api.upper()) + assert not allow(api.replace("acme", "other")) + + # ------------------------------------------------------------ the fetch def _client(handler: Callable[[httpx.Request], httpx.Response]) -> httpx.Client: