@@ -134,9 +134,9 @@ func TestBoundaryIntegration(t *testing.T) {
134134 })
135135
136136 // Test blocked domain (from inside the jail)
137- t .Run ("BlockedDomainTest " , func (t * testing.T ) {
137+ t .Run ("HTTPBlockedDomainTest " , func (t * testing.T ) {
138138 // Run curl directly in the namespace using ip netns exec
139- curlCmd := exec .Command ("sudo" , "sudo" , " nsenter" , "-t" , pid , "-n" , "--" ,
139+ curlCmd := exec .Command ("sudo" , "nsenter" , "-t" , pid , "-n" , "--" ,
140140 "curl" , "-s" , "http://example.com" )
141141
142142 // Capture stderr separately
@@ -150,6 +150,101 @@ func TestBoundaryIntegration(t *testing.T) {
150150 require .Contains (t , string (output ), "Request Blocked by Boundary" )
151151 })
152152
153+ // Test blocked domain (from inside the jail)
154+ t .Run ("HTTPSBlockedDomainTest" , func (t * testing.T ) {
155+ _ , _ , _ , _ , configDir := util .GetUserInfo ()
156+ certPath := fmt .Sprintf ("%v/ca-cert.pem" , configDir )
157+
158+ // Run curl directly in the namespace using ip netns exec
159+ curlCmd := exec .Command ("sudo" , "nsenter" , "-t" , pid , "-n" , "--" ,
160+ "env" , fmt .Sprintf ("SSL_CERT_FILE=%v" , certPath ), "curl" , "-s" , "https://example.com" )
161+
162+ // Capture stderr separately
163+ var stderr bytes.Buffer
164+ curlCmd .Stderr = & stderr
165+ output , err := curlCmd .Output ()
166+
167+ if err != nil {
168+ t .Fatalf ("curl command failed: %v, stderr: %s, output: %s" , err , stderr .String (), string (output ))
169+ }
170+ require .Contains (t , string (output ), "Request Blocked by Boundary" )
171+ })
172+
173+ // Gracefully close process, call cleanup methods
174+ err = boundaryCmd .Process .Signal (os .Interrupt )
175+ require .NoError (t , err , "Failed to interrupt boundary process" )
176+ time .Sleep (time .Second * 1 )
177+
178+ // Clean up
179+ cancel () // This will terminate the boundary process
180+ err = boundaryCmd .Wait () // Wait for process to finish
181+ if err != nil {
182+ t .Logf ("Boundary process finished with error: %v" , err )
183+ }
184+
185+ // Clean up binary
186+ err = os .Remove ("/tmp/boundary-test" )
187+ require .NoError (t , err , "Failed to remove /tmp/boundary-test" )
188+ }
189+
190+ func TestBoundaryIntegration2 (t * testing.T ) {
191+ // Find project root by looking for go.mod file
192+ projectRoot := findProjectRoot (t )
193+
194+ // Build the boundary binary
195+ buildCmd := exec .Command ("go" , "build" , "-o" , "/tmp/boundary-test" , "./cmd/..." )
196+ buildCmd .Dir = projectRoot
197+ err := buildCmd .Run ()
198+ require .NoError (t , err , "Failed to build boundary binary" )
199+
200+ // Create context for boundary process
201+ ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
202+ defer cancel ()
203+
204+ // Start boundary process with sudo
205+ boundaryCmd := exec .CommandContext (ctx , "/tmp/boundary-test" ,
206+ "--allow" , "example.com" ,
207+ "--log-level" , "debug" ,
208+ "--" , "/bin/bash" , "-c" , "/usr/bin/sleep 10 && /usr/bin/echo 'Test completed'" )
209+
210+ boundaryCmd .Stdin = os .Stdin
211+ boundaryCmd .Stdout = os .Stdout
212+ boundaryCmd .Stderr = os .Stderr
213+
214+ // Start the process
215+ err = boundaryCmd .Start ()
216+ require .NoError (t , err , "Failed to start boundary process" )
217+
218+ // Give boundary time to start
219+ time .Sleep (2 * time .Second )
220+
221+ pidInt := getChildProcessPID (t )
222+ pid := fmt .Sprintf ("%v" , pidInt )
223+
224+ // Test HTTPS request through boundary (from inside the jail)
225+ t .Run ("HTTPSRequestThroughBoundary" , func (t * testing.T ) {
226+ _ , _ , _ , _ , configDir := util .GetUserInfo ()
227+ certPath := fmt .Sprintf ("%v/ca-cert.pem" , configDir )
228+
229+ // Run curl directly in the namespace using ip netns exec
230+ curlCmd := exec .Command ("sudo" , "nsenter" , "-t" , pid , "-n" , "--" ,
231+ "env" , fmt .Sprintf ("SSL_CERT_FILE=%v" , certPath ), "curl" , "-s" , "https://example.com" )
232+
233+ // Capture stderr separately
234+ var stderr bytes.Buffer
235+ curlCmd .Stderr = & stderr
236+ output , err := curlCmd .Output ()
237+
238+ if err != nil {
239+ t .Fatalf ("curl command failed: %v, stderr: %s, output: %s" , err , stderr .String (), string (output ))
240+ }
241+
242+ // Verify response contains expected content
243+ expectedResponse := `<!doctype html><html lang="en"><head><title>Example Domain</title><meta name="viewport" content="width=device-width, initial-scale=1"><style>body{background:#eee;width:60vw;margin:15vh auto;font-family:system-ui,sans-serif}h1{font-size:1.5em}div{opacity:0.8}a:link,a:visited{color:#348}</style><body><div><h1>Example Domain</h1><p>This domain is for use in documentation examples without needing permission. Avoid use in operations.<p><a href="https://iana.org/domains/example">Learn more</a></div></body></html>
244+ `
245+ require .Equal (t , expectedResponse , string (output ))
246+ })
247+
153248 // Gracefully close process, call cleanup methods
154249 err = boundaryCmd .Process .Signal (os .Interrupt )
155250 require .NoError (t , err , "Failed to interrupt boundary process" )
0 commit comments