Skip to content

Commit 6c61567

Browse files
committed
fix: new unit test for custom and empty tls configuration
1 parent 85c8656 commit 6c61567

2 files changed

Lines changed: 55 additions & 3 deletions

File tree

lib/resourcebuilder/core.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,12 @@ func updateRNodeWithTLSSettings(rnode *yaml.RNode, minTLSVersion string, minTLSF
158158
return err
159159
}
160160

161-
if ciphersFound && len(cipherSuites) > 0 {
161+
if ciphersFound {
162162
currentCiphers, err := getSortedCipherSuites(servingInfo)
163-
if err != nil || !slices.Equal(currentCiphers, cipherSuites) {
163+
if err != nil {
164+
return err
165+
}
166+
if !slices.Equal(currentCiphers, cipherSuites) {
164167
// Create a sequence node with the cipher suites
165168
seqNode := yaml.NewListRNode(cipherSuites...)
166169
if err := servingInfo.PipeE(yaml.SetField("cipherSuites", seqNode)); err != nil {
@@ -170,7 +173,7 @@ func updateRNodeWithTLSSettings(rnode *yaml.RNode, minTLSVersion string, minTLSF
170173
}
171174

172175
// Update minTLSVersion if found
173-
if minTLSFound && minTLSVersion != "" {
176+
if minTLSFound {
174177
if err := servingInfo.PipeE(yaml.SetField("minTLSVersion", yaml.NewStringRNode(minTLSVersion))); err != nil {
175178
return err
176179
}

lib/resourcebuilder/core_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,55 @@ servingInfo:
527527
}
528528
},
529529
},
530+
{
531+
name: "ConfigMap with APIServer custom profile with empty ciphers and minTLSVersion - update to empty values",
532+
configMap: makeConfigMap(true, map[string]string{
533+
genericOperatorConfigCMKey: makeGenericOperatorConfigYAML(testCipherSuites, tlsVersion12),
534+
}),
535+
apiServer: makeAPIServerConfig(withCustomTLSProfile([]string{}, "")),
536+
expectError: false,
537+
validateConfigMap: func(t *testing.T, original, modified *corev1.ConfigMap) {
538+
// When Custom profile has empty ciphers/minTLSVersion, it should fall back to default Intermediate profile
539+
defaultTLSConfigMap := makeConfigMap(true, map[string]string{
540+
genericOperatorConfigCMKey: makeGenericOperatorConfigYAML([]string{}, ""),
541+
})
542+
if err := validateConfigMapsEqual(defaultTLSConfigMap, modified); err != nil {
543+
t.Fatalf("validation failed: %v", err)
544+
}
545+
},
546+
},
547+
{
548+
name: "ConfigMap with APIServer custom profile with non-empty ciphers and empty minTLSVersion - update minTLSVersion to an empty value",
549+
configMap: makeConfigMap(true, map[string]string{
550+
genericOperatorConfigCMKey: makeGenericOperatorConfigYAML(testCipherSuites, tlsVersion12),
551+
}),
552+
apiServer: makeAPIServerConfig(withCustomTLSProfile(testOpenSSLCipherSuites2, "")),
553+
expectError: false,
554+
validateConfigMap: func(t *testing.T, original, modified *corev1.ConfigMap) {
555+
expectedConfigMap := makeConfigMap(true, map[string]string{
556+
genericOperatorConfigCMKey: makeGenericOperatorConfigYAML(testCipherSuites2, ""),
557+
})
558+
if err := validateConfigMapsEqual(expectedConfigMap, modified); err != nil {
559+
t.Fatalf("validation failed: %v", err)
560+
}
561+
},
562+
},
563+
{
564+
name: "ConfigMap with APIServer custom profile with empty ciphers and non-empty minTLSVersion - update ciphers to an empty value",
565+
configMap: makeConfigMap(true, map[string]string{
566+
genericOperatorConfigCMKey: makeGenericOperatorConfigYAML(testCipherSuites, tlsVersion12),
567+
}),
568+
apiServer: makeAPIServerConfig(withCustomTLSProfile([]string{}, tlsVersion12)),
569+
expectError: false,
570+
validateConfigMap: func(t *testing.T, original, modified *corev1.ConfigMap) {
571+
expectedConfigMap := makeConfigMap(true, map[string]string{
572+
genericOperatorConfigCMKey: makeGenericOperatorConfigYAML([]string{}, tlsVersion12),
573+
})
574+
if err := validateConfigMapsEqual(expectedConfigMap, modified); err != nil {
575+
t.Fatalf("validation failed: %v", err)
576+
}
577+
},
578+
},
530579
}
531580

532581
for _, tt := range tests {

0 commit comments

Comments
 (0)