77 "context"
88 "fmt"
99 "os"
10+ "strings"
1011 "testing"
1112
1213 "github.com/stretchr/testify/require"
@@ -17,6 +18,9 @@ import (
1718)
1819
1920func TestFromPath (t * testing.T ) {
21+ stringOfLength253 := strings .Repeat ("a" , 253 )
22+ stringOfLength254 := strings .Repeat ("a" , 254 )
23+
2024 tests := []struct {
2125 name string
2226 yaml string
@@ -26,7 +30,7 @@ func TestFromPath(t *testing.T) {
2630 }{
2731 {
2832 name : "Fully filled out" ,
29- yaml : here .Doc (`
33+ yaml : here .Docf (`
3034 ---
3135 discovery:
3236 url: https://some.discovery/url
@@ -64,6 +68,7 @@ func TestFromPath(t *testing.T) {
6468 namePrefix: kube-cert-agent-name-prefix-
6569 image: kube-cert-agent-image
6670 imagePullSecrets: [kube-cert-agent-image-pull-secret]
71+ priorityClassName: %s
6772 log:
6873 level: debug
6974 tls:
@@ -74,7 +79,7 @@ func TestFromPath(t *testing.T) {
7479 - TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305
7580 audit:
7681 logUsernamesAndGroups: enabled
77- ` ),
82+ ` , stringOfLength253 ),
7883 wantConfig : & Config {
7984 DiscoveryInfo : DiscoveryInfoSpec {
8085 URL : ptr .To ("https://some.discovery/url" ),
@@ -112,9 +117,10 @@ func TestFromPath(t *testing.T) {
112117 "myLabelKey2" : "myLabelValue2" ,
113118 },
114119 KubeCertAgentConfig : KubeCertAgentSpec {
115- NamePrefix : ptr .To ("kube-cert-agent-name-prefix-" ),
116- Image : ptr .To ("kube-cert-agent-image" ),
117- ImagePullSecrets : []string {"kube-cert-agent-image-pull-secret" },
120+ NamePrefix : ptr .To ("kube-cert-agent-name-prefix-" ),
121+ Image : ptr .To ("kube-cert-agent-image" ),
122+ ImagePullSecrets : []string {"kube-cert-agent-image-pull-secret" },
123+ PriorityClassName : stringOfLength253 ,
118124 },
119125 Log : plog.LogSpec {
120126 Level : plog .LevelDebug ,
@@ -173,6 +179,7 @@ func TestFromPath(t *testing.T) {
173179 namePrefix: kube-cert-agent-name-prefix-
174180 image: kube-cert-agent-image
175181 imagePullSecrets: [kube-cert-agent-image-pull-secret]
182+ priorityClassName: kube-cert-agent-priority-class-name
176183 log:
177184 level: all
178185 format: json
@@ -216,9 +223,10 @@ func TestFromPath(t *testing.T) {
216223 "myLabelKey2" : "myLabelValue2" ,
217224 },
218225 KubeCertAgentConfig : KubeCertAgentSpec {
219- NamePrefix : ptr .To ("kube-cert-agent-name-prefix-" ),
220- Image : ptr .To ("kube-cert-agent-image" ),
221- ImagePullSecrets : []string {"kube-cert-agent-image-pull-secret" },
226+ NamePrefix : ptr .To ("kube-cert-agent-name-prefix-" ),
227+ Image : ptr .To ("kube-cert-agent-image" ),
228+ ImagePullSecrets : []string {"kube-cert-agent-image-pull-secret" },
229+ PriorityClassName : "kube-cert-agent-priority-class-name" ,
222230 },
223231 Log : plog.LogSpec {
224232 Level : plog .LevelAll ,
@@ -703,6 +711,50 @@ func TestFromPath(t *testing.T) {
703711 ` ),
704712 wantError : "validate audit: invalid logUsernamesAndGroups format, valid choices are 'enabled', 'disabled', or empty string (equivalent to 'disabled')" ,
705713 },
714+ {
715+ name : "invalid kubeCertAgent.priorityClassName length" ,
716+ yaml : here .Docf (`
717+ ---
718+ names:
719+ servingCertificateSecret: pinniped-concierge-api-tls-serving-certificate
720+ credentialIssuer: pinniped-config
721+ apiService: pinniped-api
722+ impersonationLoadBalancerService: impersonationLoadBalancerService-value
723+ impersonationClusterIPService: impersonationClusterIPService-value
724+ impersonationTLSCertificateSecret: impersonationTLSCertificateSecret-value
725+ impersonationCACertificateSecret: impersonationCACertificateSecret-value
726+ impersonationSignerSecret: impersonationSignerSecret-value
727+ impersonationSignerSecret: impersonationSignerSecret-value
728+ agentServiceAccount: agentServiceAccount-value
729+ impersonationProxyServiceAccount: impersonationProxyServiceAccount-value
730+ impersonationProxyLegacySecret: impersonationProxyLegacySecret-value
731+ kubeCertAgent:
732+ priorityClassName: %s
733+ ` , stringOfLength254 ),
734+ wantError : "validate kubeCertAgent: invalid priorityClassName: must be no more than 253 characters" ,
735+ },
736+ {
737+ name : "invalid kubeCertAgent.priorityClassName format" ,
738+ yaml : here .Doc (`
739+ ---
740+ names:
741+ servingCertificateSecret: pinniped-concierge-api-tls-serving-certificate
742+ credentialIssuer: pinniped-config
743+ apiService: pinniped-api
744+ impersonationLoadBalancerService: impersonationLoadBalancerService-value
745+ impersonationClusterIPService: impersonationClusterIPService-value
746+ impersonationTLSCertificateSecret: impersonationTLSCertificateSecret-value
747+ impersonationCACertificateSecret: impersonationCACertificateSecret-value
748+ impersonationSignerSecret: impersonationSignerSecret-value
749+ impersonationSignerSecret: impersonationSignerSecret-value
750+ agentServiceAccount: agentServiceAccount-value
751+ impersonationProxyServiceAccount: impersonationProxyServiceAccount-value
752+ impersonationProxyLegacySecret: impersonationProxyLegacySecret-value
753+ kubeCertAgent:
754+ priorityClassName: thisIsNotAValidPriorityClassName
755+ ` ),
756+ wantError : `validate kubeCertAgent: invalid priorityClassName: a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')` ,
757+ },
706758 }
707759 for _ , test := range tests {
708760 t .Run (test .name , func (t * testing.T ) {
0 commit comments