@@ -20,6 +20,7 @@ package tlscommon
2020import (
2121 "testing"
2222
23+ "github.com/elastic/go-ucfg"
2324 "github.com/stretchr/testify/require"
2425 "gopkg.in/yaml.v2"
2526)
@@ -92,3 +93,83 @@ func Test_ServerConfig_Serialization_ClientAuth(t *testing.T) {
9293 })
9394 }
9495}
96+
97+ func Test_ServerConfig_Repack (t * testing.T ) {
98+ tests := []struct {
99+ name string
100+ yaml string
101+ auth * TLSClientAuth
102+ }{{
103+ name : "with client auth" ,
104+ yaml : `
105+ enabled: true
106+ verification_mode: certificate
107+ supported_protocols: [TLSv1.1, TLSv1.2]
108+ cipher_suites:
109+ - RSA-AES-256-CBC-SHA
110+ certificate_authorities:
111+ - /path/to/ca.crt
112+ certificate: /path/to/cert.cry
113+ key: /path/to/key/crt
114+ curve_types:
115+ - P-521
116+ client_authentication: optional
117+ ca_sha256:
118+ - example` ,
119+ auth : & optional ,
120+ }, {
121+ name : "nil client auth" ,
122+ yaml : `
123+ enabled: true
124+ verification_mode: certificate
125+ supported_protocols: [TLSv1.1, TLSv1.2]
126+ cipher_suites:
127+ - RSA-AES-256-CBC-SHA
128+ certificate_authorities:
129+ - /path/to/ca.crt
130+ certificate: /path/to/cert.cry
131+ key: /path/to/key/crt
132+ curve_types:
133+ - P-521
134+ ca_sha256:
135+ - example` ,
136+ auth : & required ,
137+ }, {
138+ name : "nil client auth, no cas" ,
139+ yaml : `
140+ enabled: true
141+ verification_mode: certificate
142+ supported_protocols: [TLSv1.1, TLSv1.2]
143+ cipher_suites:
144+ - RSA-AES-256-CBC-SHA
145+ certificate: /path/to/cert.cry
146+ key: /path/to/key/crt
147+ curve_types:
148+ - P-521
149+ ca_sha256:
150+ - example` ,
151+ auth : nil ,
152+ }}
153+
154+ for _ , tc := range tests {
155+ t .Run (tc .name , func (t * testing.T ) {
156+ cfg := mustLoadServerConfig (t , tc .yaml )
157+ if tc .auth != nil {
158+ require .Equal (t , * tc .auth , * cfg .ClientAuth )
159+ } else {
160+ require .Nil (t , cfg .ClientAuth )
161+ }
162+
163+ tmp , err := ucfg .NewFrom (cfg )
164+ require .NoError (t , err )
165+
166+ err = tmp .Unpack (& cfg )
167+ require .NoError (t , err )
168+ if tc .auth != nil {
169+ require .Equal (t , * tc .auth , * cfg .ClientAuth )
170+ } else {
171+ require .Nil (t , cfg .ClientAuth )
172+ }
173+ })
174+ }
175+ }
0 commit comments