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
59
60
61
62
63
64
65
66
67
68
69
|
package e2e
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
func TestConfigPropagation(t *testing.T) {
binaryPath := EnsureBinary(t)
tmpConfigDir := t.TempDir()
tmpRuntimeDir := t.TempDir()
profile := "config-test-vpn"
// Write a valid dummy profile for config-test-vpn so it doesn't fail the profile-existence check
confContent := `[Interface]
PrivateKey = YXNkZmFzZGZhc2RmYXNkZmFzZGZhc2RmYXNkZmFzZGY=
Address = 10.0.0.2/24
[Peer]
PublicKey = YXNkZmFzZGZhc2RmYXNkZmFzZGZhc2RmYXNkZmFzZGY=
Endpoint = 127.0.0.1:51820
AllowedIPs = 10.0.0.0/24
`
profilesDir := filepath.Join(tmpConfigDir, "wg-wrap", "profiles")
_ = os.MkdirAll(profilesDir, 0755)
_ = os.WriteFile(filepath.Join(profilesDir, profile+".conf"), []byte(confContent), 0644)
// 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),
fmt.Sprintf("XDG_CONFIG_HOME=%s", tmpConfigDir),
)
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)
cmdIsolated := exec.Command(binaryPath, "--profile", profile, "--", "sh", "-c", "echo $XDG_RUNTIME_DIR")
cmdIsolated.Env = append(os.Environ(),
fmt.Sprintf("XDG_RUNTIME_DIR=%s", tmpRuntimeDir),
fmt.Sprintf("XDG_CONFIG_HOME=%s", tmpConfigDir),
)
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))
}
}
|