@@ -291,4 +291,80 @@ var _ = Describe("NewTLSConfigFromProfile", func() {
291291 Expect (tlsConf .CipherSuites ).To (BeNil ())
292292 })
293293 })
294+
295+ Context ("when profile contains Groups" , func () {
296+ It ("should set CurvePreferences for supported groups" , func () {
297+ profile := configv1.TLSProfileSpec {
298+ MinTLSVersion : configv1 .VersionTLS12 ,
299+ Groups : []configv1.TLSGroup {
300+ configv1 .TLSGroupX25519 ,
301+ configv1 .TLSGroupSecP256r1 ,
302+ },
303+ }
304+
305+ tlsConfigFn , unsupported := NewTLSConfigFromProfile (profile )
306+ Expect (unsupported ).To (BeEmpty ())
307+
308+ tlsConf := & tls.Config {}
309+ tlsConfigFn (tlsConf )
310+
311+ Expect (tlsConf .CurvePreferences ).To (HaveLen (2 ))
312+ Expect (tlsConf .CurvePreferences ).To (ContainElement (tls .X25519 ))
313+ Expect (tlsConf .CurvePreferences ).To (ContainElement (tls .CurveP256 ))
314+ })
315+ })
316+
317+ Context ("when profile contains unsupported Groups" , func () {
318+ It ("should return unsupported groups and set only supported curves" , func () {
319+ profile := configv1.TLSProfileSpec {
320+ MinTLSVersion : configv1 .VersionTLS12 ,
321+ Groups : []configv1.TLSGroup {
322+ configv1 .TLSGroupX25519 ,
323+ configv1 .TLSGroup ("unsupported_group" ),
324+ },
325+ }
326+
327+ tlsConfigFn , unsupported := NewTLSConfigFromProfile (profile )
328+ Expect (unsupported ).To (ConsistOf ("unsupported_group" ))
329+
330+ tlsConf := & tls.Config {}
331+ tlsConfigFn (tlsConf )
332+
333+ Expect (tlsConf .CurvePreferences ).To (HaveLen (1 ))
334+ Expect (tlsConf .CurvePreferences ).To (ContainElement (tls .X25519 ))
335+ })
336+ })
337+
338+ Context ("when profile has empty Groups" , func () {
339+ It ("should not set CurvePreferences" , func () {
340+ profile := configv1.TLSProfileSpec {
341+ MinTLSVersion : configv1 .VersionTLS12 ,
342+ Groups : []configv1.TLSGroup {},
343+ }
344+
345+ tlsConfigFn , unsupported := NewTLSConfigFromProfile (profile )
346+ Expect (unsupported ).To (BeEmpty ())
347+
348+ tlsConf := & tls.Config {}
349+ tlsConfigFn (tlsConf )
350+
351+ Expect (tlsConf .CurvePreferences ).To (BeNil ())
352+ })
353+ })
354+
355+ Context ("when using Intermediate profile with Groups" , func () {
356+ It ("should set CurvePreferences from the profile" , func () {
357+ profile := * configv1 .TLSProfiles [configv1 .TLSProfileIntermediateType ]
358+
359+ tlsConfigFn , _ := NewTLSConfigFromProfile (profile )
360+
361+ tlsConf := & tls.Config {}
362+ tlsConfigFn (tlsConf )
363+
364+ // Intermediate profile now includes Groups
365+ if len (profile .Groups ) > 0 {
366+ Expect (tlsConf .CurvePreferences ).NotTo (BeNil ())
367+ }
368+ })
369+ })
294370})
0 commit comments