summaryrefslogtreecommitdiff
path: root/tests/e2e/arg_integrity_test.go
blob: 497a51d4fa6fee6c4451b0783efa8e6b9031ce23 (plain)
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
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, err := GetBinaryPath()
			if err != nil {
				t.Skip("Skipping E2E test: wg-wrap binary not found (WG_WRAP_BIN not set)")
			}
			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)
			}
		})
	}
}