package windowsnative import ( "os" "os/exec" "path/filepath" "strings" "testing" ) // TestNativeFixtureAssets_HP_HARNESS_20 prevents the host-side controller from // drifting back to a PowerShell-only or protocol-stub lane. It intentionally // checks only static contracts; the real hierarchy proof remains the documented // native VM run. func TestNativeFixtureAssets_HP_HARNESS_20(t *testing.T) { t.Parallel() root := filepath.Clean(filepath.Join("..", "..")) read := func(relative string) string { t.Helper() data, err := os.ReadFile(filepath.Join(root, relative)) if err != nil { t.Fatalf("read %s: %v", relative, err) } return string(data) } runner := read("scripts/windows/native-test") for _, required := range []string{ "scripts/windows/build-test-bundle\" --native-fixture", "scripts/windows/test-host\" prepare", "ACTIVE_USER_ELEVATED,ACTIVE_SYSTEM", "assert_context local-service no local-service", "assert_stdin_close", "assert_signal_term", "rvc kill TERM \"$client_id\" \"$issue\"", "assert_server_restart_reconnect", "compose restart server", "rvc append \"$client_id\" \"$issue\" RVBOX_NATIVE_INPUT", "rvc close-stdin \"$client_id\" \"$issue\"", "clean --purge --yes", "RVBOX_NATIVE_ENDPOINT_HOST", "test/linux-server/compose.yaml", } { if !strings.Contains(runner, required) { t.Fatalf("native runner is missing %q", required) } } testHost := read("scripts/windows/test-host") for _, required := range []string{"xz -T0 -3", "accelerated_stage", "copy_stage_file", "--proxy", "--anyauth", "--continue-at", "rvbox.exe.xz", "retry_limit=4", "ConnectTimeout=10", "bundle transfer did not reach the expected SHA-256 manifest", "verified transfer_sha256", "reset-force-poweroff", "$run_root/.accelerated-stage.XXXXXX", "service-startup.log", "test-logs/rvbox.log"} { if !strings.Contains(testHost, required) { t.Fatalf("native test-host is missing compressed transfer contract %q", required) } } rdpAccess := read("test/rdp-access/rdp-access") for _, required := range []string{"RDP_ACCESS_PROFILE", "--profile", "rvbox-rdp-access-$profile", "runtime_root", "ipv6_forward_status", "compose restart guacd", "compose down --remove-orphans"} { if !strings.Contains(rdpAccess, required) { t.Fatalf("RDP helper is missing isolated lifecycle contract %q", required) } } rdpReadme := read("test/rdp-access/README.md") for _, required := range []string{"Current fixture quick start", "RDP_ACCESS_PROFILE=vm-b", "Partial stack or changed endpoint", "Inspect, repair, stop, or clean that instance"} { if !strings.Contains(rdpReadme, required) { t.Fatalf("RDP helper documentation is missing %q", required) } } compose := read("test/linux-server/compose.yaml") for _, required := range []string{"../../bin/rvbox-server", "nginx:1.27-alpine", "rvbox.native.run_id", "RVBOX_NATIVE_RUNTIME_DIR", "certgen", "networks: [native]"} { if !strings.Contains(compose, required) { t.Fatalf("native Compose fixture is missing %q", required) } } defaults := read("internal/client/supervisor/windows/testfaults_default.go") fixture := read("internal/client/supervisor/windows/testfaults_fixture.go") if !strings.Contains(defaults, "//go:build !rvbox_native_test") || !strings.Contains(fixture, "//go:build rvbox_native_test") { t.Fatal("fixture-only context faults are not separated from release builds") } service := read("cmd/rvbox/service_windows.go") if !strings.Contains(service, "applyServiceDiagnosticsACL") || !strings.Contains(service, "D:P(A;;FA;;;SY)(A;;FA;;;BA)") { t.Fatal("Windows service diagnostics are not readable by administrators") } testing := read("docs/testing.md") for _, required := range []string{"server-process\nrestart", "new reconciled WSS session", "`logs` is the narrow read-only"} { if !strings.Contains(testing, required) { t.Fatalf("native workflow documentation is missing %q", required) } } } func TestLANRelayAssets_HP_HARNESS_22(t *testing.T) { t.Parallel() root := filepath.Clean(filepath.Join("..", "..")) read := func(relative string) string { t.Helper() data, err := os.ReadFile(filepath.Join(root, relative)) if err != nil { t.Fatal(err) } return string(data) } helper := read("test/rdp-access/lan-access") for _, required := range []string{"assert_owned", "requested backend port does not belong to this VM", "VM UUID mismatch", "saved VM UUID mismatch", "interface subnet extends outside private", "ip -4 route get", "unrelated listener", "compose down --remove-orphans", "rmdir \"$dir\"", "attempt\" -le 4", "one console slot"} { if !strings.Contains(helper, required) { t.Fatalf("LAN helper is missing safety/lifecycle contract %q", required) } } for _, prohibited := range []string{"controlvm", "modifyvm", "docker system prune", "rm -rf", "--privileged", "sudo "} { if strings.Contains(helper, prohibited) { t.Fatalf("LAN helper unexpectedly contains %q", prohibited) } } compose := read("test/rdp-access/compose-lan.yaml") for _, required := range []string{"alpine/socat@sha256:", "network_mode: host", "bind=${LAN_BIND},range=${LAN_CIDR}", "TCP4:127.0.0.1:${VRDE_PORT}", "read_only: true", "cap_drop: [ALL]", "65534:65534", "mem_limit: 32m", "rvbox.rdp.lan.vm_uuid"} { if !strings.Contains(compose, required) { t.Fatalf("LAN relay Compose asset is missing %q", required) } } entrypoint := read("test/rdp-access/rdp-access") if !strings.Contains(entrypoint, "lan-up|lan-status|lan-down|lan-clean") || !strings.Contains(entrypoint, "--lan) expose_lan=true") { t.Fatal("LAN lifecycle is not exposed through the existing RDP helper") } } func TestLANRelayRejectsUnsafeOptions_BH_HARNESS_22(t *testing.T) { t.Parallel() root := filepath.Clean(filepath.Join("..", "..")) // Any accidental attempt to reach SSH must fail locally and be detectable. fakeBin := t.TempDir() if err := os.WriteFile(filepath.Join(fakeBin, "ssh"), []byte("#!/bin/sh\necho UNEXPECTED_SSH_ATTEMPT >&2\nexit 99\n"), 0700); err != nil { t.Fatal(err) } for _, tc := range []struct { name string args []string }{ {"wildcard", []string{"--lan-bind", "0.0.0.0"}}, {"loopback", []string{"--lan-bind", "127.0.0.1"}}, {"public", []string{"--lan-bind", "8.8.8.8"}}, {"invalid_octet", []string{"--lan-bind", "192.168.50.999"}}, {"shell_injection", []string{"--lan-bind", "192.168.50.1;id"}}, {"high_port", []string{"--lan-port", "65536"}}, {"privileged_port", []string{"--lan-port", "22"}}, {"wide_192_subnet", []string{"--lan-cidr", "192.168.50.0/8"}}, {"wide_172_subnet", []string{"--lan-cidr", "172.20.0.0/8"}}, {"public_subnet", []string{"--lan-cidr", "0.0.0.0/0"}}, {"profile_traversal", []string{"--profile", "../other"}}, {"remote_root_traversal", nil}, {"images_on_up", []string{"--images"}}, } { t.Run(tc.name, func(t *testing.T) { args := append([]string{filepath.Join(root, "test/rdp-access/rdp-access"), "lan-up"}, tc.args...) cmd := exec.Command("sh", args...) cmd.Env = append(os.Environ(), "PATH="+fakeBin+":"+os.Getenv("PATH"), "RDP_ACCESS_PROFILE=default", "RDP_ACCESS_LAN_BIND=auto", "RDP_ACCESS_LAN_CIDR=auto", "RDP_ACCESS_LAN_PORT=3389") if tc.name == "remote_root_traversal" { cmd.Env = append(cmd.Env, "RDP_ACCESS_LAN_REMOTE_ROOT=/home/cabbage/.local/state/../other") } output, err := cmd.CombinedOutput() if err == nil || !strings.Contains(string(output), "lan-access:") || strings.Contains(string(output), "UNEXPECTED_SSH_ATTEMPT") { t.Fatalf("unsafe input was not rejected before SSH: error=%v output=%s", err, output) } }) } } // Static safety contracts complement the live Windows device/GUI checks. func TestMouseFilterRecoveryAssets_HP_HARNESS_21(t *testing.T) { t.Parallel() root := filepath.Clean(filepath.Join("..", "..")) read := func(relative string) string { t.Helper() data, err := os.ReadFile(filepath.Join(root, relative)) if err != nil { t.Fatal(err) } return string(data) } host := read("scripts/windows/test-host") for _, required := range []string{"mouse-status|mouse-verify|mouse-bypass|mouse-restore", "mouse_action=Restore; assert_provisioner_elevated", "mouse-filter-backup.json", "step \"$action completed; inspect reboot_required before testing input\"", "prepare-usb-mouse-verified", "assert_mouse_bypassed()", "Never reboot here"} { if !strings.Contains(host, required) { t.Fatalf("mouse recovery controller is missing %q", required) } } filter := read("scripts/windows/mouse-filter.ps1") for _, required := range []string{"$Action = 'Status'", "[IO.FileMode]::CreateNew", "-PropertyType MultiString", "$filters -notcontains 'mouclass'", "VID_80EE&PID_0021", "refusing to overwrite other changes", "/restart-device $device.InstanceId", "$deviceExit -eq 3010", "reboot_required=$rebootRequired", "RVBOX_GUEST_OK"} { if !strings.Contains(filter, required) { t.Fatalf("mouse filter helper is missing safety contract %q", required) } } for _, prohibited := range []string{"shutdown.exe", "/delete-driver", "Remove-ItemProperty", "Stop-Service", "/force"} { if strings.Contains(filter, prohibited) { t.Fatalf("mouse filter helper contains prohibited automatic/destructive action %q", prohibited) } } probe := read("test/rdp-access/mouse-probe.py") for _, required := range []string{"Session 0", "range(10)", "GetAsyncKeyState(1)", "'dialog_result'", "time.monotonic() + 600"} { if !strings.Contains(probe, required) { t.Fatalf("interactive mouse probe is missing %q", required) } } } // TestProductionComposeAssets_HP_OPS_01 guards the deployment properties that // a syntax-only Compose check cannot prove: private server reachability through // nginx, non-root state initialization, and a repository-local smoke cleanup. func TestProductionComposeAssets_HP_OPS_01(t *testing.T) { t.Parallel() root := filepath.Clean(filepath.Join("..", "..")) read := func(relative string) string { t.Helper() data, err := os.ReadFile(filepath.Join(root, relative)) if err != nil { t.Fatalf("read %s: %v", relative, err) } return string(data) } compose := read("deploy/production/compose.yaml") for _, required := range []string{ "RVBOX_SERVER_CONFIG:-./server.toml", "RVBOX_HTTPS_BIND:-0.0.0.0", "nginx@sha256:65645c7bb6a0661892a8b03b89d0743208a18dd2f3f17a54ef4b76fb8e2f2a10", "user: \"65532:65532\"", "nofile:", "soft: 65536", "hard: 65536", "condition: service_completed_successfully", "condition: service_healthy", "NET_BIND_SERVICE", "DAC_OVERRIDE", "CHOWN", "SETUID", "SETGID", } { if !strings.Contains(compose, required) { t.Fatalf("production Compose is missing %q", required) } } config := read("deploy/production/server.toml.example") for _, required := range []string{"agent_listen = \"0.0.0.0:6899\"", "listen = \"0.0.0.0:6901\"", "enabled = false", "log_file = \"/var/lib/rvbox-server/logs/rvbox-server.log\"", "log_max_bytes = 10485760", "log_max_files = 5"} { if !strings.Contains(config, required) { t.Fatalf("production server example is missing %q", required) } } runner := read("scripts/test-production-compose") for _, required := range []string{".test-runs/$run_id/production-compose", "RVBOX_HTTPS_BIND=127.0.0.1", "curl --fail", "compose exec -T server", "clean --purge --yes"} { if !strings.Contains(runner, required) { t.Fatalf("production smoke runner is missing %q", required) } } }