7
7
"os"
8
8
"os/exec"
9
9
"path/filepath"
10
+ "strconv"
10
11
"strings"
11
12
"testing"
12
13
"time"
@@ -37,29 +38,15 @@ func findProjectRoot(t *testing.T) string {
37
38
}
38
39
}
39
40
40
- // getNamespaceName gets the single network namespace name
41
- // Fails if there are 0 or multiple namespaces
42
- func getNamespaceName (t * testing.T ) string {
43
- cmd := exec .Command ("ip" , "netns" , "list" )
41
+ func getChildProcessPID (t * testing.T ) int {
42
+ cmd := exec .Command ("pgrep" , "-f" , "boundary-test" , "-n" )
44
43
output , err := cmd .Output ()
45
- require .NoError (t , err , "Failed to list network namespaces" )
46
-
47
- lines := strings .Split (string (output ), "\n " )
48
- var namespaces []string
49
-
50
- for _ , line := range lines {
51
- line = strings .TrimSpace (line )
52
- if line != "" {
53
- // Extract namespace name (first field)
54
- parts := strings .Fields (line )
55
- if len (parts ) > 0 {
56
- namespaces = append (namespaces , parts [0 ])
57
- }
58
- }
59
- }
44
+ require .NoError (t , err )
60
45
61
- require .Len (t , namespaces , 1 , "Expected exactly one network namespace, found %d: %v" , len (namespaces ), namespaces )
62
- return namespaces [0 ]
46
+ pidStr := strings .TrimSpace (string (output ))
47
+ pid , err := strconv .Atoi (pidStr )
48
+ require .NoError (t , err )
49
+ return pid
63
50
}
64
51
65
52
func TestBoundaryIntegration (t * testing.T ) {
@@ -73,18 +60,19 @@ func TestBoundaryIntegration(t *testing.T) {
73
60
require .NoError (t , err , "Failed to build boundary binary" )
74
61
75
62
// Create context for boundary process
76
- ctx , cancel := context .WithTimeout (context .Background (), 15 * time .Second )
63
+ ctx , cancel := context .WithTimeout (context .Background (), 1500 * time .Second )
77
64
defer cancel ()
78
65
79
66
// Start boundary process with sudo
80
67
boundaryCmd := exec .CommandContext (ctx , "/tmp/boundary-test" ,
81
68
"--allow" , "dev.coder.com" ,
82
69
"--allow" , "jsonplaceholder.typicode.com" ,
83
70
"--log-level" , "debug" ,
84
- "--" , "bash" , "-c" , "sleep 10 && echo 'Test completed'" )
71
+ //"--", "/bin/bash")
72
+ "--" , "/bin/bash" , "-c" , "/usr/bin/sleep 12 && /usr/bin/echo 'Test completed'" )
85
73
86
- // Suppress output to prevent terminal corruption
87
- boundaryCmd .Stdout = os .Stdout // Let it go to /dev/null
74
+ boundaryCmd . Stdin = os . Stdin
75
+ boundaryCmd .Stdout = os .Stdout
88
76
boundaryCmd .Stderr = os .Stderr
89
77
90
78
// Start the process
@@ -95,12 +83,18 @@ func TestBoundaryIntegration(t *testing.T) {
95
83
time .Sleep (2 * time .Second )
96
84
97
85
// Get the namespace name that boundary created
98
- namespaceName := getNamespaceName (t )
86
+ //namespaceName := getNamespaceName(t)
87
+
88
+ pidInt := getChildProcessPID (t )
89
+ pid := fmt .Sprintf ("%v" , pidInt )
90
+
91
+ fmt .Printf ("pidInt: %v\n " , pidInt )
92
+ //time.Sleep(200 * time.Second)
99
93
100
94
// Test HTTP request through boundary (from inside the jail)
101
95
t .Run ("HTTPRequestThroughBoundary" , func (t * testing.T ) {
102
96
// Run curl directly in the namespace using ip netns exec
103
- curlCmd := exec .Command ("sudo" , "ip " , "netns " , "exec " , namespaceName ,
97
+ curlCmd := exec .Command ("sudo" , "nsenter " , "-t " , pid , "-n " , "--" ,
104
98
"curl" , "http://jsonplaceholder.typicode.com/todos/1" )
105
99
106
100
// Capture stderr separately
@@ -128,7 +122,7 @@ func TestBoundaryIntegration(t *testing.T) {
128
122
certPath := fmt .Sprintf ("%v/ca-cert.pem" , configDir )
129
123
130
124
// Run curl directly in the namespace using ip netns exec
131
- curlCmd := exec .Command ("sudo" , "ip " , "netns " , "exec " , namespaceName ,
125
+ curlCmd := exec .Command ("sudo" , "sudo " , "nsenter " , "-t " , pid , "-n" , "--" ,
132
126
"env" , fmt .Sprintf ("SSL_CERT_FILE=%v" , certPath ), "curl" , "-s" , "https://dev.coder.com/api/v2" )
133
127
134
128
// Capture stderr separately
@@ -149,7 +143,7 @@ func TestBoundaryIntegration(t *testing.T) {
149
143
// Test blocked domain (from inside the jail)
150
144
t .Run ("BlockedDomainTest" , func (t * testing.T ) {
151
145
// Run curl directly in the namespace using ip netns exec
152
- curlCmd := exec .Command ("sudo" , "ip " , "netns " , "exec " , namespaceName ,
146
+ curlCmd := exec .Command ("sudo" , "sudo " , "nsenter " , "-t " , pid , "-n" , "--" ,
153
147
"curl" , "-s" , "http://example.com" )
154
148
155
149
// Capture stderr separately
0 commit comments