From 8ada027af8bc2dcdd0e506a52cba5ac60cb7f3b7 Mon Sep 17 00:00:00 2001 From: "Christian R. Garcia" Date: Wed, 27 Nov 2024 07:02:56 -0800 Subject: [PATCH] Updating regex and improved debug --- service/models_pods.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/service/models_pods.py b/service/models_pods.py index c7a6308..5d17a6b 100644 --- a/service/models_pods.py +++ b/service/models_pods.py @@ -108,7 +108,7 @@ def check_url(cls, v): # Regex match to ensure url is safe with only [A-z0-9.-] chars. res = re.fullmatch(r'[a-z][a-z0-9.-]+', v) if not res: - raise ValueError(f"networking.url can only contain lowercase alphanumeric characters, periods, and hyphens.") + raise ValueError(f"networking.url can only contain lowercase alphanumeric characters, periods, and hyphens. Got {v}") # pod_id char limit = 64 if len(v) > 128: raise ValueError(f"networking.*.url length must be below 128 characters. Inputted length: {len(v)}") @@ -131,12 +131,14 @@ def check_tapis_auth_forward_cookies(cls, v): @validator('tapis_auth_return_path') def check_tapis_auth_return_path(cls, v): if v: + if not v.startswith('/'): + raise ValueError(f"networking.tapis_auth_return_path should start with '/'. Got {v}") # Regex match to ensure url is safe with only [A-z0-9.-/] chars. - res = re.fullmatch(r'[a-z][a-z0-9.-/]+', v) + res = re.fullmatch(r'^\/[A-Za-z][a-z0-9.\-_\/]+', v) if not res: - raise ValueError(f"networking.tapis_auth_return_path can only contain lowercase alphanumeric characters, periods, forward-slash, and hyphens.") + raise ValueError(f"networking.tapis_auth_return_path should start with '/' and can contain alphanumeric characters, periods, forward-slash, underscores, and hyphens. Got {v}") if len(v) > 180: - raise ValueError(f"networking.tapis_auth_return_path length must be below 180 characters. Inputted length: {len(v)}") + raise ValueError(f"networking.tapis_auth_return_path length must be below 180 characters. Got length: {len(v)}") return v @validator('tapis_auth_allowed_users') @@ -155,7 +157,7 @@ def check_tapis_ui_uri(cls, v): # Regex match to ensure url is safe with only [A-z0-9.-/] chars. res = re.fullmatch(r'[a-z][a-z0-9.-/]+', v) if not res: - raise ValueError(f"networking.tapis_ui_uri can only contain lowercase alphanumeric characters, periods, forward-slash, and hyphens.") + raise ValueError(f"networking.tapis_ui_uri can only contain lowercase alphanumeric characters, periods, forward-slash, and hyphens. Got {v}") # pod_id char limit = 64 if len(v) > 128: raise ValueError(f"networking.tapis_ui_uri length must be below 128 characters. Inputted length: {len(v)}") @@ -165,7 +167,7 @@ def check_tapis_ui_uri(cls, v): def check_tapis_ui_uri_description(cls, v): # ensure tapis_ui_uri_description is all ascii if not v.isascii(): - raise ValueError(f"networking.tapis_ui_uri_description field may only contain ASCII characters.") + raise ValueError(f"networking.tapis_ui_uri_description field may only contain ASCII characters. Got {v}") # make sure tapis_ui_uri_description < 255 characters if len(v) > 255: raise ValueError(f"networking.tapis_ui_uri_description field must be less than 255 characters. Inputted length: {len(v)}") @@ -177,7 +179,7 @@ def check_tapis_auth_fields(cls, values): tapis_auth = values.get('tapis_auth') if tapis_auth and protocol != "http": - raise ValueError(f"networking.tapis_auth can only be used with protocol 'http'.") + raise ValueError(f"networking.tapis_auth can only be used with protocol 'http'. Got protocol {protocol}.") return values