@@ -22,6 +22,7 @@ import (
2222 . "github.com/onsi/ginkgo/v2"
2323 . "github.com/onsi/gomega"
2424 configv1 "github.com/openshift/api/config/v1"
25+ libgocrypto "github.com/openshift/library-go/pkg/crypto"
2526)
2627
2728var _ = Describe ("GetTLSProfileSpec" , func () {
@@ -379,4 +380,80 @@ var _ = Describe("NewTLSConfigFromProfile", func() {
379380 Expect (tlsConf .CipherSuites ).To (BeNil ())
380381 })
381382 })
383+
384+ Context ("when profile contains Groups" , func () {
385+ It ("should set CurvePreferences for supported groups" , func () {
386+ profile := configv1.TLSProfileSpec {
387+ MinTLSVersion : configv1 .VersionTLS12 ,
388+ Groups : []configv1.TLSGroup {
389+ configv1 .TLSGroupX25519 ,
390+ configv1 .TLSGroupSecP256r1 ,
391+ },
392+ }
393+
394+ tlsConfigFn , unsupported := NewTLSConfigFromProfile (profile )
395+ Expect (unsupported ).To (BeEmpty ())
396+
397+ tlsConf := & tls.Config {}
398+ tlsConfigFn (tlsConf )
399+
400+ Expect (tlsConf .CurvePreferences ).To (Equal ([]tls.CurveID {tls .X25519 , tls .CurveP256 }))
401+ })
402+ })
403+
404+ Context ("when profile contains unsupported Groups" , func () {
405+ It ("should return unsupported groups and set only supported curves" , func () {
406+ profile := configv1.TLSProfileSpec {
407+ MinTLSVersion : configv1 .VersionTLS12 ,
408+ Groups : []configv1.TLSGroup {
409+ configv1 .TLSGroupX25519 ,
410+ configv1 .TLSGroup ("unsupported_group" ),
411+ },
412+ }
413+
414+ tlsConfigFn , unsupported := NewTLSConfigFromProfile (profile )
415+ Expect (unsupported ).To (ConsistOf ("unsupported_group" ))
416+
417+ tlsConf := & tls.Config {}
418+ tlsConfigFn (tlsConf )
419+
420+ Expect (tlsConf .CurvePreferences ).To (HaveLen (1 ))
421+ Expect (tlsConf .CurvePreferences ).To (ContainElement (tls .X25519 ))
422+ })
423+ })
424+
425+ Context ("when profile has empty Groups" , func () {
426+ It ("should not set CurvePreferences" , func () {
427+ profile := configv1.TLSProfileSpec {
428+ MinTLSVersion : configv1 .VersionTLS12 ,
429+ Groups : []configv1.TLSGroup {},
430+ }
431+
432+ tlsConfigFn , unsupported := NewTLSConfigFromProfile (profile )
433+ Expect (unsupported ).To (BeEmpty ())
434+
435+ tlsConf := & tls.Config {}
436+ tlsConfigFn (tlsConf )
437+
438+ Expect (tlsConf .CurvePreferences ).To (BeNil ())
439+ })
440+ })
441+
442+ Context ("when using Intermediate profile with Groups" , func () {
443+ It ("should set CurvePreferences from the profile" , func () {
444+ profile := * configv1 .TLSProfiles [configv1 .TLSProfileIntermediateType ]
445+
446+ tlsConfigFn , _ := NewTLSConfigFromProfile (profile )
447+
448+ tlsConf := & tls.Config {}
449+ tlsConfigFn (tlsConf )
450+
451+ expectedCurves , _ := libgocrypto .CurveIDsForTLSGroups (profile .Groups )
452+ if len (expectedCurves ) > 0 {
453+ Expect (tlsConf .CurvePreferences ).To (Equal (expectedCurves ))
454+ } else {
455+ Expect (tlsConf .CurvePreferences ).To (BeNil ())
456+ }
457+ })
458+ })
382459})
0 commit comments