1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
package e2e
import (
"fmt"
"os"
"os/exec"
"strings"
"testing"
)
func TestConfigPropagation(t *testing.T) {
binaryPath, err := GetBinaryPath()
if err != nil {
t.Skipf("Skipping test: %v", err)
}
tmpRuntimeDir := t.TempDir()
profile := "config-test-vpn"
// Test 1: Non-isolated configuration
cmd := exec.Command(binaryPath, "show-config", "--profile", profile)
cmd.Env = append(os.Environ(), fmt.Sprintf("XDG_RUNTIME_DIR=%s", tmpRuntimeDir))
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("show-config failed: %v\nOutput: %s", err, string(out))
}
output := string(out)
expectedBase := tmpRuntimeDir
expectedPids := fmt.Sprintf("%s/profiles/%s/pids", tmpRuntimeDir, profile)
if !strings.Contains(output, fmt.Sprintf("Runtime Base: %s", expectedBase)) {
t.Errorf("Expected Runtime Base %s in output: %s", expectedBase, output)
}
if !strings.Contains(output, fmt.Sprintf("PIDs Path: %s", expectedPids)) {
t.Errorf("Expected PIDs Path %s in output: %s", expectedPids, output)
}
// Test 2: Configuration after bootstrap (Isolated)
// We use 'test-ns' as a way to run a command that we know is isolated.
// Actually, we can just run 'show-config' but the current 'Route'
// handles 'show-config' BEFORE the bootstrap.
// To test isolated config, we can't use 'show-config' because it's a diagnostic
// command designed to run outside isolation.
// To verify what an isolated process sees, we can use a target command
// that prints the environment.
cmdIsolated := exec.Command(binaryPath, "--profile", profile, "--", "sh", "-c", "echo $XDG_RUNTIME_DIR")
cmdIsolated.Env = append(os.Environ(), fmt.Sprintf("XDG_RUNTIME_DIR=%s", tmpRuntimeDir))
outIso, err := cmdIsolated.CombinedOutput()
if err != nil {
t.Fatalf("Isolated command failed: %v\nOutput: %s", err, string(outIso))
}
if !strings.Contains(string(outIso), expectedBase) {
t.Errorf("Expected isolated process to see XDG_RUNTIME_DIR=%s, got: %s", expectedBase, string(outIso))
}
}
|