Skip to content

Commit 6cd37b5

Browse files
temporary commit: trying to fix e2e tests
1 parent a8cd568 commit 6cd37b5

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

cli/cli.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,26 @@ func BaseCommand() *serpent.Command {
9797
func Run(ctx context.Context, config Config, args []string) error {
9898
isChild := os.Getenv("CHILD") == "true"
9999
if isChild {
100+
log.Printf("CHILD process is started")
100101
vethNetJail := os.Getenv("VETH_JAIL_NAME")
101102

102103
err := jail.SetupChildNetworking(vethNetJail)
103104
if err != nil {
104-
fmt.Fprintf(os.Stderr, "failed setupChildNetworking: %v\n", err)
105-
os.Exit(1)
105+
return fmt.Errorf("failed to run SetupChildNetworking: %v", err)
106106
}
107+
log.Printf("child networking is configured")
107108

108109
// Program to run
109110
bin := args[0]
110111
args = args[1:]
111112
env := os.Environ()
113+
log.Printf("bin: %v, args: %v\n", bin, args)
114+
log.Printf("env: %v\n", os.Environ())
112115
// syscall.Exec replaces the current process image
113116
// with the new program, so nothing after this call runs.
114117
if err := syscall.Exec(bin, args, env); err != nil {
115-
log.Fatalf("exec failed: %v", err)
118+
log.Printf("failed to exec child process: %v", err)
119+
return fmt.Errorf("failed to exec child process: %v", err)
116120
}
117121

118122
// This line is never reached if Exec succeeds.
@@ -227,7 +231,7 @@ func Run(ctx context.Context, config Config, args []string) error {
227231
logger.Debug("Executing command in boundary", "command", strings.Join(os.Args, " "))
228232
err := cmd.Start()
229233
if err != nil {
230-
logger.Error("Command execution failed", "error", err)
234+
logger.Error("Command execution failed(Start)", "error", err)
231235
}
232236

233237
err = boundaryInstance.ConfigureAfterCommandExecution(cmd.Process.Pid)
@@ -237,7 +241,7 @@ func Run(ctx context.Context, config Config, args []string) error {
237241

238242
err = cmd.Wait()
239243
if err != nil {
240-
logger.Error("Command execution failed", "error", err)
244+
logger.Error("Command execution failed(Wait)", "error", err)
241245
}
242246
}()
243247

e2e_tests/boundary_integration_test.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"os/exec"
99
"path/filepath"
10+
"strconv"
1011
"strings"
1112
"testing"
1213
"time"
@@ -62,6 +63,21 @@ func getNamespaceName(t *testing.T) string {
6263
return namespaces[0]
6364
}
6465

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+
6581
func TestBoundaryIntegration(t *testing.T) {
6682
// Find project root by looking for go.mod file
6783
projectRoot := findProjectRoot(t)
@@ -81,7 +97,8 @@ func TestBoundaryIntegration(t *testing.T) {
8197
"--allow", "dev.coder.com",
8298
"--allow", "jsonplaceholder.typicode.com",
8399
"--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'")
85102

86103
// Suppress output to prevent terminal corruption
87104
boundaryCmd.Stdout = os.Stdout // Let it go to /dev/null
@@ -92,15 +109,18 @@ func TestBoundaryIntegration(t *testing.T) {
92109
require.NoError(t, err, "Failed to start boundary process")
93110

94111
// Give boundary time to start
95-
time.Sleep(2 * time.Second)
112+
time.Sleep(200 * time.Second)
96113

97114
// 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)
99119

100120
// Test HTTP request through boundary (from inside the jail)
101121
t.Run("HTTPRequestThroughBoundary", func(t *testing.T) {
102122
// 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", "--",
104124
"curl", "http://jsonplaceholder.typicode.com/todos/1")
105125

106126
// Capture stderr separately
@@ -128,7 +148,7 @@ func TestBoundaryIntegration(t *testing.T) {
128148
certPath := fmt.Sprintf("%v/ca-cert.pem", configDir)
129149

130150
// 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", "--",
132152
"env", fmt.Sprintf("SSL_CERT_FILE=%v", certPath), "curl", "-s", "https://dev.coder.com/api/v2")
133153

134154
// Capture stderr separately
@@ -149,7 +169,7 @@ func TestBoundaryIntegration(t *testing.T) {
149169
// Test blocked domain (from inside the jail)
150170
t.Run("BlockedDomainTest", func(t *testing.T) {
151171
// 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", "--",
153173
"curl", "-s", "http://example.com")
154174

155175
// Capture stderr separately

0 commit comments

Comments
 (0)