@@ -31,6 +31,7 @@ import (
3131)
3232
3333var  _  =  Describe ("Server" , func () {
34+ 
3435	It ("Should respond to /health" , func () {
3536		ctx  :=  context .TODO ()
3637		client , err  :=  startServer (ctx , common .ModeRandom )
@@ -116,4 +117,95 @@ var _ = Describe("Server", func() {
116117			Expect (tokenizeResp .MaxModelLen ).To (Equal (2048 ))
117118		})
118119	})
120+ 
121+ 	Context ("SSL/HTTPS Configuration" , func () {
122+ 		It ("Should parse SSL certificate configuration correctly" , func () {
123+ 			tempDir  :=  GinkgoT ().TempDir ()
124+ 			certFile , keyFile , err  :=  GenerateTempCerts (tempDir )
125+ 			Expect (err ).NotTo (HaveOccurred ())
126+ 
127+ 			oldArgs  :=  os .Args 
128+ 			defer  func () {
129+ 				os .Args  =  oldArgs 
130+ 			}()
131+ 
132+ 			os .Args  =  []string {"cmd" , "--model" , model , "--ssl-certfile" , certFile , "--ssl-keyfile" , keyFile }
133+ 			config , err  :=  common .ParseCommandParamsAndLoadConfig ()
134+ 			Expect (err ).NotTo (HaveOccurred ())
135+ 			Expect (config .SSLEnabled ()).To (BeTrue ())
136+ 			Expect (config .SSLCertFile ).To (Equal (certFile ))
137+ 			Expect (config .SSLKeyFile ).To (Equal (keyFile ))
138+ 		})
139+ 
140+ 		It ("Should parse self-signed certificate configuration correctly" , func () {
141+ 			oldArgs  :=  os .Args 
142+ 			defer  func () {
143+ 				os .Args  =  oldArgs 
144+ 			}()
145+ 
146+ 			os .Args  =  []string {"cmd" , "--model" , model , "--self-signed-certs" }
147+ 			config , err  :=  common .ParseCommandParamsAndLoadConfig ()
148+ 			Expect (err ).NotTo (HaveOccurred ())
149+ 			Expect (config .SSLEnabled ()).To (BeTrue ())
150+ 			Expect (config .SelfSignedCerts ).To (BeTrue ())
151+ 		})
152+ 
153+ 		It ("Should create self-signed TLS certificate successfully" , func () {
154+ 			cert , err  :=  CreateSelfSignedTLSCertificate ()
155+ 			Expect (err ).NotTo (HaveOccurred ())
156+ 			Expect (cert .Certificate ).To (HaveLen (1 ))
157+ 			Expect (cert .PrivateKey ).NotTo (BeNil ())
158+ 		})
159+ 
160+ 		It ("Should validate SSL configuration - both cert and key required" , func () {
161+ 			tempDir  :=  GinkgoT ().TempDir ()
162+ 
163+ 			oldArgs  :=  os .Args 
164+ 			defer  func () {
165+ 				os .Args  =  oldArgs 
166+ 			}()
167+ 
168+ 			certFile , _ , err  :=  GenerateTempCerts (tempDir )
169+ 			Expect (err ).NotTo (HaveOccurred ())
170+ 
171+ 			os .Args  =  []string {"cmd" , "--model" , model , "--ssl-certfile" , certFile }
172+ 			_ , err  =  common .ParseCommandParamsAndLoadConfig ()
173+ 			Expect (err ).To (HaveOccurred ())
174+ 			Expect (err .Error ()).To (ContainSubstring ("both ssl-certfile and ssl-keyfile must be provided together" ))
175+ 
176+ 			_ , keyFile , err  :=  GenerateTempCerts (tempDir )
177+ 			Expect (err ).NotTo (HaveOccurred ())
178+ 
179+ 			os .Args  =  []string {"cmd" , "--model" , model , "--ssl-keyfile" , keyFile }
180+ 			_ , err  =  common .ParseCommandParamsAndLoadConfig ()
181+ 			Expect (err ).To (HaveOccurred ())
182+ 			Expect (err .Error ()).To (ContainSubstring ("both ssl-certfile and ssl-keyfile must be provided together" ))
183+ 		})
184+ 
185+ 		It ("Should start HTTPS server with provided SSL certificates" , func (ctx  SpecContext ) {
186+ 			tempDir  :=  GinkgoT ().TempDir ()
187+ 			certFile , keyFile , err  :=  GenerateTempCerts (tempDir )
188+ 			Expect (err ).NotTo (HaveOccurred ())
189+ 
190+ 			args  :=  []string {"cmd" , "--model" , model , "--mode" , common .ModeRandom ,
191+ 				"--ssl-certfile" , certFile , "--ssl-keyfile" , keyFile }
192+ 			client , err  :=  startServerWithArgs (ctx , common .ModeRandom , args , nil )
193+ 			Expect (err ).NotTo (HaveOccurred ())
194+ 
195+ 			resp , err  :=  client .Get ("https://localhost/health" )
196+ 			Expect (err ).NotTo (HaveOccurred ())
197+ 			Expect (resp .StatusCode ).To (Equal (http .StatusOK ))
198+ 		})
199+ 
200+ 		It ("Should start HTTPS server with self-signed certificates" , func (ctx  SpecContext ) {
201+ 			args  :=  []string {"cmd" , "--model" , model , "--mode" , common .ModeRandom , "--self-signed-certs" }
202+ 			client , err  :=  startServerWithArgs (ctx , common .ModeRandom , args , nil )
203+ 			Expect (err ).NotTo (HaveOccurred ())
204+ 
205+ 			resp , err  :=  client .Get ("https://localhost/health" )
206+ 			Expect (err ).NotTo (HaveOccurred ())
207+ 			Expect (resp .StatusCode ).To (Equal (http .StatusOK ))
208+ 		})
209+ 
210+ 	})
119211})
0 commit comments