chore: initial commit of wgtool
This commit is contained in:
74
test_overwrite_protection.sh
Executable file
74
test_overwrite_protection.sh
Executable file
@@ -0,0 +1,74 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Test script to demonstrate file overwrite protection
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
print_status() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_header() {
|
||||
echo -e "${BLUE}================================${NC}"
|
||||
echo -e "${BLUE}$1${NC}"
|
||||
echo -e "${BLUE}================================${NC}"
|
||||
}
|
||||
|
||||
print_header "Testing File Overwrite Protection"
|
||||
|
||||
echo "This test will demonstrate the file overwrite protection feature."
|
||||
echo ""
|
||||
|
||||
# Create a test configuration file first
|
||||
print_status "Creating a test configuration file..."
|
||||
mkdir -p wireguard_configs
|
||||
echo "# Test configuration" > wireguard_configs/test_node.conf
|
||||
echo "This is a test file" >> wireguard_configs/test_node.conf
|
||||
|
||||
print_status "Test file created: wireguard_configs/test_node.conf"
|
||||
echo ""
|
||||
|
||||
# Test 1: Try to create a configuration with the same name (should prompt for overwrite)
|
||||
print_header "Test 1: Attempting to create configuration with existing name"
|
||||
|
||||
echo "Now we'll try to create a configuration with the same name 'test_node'"
|
||||
echo "The script should detect the existing file and ask if you want to overwrite it."
|
||||
echo ""
|
||||
|
||||
# Create test input that will trigger the overwrite prompt
|
||||
cat > /tmp/test_overwrite_input.txt << 'EOF'
|
||||
test_node
|
||||
10.8.0.5/24
|
||||
n
|
||||
n
|
||||
n
|
||||
EOF
|
||||
|
||||
print_status "Running setup script..."
|
||||
echo "When prompted, you can choose:"
|
||||
echo " 'y' to overwrite the existing file"
|
||||
echo " 'n' to cancel the operation"
|
||||
echo ""
|
||||
|
||||
# Run the setup script
|
||||
./wireguard_setup.sh < /tmp/test_overwrite_input.txt
|
||||
|
||||
# Clean up
|
||||
rm -f /tmp/test_overwrite_input.txt
|
||||
|
||||
print_status "Test completed!"
|
||||
echo ""
|
||||
echo "The script should have:"
|
||||
echo "1. Detected the existing test_node.conf file"
|
||||
echo "2. Asked if you wanted to overwrite it"
|
||||
echo "3. Either overwritten it (if you chose 'y') or cancelled (if you chose 'n')"
|
||||
Reference in New Issue
Block a user