Skip to content

Commit 8e61e99

Browse files
Copilotnomeguy
andcommitted
Refactor TLS tests to use helper function and eliminate duplication
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
1 parent 40b9532 commit 8e61e99

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

service/proxy_tls_test.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import (
1919
"testing"
2020
)
2121

22-
// TestTLSConfigSecurity verifies that the TLS configuration meets security requirements
23-
func TestTLSConfigSecurity(t *testing.T) {
24-
// Create a TLS config similar to what's used in Start()
25-
config := &tls.Config{
22+
// getTestTLSConfig returns the standard TLS configuration used in production
23+
// This should match the configuration in Start()
24+
func getTestTLSConfig() *tls.Config {
25+
return &tls.Config{
2626
MinVersion: tls.VersionTLS12,
2727
PreferServerCipherSuites: true,
2828
CipherSuites: []uint16{
@@ -39,6 +39,11 @@ func TestTLSConfigSecurity(t *testing.T) {
3939
tls.CurveP384,
4040
},
4141
}
42+
}
43+
44+
// TestTLSConfigSecurity verifies that the TLS configuration meets security requirements
45+
func TestTLSConfigSecurity(t *testing.T) {
46+
config := getTestTLSConfig()
4247

4348
// Test 1: Verify minimum TLS version is 1.2
4449
if config.MinVersion != tls.VersionTLS12 {
@@ -98,17 +103,7 @@ func TestTLSConfigSecurity(t *testing.T) {
98103

99104
// TestWeakCipherSuitesNotPresent specifically tests that 3DES cipher suites are not present
100105
func TestWeakCipherSuitesNotPresent(t *testing.T) {
101-
config := &tls.Config{
102-
MinVersion: tls.VersionTLS12,
103-
CipherSuites: []uint16{
104-
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
105-
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
106-
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
107-
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
108-
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
109-
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
110-
},
111-
}
106+
config := getTestTLSConfig()
112107

113108
// These are the specific weak cipher suites mentioned in the issue
114109
forbiddenCiphers := map[uint16]string{

0 commit comments

Comments
 (0)