Skip to content

Commit 95acb29

Browse files
committed
feat: add validation for release and deployment names
- Add pattern validation for release names: - Must be lowercase alphanumeric with hyphens - Must start and end with alphanumeric - Max length of 53 characters - Add pattern validation for deployment names: - Must be lowercase alphanumeric with hyphens - Must start and end with alphanumeric - Add comprehensive test cases for both validations
1 parent f80f081 commit 95acb29

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

helm_values_manager/schemas/v1.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010
},
1111
"release": {
1212
"type": "string",
13+
"pattern": "^[a-z0-9][a-z0-9-]*[a-z0-9]$",
14+
"maxLength": 53,
1315
"description": "Name of the Helm release"
1416
},
1517
"deployments": {
1618
"type": "object",
1719
"description": "Map of deployment names to their configurations",
20+
"propertyNames": {
21+
"pattern": "^[a-z0-9][a-z0-9-]*[a-z0-9]$",
22+
"description": "Deployment names must be lowercase alphanumeric with hyphens, cannot start/end with hyphen"
23+
},
1824
"additionalProperties": {
1925
"type": "object",
2026
"required": ["backend", "auth"],

tests/unit/models/test_helm_values_config.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,74 @@ def test_validate_without_release():
194194
config = HelmValuesConfig()
195195
with pytest.raises(ValueError, match="Release name is required"):
196196
config.validate()
197+
198+
199+
def test_release_name_validation():
200+
"""
201+
Test that release names are properly validated.
202+
203+
Release names must match the following pattern: ^[a-z0-9-]{1,53}$.
204+
"""
205+
# Valid cases
206+
valid_names = [
207+
"my-release",
208+
"release123",
209+
"a-b-c-123",
210+
"a" * 53, # max length
211+
]
212+
for name in valid_names:
213+
config = {"version": "1.0", "release": name, "deployments": {}, "config": []}
214+
HelmValuesConfig._validate_schema(config) # Should not raise
215+
216+
# Invalid cases
217+
invalid_names = [
218+
"UPPERCASE", # uppercase not allowed
219+
"my_release", # underscore not allowed
220+
"my.release", # dot not allowed
221+
"-starts-with-hyphen", # cannot start with hyphen
222+
"ends-with-hyphen-", # cannot end with hyphen
223+
"a" * 54, # too long
224+
"", # empty string
225+
]
226+
for name in invalid_names:
227+
config = {"version": "1.0", "release": name, "deployments": {}, "config": []}
228+
with pytest.raises(jsonschema.exceptions.ValidationError):
229+
HelmValuesConfig._validate_schema(config)
230+
231+
232+
def test_deployment_name_validation():
233+
"""
234+
Test that deployment names are properly validated.
235+
236+
Deployment names must match the following pattern: ^[a-z0-9-]{1,53}$.
237+
"""
238+
# Valid cases
239+
valid_config = {
240+
"version": "1.0",
241+
"release": "test-release",
242+
"deployments": {
243+
"my-deployment": {"backend": "no-backend", "auth": {"type": "no-auth"}},
244+
"deployment123": {"backend": "no-backend", "auth": {"type": "no-auth"}},
245+
"a-b-c-123": {"backend": "no-backend", "auth": {"type": "no-auth"}},
246+
},
247+
"config": [],
248+
}
249+
HelmValuesConfig._validate_schema(valid_config) # Should not raise
250+
251+
# Invalid cases - test one by one to ensure proper validation
252+
base_config = {"version": "1.0", "release": "test-release", "deployments": {}, "config": []}
253+
254+
invalid_names = [
255+
"UPPERCASE", # uppercase not allowed
256+
"my_deployment", # underscore not allowed
257+
"my.deployment", # dot not allowed
258+
"-starts-with-hyphen", # cannot start with hyphen
259+
"ends-with-hyphen-", # cannot end with hyphen
260+
"", # empty string
261+
]
262+
263+
for name in invalid_names:
264+
config = dict(base_config)
265+
config["deployments"] = {name: {"backend": "no-backend", "auth": {"type": "no-auth"}}}
266+
with pytest.raises(jsonschema.exceptions.ValidationError):
267+
HelmValuesConfig._validate_schema(config)

0 commit comments

Comments
 (0)