From e88cea2b6c089442798383566c23a949638ec08a Mon Sep 17 00:00:00 2001 From: jo Date: Fri, 16 Jun 2023 13:31:59 +0200 Subject: [PATCH] fix: adjust label validation for max length of 63 characters https://github.com/hetznercloud/hcloud-go/pull/273 --- hcloud/helpers/labels.py | 4 ++-- tests/unit/helpers/test_labels.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/hcloud/helpers/labels.py b/hcloud/helpers/labels.py index eb7527dd..c9f45a97 100644 --- a/hcloud/helpers/labels.py +++ b/hcloud/helpers/labels.py @@ -4,10 +4,10 @@ class LabelValidator: KEY_REGEX = re.compile( - "^([a-z0-9A-Z]((?:[\-_.]|[a-z0-9A-Z]){0,253}[a-z0-9A-Z])?/)?[a-z0-9A-Z]((?:[\-_.]|[a-z0-9A-Z]|){0,62}[a-z0-9A-Z])?$" + "^([a-z0-9A-Z]((?:[\-_.]|[a-z0-9A-Z]){0,253}[a-z0-9A-Z])?/)?[a-z0-9A-Z]((?:[\-_.]|[a-z0-9A-Z]|){0,61}[a-z0-9A-Z])?$" ) VALUE_REGEX = re.compile( - "^(([a-z0-9A-Z](?:[\-_.]|[a-z0-9A-Z]){0,62})?[a-z0-9A-Z]$|$)" + "^(([a-z0-9A-Z](?:[\-_.]|[a-z0-9A-Z]){0,61})?[a-z0-9A-Z]$|$)" ) @staticmethod diff --git a/tests/unit/helpers/test_labels.py b/tests/unit/helpers/test_labels.py index 927564cf..013394c1 100644 --- a/tests/unit/helpers/test_labels.py +++ b/tests/unit/helpers/test_labels.py @@ -22,6 +22,12 @@ }, False, ), + ( + { + "valid_key": "63-characters-are-allowed-in-a-label__this-is-one-character-more", + }, + False, + ), # invalid keys ({"incorrect.de/": "correct.de"}, False), ({"incor rect.de/": "correct.de"}, False), @@ -75,6 +81,13 @@ def test_validate(labels, expected): False, "value", ), + ( + { + "valid_key": "63-characters-are-allowed-in-a-label__this-is-one-character-more", + }, + False, + "value", + ), # invalid keys ({"incorrect.de/": "correct.de"}, False, "key"), ({"incor rect.de/": "correct.de"}, False, "key"),