Skip to content

Commit 4a42159

Browse files
committed
fix(cozy-lib): add kindIs slice guard for usages parameter
Address review feedback from lexfrei on _tls.tpl: Add type guard for usages to match dnsNames/extraDnsNames pattern, producing an actionable error instead of Helm's generic range error. Signed-off-by: Arsolitt <[email protected]>
1 parent 6b633b1 commit 4a42159

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎packages/library/cozy-lib/templates/_tls.tpl‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ Parameters:
4747
{{- if and .extraDnsNames (not (kindIs "slice" .extraDnsNames)) -}}
4848
{{- fail "ERROR: \"extraDnsNames\" must be a list for cozy-lib.tls.certificate. Got a string — wrap it in a list." -}}
4949
{{- end -}}
50+
{{- if and .usages (not (kindIs "slice" .usages)) -}}
51+
{{- fail "ERROR: \"usages\" must be a list for cozy-lib.tls.certificate. Got a string — wrap it in a list." -}}
52+
{{- end -}}
5053
{{- if not .issuerRef -}}
5154
{{- fail "ERROR: \"issuerRef\" is required for cozy-lib.tls.certificate. Provide a dict with \"name\" and \"kind\"." -}}
5255
{{- end -}}

‎packages/tests/cozy-lib-tests/tests/tls_test.yaml‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,23 @@ tests:
498498
asserts:
499499
- failedTemplate:
500500
errorMessage: 'ERROR: "extraDnsNames" must be a list for cozy-lib.tls.certificate. Got a string — wrap it in a list.'
501+
502+
# String usages triggers a type error
503+
- it: errors when usages is a string instead of a list
504+
release:
505+
name: test-release
506+
namespace: tenant-test
507+
set:
508+
_cluster: {}
509+
_namespace: {}
510+
tls:
511+
name: string-usages-tls
512+
dnsNames:
513+
- svc.example
514+
issuerRef:
515+
name: selfsigned-cluster-issuer
516+
kind: ClusterIssuer
517+
usages: server auth
518+
asserts:
519+
- failedTemplate:
520+
errorMessage: 'ERROR: "usages" must be a list for cozy-lib.tls.certificate. Got a string — wrap it in a list.'

0 commit comments

Comments
 (0)