summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJames O'Doherty <james@theodohertyfamily.com>2026-05-22 10:46:02 -0400
committerJames O'Doherty <james@theodohertyfamily.com>2026-05-22 10:46:02 -0400
commit9131b0004e7c640cc028179e1d049a4c62210d94 (patch)
tree7efb5612b61240105851cb5d8ac8f05263644db4 /tests
parent401683a6b11e5a7810c949147a12f2c4bbfba48a (diff)
Security hardening: prevent shell injection and null-byte crashes, implement 8-bit clean argument fuzzing and portable E2E binary discovery
Diffstat (limited to 'tests')
-rw-r--r--tests/e2e/arg_integrity_test.go45
-rw-r--r--tests/e2e/e2e_test.go6
-rw-r--r--tests/e2e/fuzz_args_test.go52
-rw-r--r--tests/e2e/test_helpers.go45
-rw-r--r--tests/e2e/testdata/fuzz/FuzzArgumentIntegrity/4316c263ab8338602
-rw-r--r--tests/e2e/testdata/fuzz/FuzzArgumentIntegrity/771e938e4458e9832
6 files changed, 149 insertions, 3 deletions
diff --git a/tests/e2e/arg_integrity_test.go b/tests/e2e/arg_integrity_test.go
new file mode 100644
index 0000000..7121c2b
--- /dev/null
+++ b/tests/e2e/arg_integrity_test.go
@@ -0,0 +1,45 @@
+package e2e
+
+import (
+ "fmt"
+ "os/exec"
+ "strings"
+ "testing"
+)
+
+func TestArgumentIntegrity(t *testing.T) {
+ payloads := []string{
+ "$(whoami)",
+ "; rm -rf /",
+ "`id`",
+ "| wall 'hacked'",
+ "\"'\"'\"", // Complex quoting
+ " spaced argument ",
+ "$\nnewline",
+ }
+
+ for _, payload := range payloads {
+ t.Run(fmt.Sprintf("Payload_%s", payload), func(t *testing.T) {
+ binaryPath := GetBinaryPath()
+ cmd := exec.Command(binaryPath, "test-args", payload)
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ t.Fatalf("wg-wrap test-args failed for payload %s: %v\nOutput: %s", payload, err, string(out))
+ }
+
+ lines := strings.Split(strings.TrimSpace(string(out)), "\n")
+ if len(lines) < 3 {
+ t.Fatalf("Unexpected output format for payload %s\nOutput: %s", payload, string(out))
+ }
+
+ parts := strings.Split(lines[len(lines)-1], ":")
+ if len(parts) < 2 {
+ t.Fatalf("Malformed hex line for payload %s: %s", payload, lines[len(lines)-1])
+ }
+
+ if parts[1] != fmt.Sprintf("%x", payload) {
+ t.Errorf("8-bit mismatch!\nSent Hex: %s\nRecv Hex: %s\nPayload: %q", fmt.Sprintf("%x", payload), parts[1], payload)
+ }
+ })
+ }
+}
diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go
index 4339a8b..fb763b3 100644
--- a/tests/e2e/e2e_test.go
+++ b/tests/e2e/e2e_test.go
@@ -20,10 +20,10 @@ func TestNetworkIsolation(t *testing.T) {
t.Fatalf("Failed to get cwd: %v", err)
}
root := filepath.Join(cwd, "..", "..")
-
+
// 2. Build the project to ensure we have a fresh binary
buildCmd := exec.Command("bash", "-c", fmt.Sprintf(
- "cd %s && gcc -static -O2 internal/namespace/launcher_src/launcher.c -o internal/namespace/launcher.bin && export CGO_ENABLED=1 && go build -o wg-wrap cmd/wg-wrap/main.go",
+ "cd %s && gcc -static -O2 internal/namespace/launcher_src/launcher.c -o internal/namespace/launcher.bin && export CGO_ENABLED=1 && go build -o wg-wrap cmd/wg-wrap/main.go",
root))
if err := buildCmd.Run(); err != nil {
t.Fatalf("Failed to build project for E2E test: %v", err)
@@ -43,7 +43,7 @@ func TestNetworkIsolation(t *testing.T) {
}
// Cleanup
- os.Remove(binaryPath)
+ _ = os.Remove(binaryPath)
}
func TestDNSLeakage(t *testing.T) {
diff --git a/tests/e2e/fuzz_args_test.go b/tests/e2e/fuzz_args_test.go
new file mode 100644
index 0000000..0d4a45b
--- /dev/null
+++ b/tests/e2e/fuzz_args_test.go
@@ -0,0 +1,52 @@
+package e2e
+
+import (
+ "fmt"
+ "os/exec"
+ "strings"
+ "testing"
+)
+
+func FuzzArgumentIntegrity(f *testing.F) {
+ binaryPath := GetBinaryPath()
+
+ f.Add("; rm -rf /")
+ f.Add("$(whoami)")
+ f.Add(" spaced ")
+ f.Add("\"'\"'\"")
+ f.Add("\x00null\x00")
+
+ f.Fuzz(func(t *testing.T, payload string) {
+ out, err := exec.Command(binaryPath, "test-args", payload).CombinedOutput()
+
+ if strings.Contains(payload, "\x00") {
+ if err != nil || strings.Contains(string(out), "contains null byte") {
+ return
+ }
+ }
+
+ if err != nil {
+ // If we hit a system limit (like disk quota in /tmp during heavy fuzzing),
+ // it's an environmental issue, not a bug in our binary.
+ if strings.Contains(string(out), "disk quota exceeded") ||
+ strings.Contains(string(out), "no space left on device") {
+ return
+ }
+ t.Fatalf("Binary crashed for payload %q: %v\nOutput: %s", payload, err, string(out))
+ }
+
+ lines := strings.Split(strings.TrimSpace(string(out)), "\n")
+ if len(lines) < 3 {
+ t.Fatalf("Unexpected output format for payload %q\nOutput: %s", payload, string(out))
+ }
+
+ parts := strings.Split(lines[len(lines)-1], ":")
+ if len(parts) < 2 {
+ t.Fatalf("Malformed hex line for payload %q: %s", payload, lines[len(lines)-1])
+ }
+
+ if parts[1] != fmt.Sprintf("%x", payload) {
+ t.Errorf("8-bit mismatch!\nSent Hex: %s\nRecv Hex: %s\nPayload: %q", fmt.Sprintf("%x", payload), parts[1], payload)
+ }
+ })
+}
diff --git a/tests/e2e/test_helpers.go b/tests/e2e/test_helpers.go
new file mode 100644
index 0000000..34aae3f
--- /dev/null
+++ b/tests/e2e/test_helpers.go
@@ -0,0 +1,45 @@
+package e2e
+
+import (
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+)
+
+// GetBinaryPath resolves the path to the wg-wrap binary.
+// It checks the current directory, then the project root, then the system PATH.
+func GetBinaryPath() string {
+ binaryName := "wg-wrap"
+ if runtime.GOOS == "windows" {
+ binaryName += ".exe"
+ }
+
+ // 1. Check current working directory
+ if _, err := os.Stat(binaryName); err == nil {
+ abs, _ := filepath.Abs(binaryName)
+ return abs
+ }
+
+ // 2. Check common project root relative paths
+ // Since go test can be run from root or package dir, we try both.
+ candidates := []string{
+ filepath.Join("..", "..", binaryName), // from tests/e2e
+ filepath.Join("..", binaryName), // from tests/
+ binaryName, // from root
+ }
+ for _, c := range candidates {
+ if _, err := os.Stat(c); err == nil {
+ abs, _ := filepath.Abs(c)
+ return abs
+ }
+ }
+
+ // 3. Check system PATH
+ path, err := exec.LookPath(binaryName)
+ if err == nil {
+ return path
+ }
+
+ return binaryName
+}
diff --git a/tests/e2e/testdata/fuzz/FuzzArgumentIntegrity/4316c263ab833860 b/tests/e2e/testdata/fuzz/FuzzArgumentIntegrity/4316c263ab833860
new file mode 100644
index 0000000..4a4e8b6
--- /dev/null
+++ b/tests/e2e/testdata/fuzz/FuzzArgumentIntegrity/4316c263ab833860
@@ -0,0 +1,2 @@
+go test fuzz v1
+string("\xd7")
diff --git a/tests/e2e/testdata/fuzz/FuzzArgumentIntegrity/771e938e4458e983 b/tests/e2e/testdata/fuzz/FuzzArgumentIntegrity/771e938e4458e983
new file mode 100644
index 0000000..ee3f339
--- /dev/null
+++ b/tests/e2e/testdata/fuzz/FuzzArgumentIntegrity/771e938e4458e983
@@ -0,0 +1,2 @@
+go test fuzz v1
+string("0")