- Create test_helper/common.bash with shared utilities - Add unit tests for firewall configuration functions - Add unit tests for build script functions - Establish testing patterns for TDD approach This provides the foundation for 100% test coverage. 💘 Generated with Crush Assisted-by: GLM-4.6 via Crush <crush@charm.land>
51 lines
1.4 KiB
Bash
51 lines
1.4 KiB
Bash
#!/usr/bin/env bats
|
|
# Unit tests for firewall configuration functions
|
|
|
|
load 'test_helper/common.bash'
|
|
|
|
@test "parse wireguard endpoint from config" {
|
|
# Create test configuration
|
|
local test_config="$TEST_TEMP_DIR/wg0.conf"
|
|
create_test_wg_config "$test_config"
|
|
|
|
# Source the firewall setup script functions
|
|
source "${PROJECT_ROOT}/src/firewall-setup.sh"
|
|
|
|
# Test parsing function
|
|
result=$(parse_wg_endpoint "$test_config")
|
|
assert_equal "$result" "192.168.1.100:51820"
|
|
}
|
|
|
|
@test "generate nftables rules for wireguard" {
|
|
source "${PROJECT_ROOT}/src/firewall-setup.sh"
|
|
|
|
rules=$(generate_nftables_rules "192.168.1.100:51820")
|
|
assert_regex "$rules" "udp.*192.168.1.100.*51820"
|
|
assert_regex "$rules" "policy drop"
|
|
}
|
|
|
|
@test "error handling for missing config file" {
|
|
source "${PROJECT_ROOT}/src/firewall-setup.sh"
|
|
|
|
run parse_wg_endpoint "/nonexistent/file.conf"
|
|
assert_failure
|
|
assert_output --partial "Error: WireGuard config not found"
|
|
}
|
|
|
|
@test "error handling for malformed config" {
|
|
# Create malformed config without endpoint
|
|
local malformed_config="$TEST_TEMP_DIR/malformed.conf"
|
|
cat > "$malformed_config" << EOF
|
|
[Interface]
|
|
PrivateKey = testkey
|
|
Address = 10.0.0.2/24
|
|
|
|
[Peer]
|
|
PublicKey = testpubkey
|
|
# No endpoint line
|
|
EOF
|
|
|
|
source "${PROJECT_ROOT}/src/firewall-setup.sh"
|
|
run parse_wg_endpoint "$malformed_config"
|
|
assert_failure
|
|
} |