Add WireGuard TUI implementation

- Add Go TUI with bubbletea for WireGuard management
- Implement client CRUD operations with QR code generation
- Add configuration and validation modules
- Install/update scripts for client setup
- Update Makefile to build binaries to bin/ directory
- Add .gitignore for Go projects
This commit is contained in:
Calmcacil
2026-01-12 19:03:35 +01:00
parent 5ac68db854
commit 26120b8bc2
37 changed files with 6330 additions and 97 deletions

124
test-wg-install.sh Executable file
View File

@@ -0,0 +1,124 @@
#!/usr/bin/env bash
# Test script for wg-install.sh validation functions
set -euo pipefail
# Override log location for tests
export WGI_LOG_FILE="/tmp/wg-admin-install-test.log"
# Source the main script to get functions
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/wg-install.sh"
# Test counter
TESTS_RUN=0
TESTS_PASSED=0
TESTS_FAILED=0
# Test function
run_test() {
local test_name="$1"
local expected="$2"
shift 2
local result
TESTS_RUN=$((TESTS_RUN + 1))
# Run function and capture output and exit code
if result=$("$@" 2>&1); then
local exit_code=$?
else
local exit_code=$?
fi
if [[ "$expected" == "success" && "$exit_code" -eq 0 ]]; then
TESTS_PASSED=$((TESTS_PASSED + 1))
echo "✓ PASS: $test_name"
return 0
elif [[ "$expected" == "failure" && "$exit_code" -ne 0 ]]; then
TESTS_PASSED=$((TESTS_PASSED + 1))
echo "✓ PASS: $test_name"
return 0
else
TESTS_FAILED=$((TESTS_FAILED + 1))
echo "✗ FAIL: $test_name"
echo " Expected: $expected"
echo " Exit code: $exit_code"
echo " Output: $result"
return 1
fi
}
echo "=== Running wg-install.sh Tests ==="
echo ""
# Test validate_server_domain
echo "Testing validate_server_domain..."
run_test "Valid domain" success validate_server_domain "vpn.example.com"
run_test "Valid subdomain" success validate_server_domain "wg.vpn.example.com"
run_test "Valid domain with hyphen" success validate_server_domain "my-vpn.example.com"
run_test "Empty domain" failure validate_server_domain ""
run_test "Invalid domain - spaces" failure validate_server_domain "vpn example.com"
run_test "Invalid domain - special chars" failure validate_server_domain "vpn@example.com"
echo ""
# Test validate_port_range
echo "Testing validate_port_range..."
run_test "Valid default port" success validate_port_range "51820"
run_test "Valid port 80" success validate_port_range "80"
run_test "Valid port 443" success validate_port_range "443"
run_test "Valid max port" success validate_port_range "65535"
run_test "Empty port" failure validate_port_range ""
run_test "Invalid port - negative" failure validate_port_range "-1"
run_test "Invalid port - zero" failure validate_port_range "0"
run_test "Invalid port - too high" failure validate_port_range "65536"
run_test "Invalid port - non-numeric" failure validate_port_range "abc"
echo ""
# Test validate_cidr (IPv4)
echo "Testing validate_cidr (IPv4)..."
run_test "Valid IPv4 /24" success validate_cidr "10.10.69.0/24" false
run_test "Valid IPv4 /32" success validate_cidr "192.168.1.1/32" false
run_test "Valid IPv4 /16" success validate_cidr "172.16.0.0/16" false
run_test "Empty IPv4 CIDR" failure validate_cidr "" false
run_test "Invalid IPv4 - no prefix" failure validate_cidr "10.10.69.0" false
run_test "Invalid IPv4 - prefix too large" failure validate_cidr "10.10.69.0/33" false
run_test "Invalid IPv4 - negative prefix" failure validate_cidr "10.10.69.0/-1" false
run_test "Invalid IPv4 - bad IP" failure validate_cidr "256.1.1.1/24" false
echo ""
# Test validate_cidr (IPv6)
echo "Testing validate_cidr (IPv6)..."
run_test "Valid IPv6 /64" success validate_cidr "fd69:dead:beef:69::/64" true
run_test "Valid IPv6 /128" success validate_cidr "fd69:dead:beef:69::1/128" true
run_test "Valid IPv6 /48" success validate_cidr "fd69:dead::/48" true
run_test "Empty IPv6 CIDR" failure validate_cidr "" true
run_test "Invalid IPv6 - no prefix" failure validate_cidr "fd69:dead:beef:69::" true
run_test "Invalid IPv6 - prefix too large" failure validate_cidr "fd69:dead:beef:69::/129" true
echo ""
# Test validate_dns_servers
echo "Testing validate_dns_servers..."
run_test "Valid single DNS" success validate_dns_servers "8.8.8.8"
run_test "Valid multiple DNS" success validate_dns_servers "8.8.8.8, 8.8.4.4"
run_test "Valid DNS with spaces" success validate_dns_servers "8.8.8.8, 1.1.1.1"
run_test "Empty DNS" success validate_dns_servers ""
run_test "Invalid DNS - bad format" failure validate_dns_servers "8.8.8"
run_test "Invalid DNS - special chars" failure validate_dns_servers "dns.example.com"
echo ""
# Summary
echo ""
echo "=== Test Summary ==="
echo "Tests run: $TESTS_RUN"
echo "Tests passed: $TESTS_PASSED"
echo "Tests failed: $TESTS_FAILED"
echo ""
if [[ $TESTS_FAILED -eq 0 ]]; then
echo "All tests passed! ✓"
exit 0
else
echo "Some tests failed! ✗"
exit 1
fi