7
7
"os"
8
8
"os/exec"
9
9
"path/filepath"
10
+ "strconv"
10
11
"strings"
11
12
"testing"
12
13
"time"
@@ -62,6 +63,21 @@ func getNamespaceName(t *testing.T) string {
62
63
return namespaces [0 ]
63
64
}
64
65
66
+ func getChildProcessPID (t * testing.T ) int {
67
+ // Option 1: Look for processes with CHILD=true
68
+ cmd := exec .Command ("pgrep" , "-f" , "CHILD=true" )
69
+ output , err := cmd .CombinedOutput ()
70
+ require .NoError (t , err , "output: %v" , output )
71
+
72
+ pidStr := strings .TrimSpace (string (output ))
73
+ pid , err := strconv .Atoi (pidStr )
74
+ require .NoError (t , err )
75
+ return pid
76
+
77
+ // Option 2: Use the boundary process's child PID
78
+ // This would require modifying boundary to expose the child PID
79
+ }
80
+
65
81
func TestBoundaryIntegration (t * testing.T ) {
66
82
// Find project root by looking for go.mod file
67
83
projectRoot := findProjectRoot (t )
@@ -81,7 +97,8 @@ func TestBoundaryIntegration(t *testing.T) {
81
97
"--allow" , "dev.coder.com" ,
82
98
"--allow" , "jsonplaceholder.typicode.com" ,
83
99
"--log-level" , "debug" ,
84
- "--" , "bash" , "-c" , "sleep 10 && echo 'Test completed'" )
100
+ "--" , "/bin/bash" )
101
+ //"--", "/bin/bash", "-c", "/usr/bin/sleep 10 && /usr/bin/echo 'Test completed'")
85
102
86
103
// Suppress output to prevent terminal corruption
87
104
boundaryCmd .Stdout = os .Stdout // Let it go to /dev/null
@@ -92,15 +109,18 @@ func TestBoundaryIntegration(t *testing.T) {
92
109
require .NoError (t , err , "Failed to start boundary process" )
93
110
94
111
// Give boundary time to start
95
- time .Sleep (2 * time .Second )
112
+ time .Sleep (200 * time .Second )
96
113
97
114
// Get the namespace name that boundary created
98
- namespaceName := getNamespaceName (t )
115
+ //namespaceName := getNamespaceName(t)
116
+
117
+ pidInt := getChildProcessPID (t )
118
+ pid := fmt .Sprintf ("%v" , pidInt )
99
119
100
120
// Test HTTP request through boundary (from inside the jail)
101
121
t .Run ("HTTPRequestThroughBoundary" , func (t * testing.T ) {
102
122
// Run curl directly in the namespace using ip netns exec
103
- curlCmd := exec .Command ("sudo" , "ip " , "netns " , "exec " , namespaceName ,
123
+ curlCmd := exec .Command ("sudo" , "nsenter " , "-t " , pid , "-n " , "--" ,
104
124
"curl" , "http://jsonplaceholder.typicode.com/todos/1" )
105
125
106
126
// Capture stderr separately
@@ -128,7 +148,7 @@ func TestBoundaryIntegration(t *testing.T) {
128
148
certPath := fmt .Sprintf ("%v/ca-cert.pem" , configDir )
129
149
130
150
// Run curl directly in the namespace using ip netns exec
131
- curlCmd := exec .Command ("sudo" , "ip " , "netns " , "exec " , namespaceName ,
151
+ curlCmd := exec .Command ("sudo" , "sudo " , "nsenter " , "-t " , pid , "-n" , "--" ,
132
152
"env" , fmt .Sprintf ("SSL_CERT_FILE=%v" , certPath ), "curl" , "-s" , "https://dev.coder.com/api/v2" )
133
153
134
154
// Capture stderr separately
@@ -149,7 +169,7 @@ func TestBoundaryIntegration(t *testing.T) {
149
169
// Test blocked domain (from inside the jail)
150
170
t .Run ("BlockedDomainTest" , func (t * testing.T ) {
151
171
// Run curl directly in the namespace using ip netns exec
152
- curlCmd := exec .Command ("sudo" , "ip " , "netns " , "exec " , namespaceName ,
172
+ curlCmd := exec .Command ("sudo" , "sudo " , "nsenter " , "-t " , pid , "-n" , "--" ,
153
173
"curl" , "-s" , "http://example.com" )
154
174
155
175
// Capture stderr separately
0 commit comments