@@ -504,3 +504,103 @@ func TestSyncWebhookConfiguration(t *testing.T) {
504504 })
505505 }
506506}
507+
508+ func TestNewKubeProxyContainer (t * testing.T ) {
509+ testCases := []struct {
510+ name string
511+ image string
512+ portName string
513+ upstreamPort string
514+ exposePort int32
515+ tlsProfile configv1.TLSProfileSpec
516+ expectedCipherSuitesInArgs bool
517+ }{
518+ {
519+ name : "TLS 1.2 Intermediate profile with cipher suites" ,
520+ image : "test-image:latest" ,
521+ portName : "test-mtrc" ,
522+ upstreamPort : ":8080" ,
523+ exposePort : 8443 ,
524+ tlsProfile : configv1.TLSProfileSpec {
525+ Ciphers : []string {
526+ "TLS_AES_128_GCM_SHA256" ,
527+ "TLS_AES_256_GCM_SHA384" ,
528+ "TLS_CHACHA20_POLY1305_SHA256" ,
529+ "ECDHE-ECDSA-AES128-GCM-SHA256" ,
530+ "ECDHE-RSA-AES128-GCM-SHA256" ,
531+ },
532+ MinTLSVersion : configv1 .VersionTLS12 ,
533+ },
534+ expectedCipherSuitesInArgs : true ,
535+ },
536+ {
537+ name : "TLS 1.3 Modern profile without cipher suites" ,
538+ image : "test-image:latest" ,
539+ portName : "test-mtrc" ,
540+ upstreamPort : ":8080" ,
541+ exposePort : 8443 ,
542+ tlsProfile : configv1.TLSProfileSpec {
543+ Ciphers : []string {
544+ "TLS_AES_128_GCM_SHA256" ,
545+ "TLS_AES_256_GCM_SHA384" ,
546+ "TLS_CHACHA20_POLY1305_SHA256" ,
547+ },
548+ MinTLSVersion : configv1 .VersionTLS13 ,
549+ },
550+ expectedCipherSuitesInArgs : false ,
551+ },
552+ {
553+ name : "Empty cipher list" ,
554+ image : "test-image:latest" ,
555+ portName : "test-mtrc" ,
556+ upstreamPort : ":8080" ,
557+ exposePort : 8443 ,
558+ tlsProfile : configv1.TLSProfileSpec {
559+ Ciphers : []string {},
560+ MinTLSVersion : configv1 .VersionTLS13 ,
561+ },
562+ expectedCipherSuitesInArgs : false ,
563+ },
564+ }
565+
566+ for _ , tc := range testCases {
567+ t .Run (tc .name , func (t * testing.T ) {
568+ g := NewWithT (t )
569+
570+ container := newKubeProxyContainer (tc .image , tc .portName , tc .upstreamPort , tc .exposePort , tc .tlsProfile )
571+
572+ // Verify basic container properties
573+ g .Expect (container .Name ).To (Equal ("kube-rbac-proxy-" + tc .portName ))
574+ g .Expect (container .Image ).To (Equal (tc .image ))
575+
576+ // Verify ports
577+ g .Expect (container .Ports ).To (HaveLen (1 ))
578+ g .Expect (container .Ports [0 ].Name ).To (Equal (tc .portName ))
579+ g .Expect (container .Ports [0 ].ContainerPort ).To (Equal (tc .exposePort ))
580+
581+ // Verify resource requests
582+ g .Expect (container .Resources .Requests ).To (HaveKey (corev1 .ResourceMemory ))
583+ g .Expect (container .Resources .Requests ).To (HaveKey (corev1 .ResourceCPU ))
584+
585+ // Verify volume mounts
586+ g .Expect (container .VolumeMounts ).To (HaveLen (2 ))
587+
588+ // Verify args
589+ hasCipherSuitesArg := false
590+ hasTLSMinVersionArg := false
591+ for _ , arg := range container .Args {
592+ if len (arg ) >= len ("--tls-cipher-suites=" ) && arg [:len ("--tls-cipher-suites=" )] == "--tls-cipher-suites=" {
593+ hasCipherSuitesArg = true
594+ }
595+ if len (arg ) >= len ("--tls-min-version=" ) && arg [:len ("--tls-min-version=" )] == "--tls-min-version=" {
596+ hasTLSMinVersionArg = true
597+ g .Expect (arg ).To (ContainSubstring (string (tc .tlsProfile .MinTLSVersion )))
598+ }
599+ }
600+
601+ g .Expect (hasCipherSuitesArg ).To (Equal (tc .expectedCipherSuitesInArgs ),
602+ "cipher suites arg presence mismatch" )
603+ g .Expect (hasTLSMinVersionArg ).To (BeTrue (), "TLS min version arg should be present" )
604+ })
605+ }
606+ }
0 commit comments