mirror of
https://github.com/angristan/openvpn-install.git
synced 2025-12-16 08:57:03 +01:00
fix: exit non-zero when client name exists (#1407)
Fixes https://github.com/angristan/openvpn-install/issues/1194
This commit is contained in:
@@ -3142,7 +3142,7 @@ function newClient() {
|
|||||||
CLIENTEXISTS=$(tail -n +2 /etc/openvpn/server/easy-rsa/pki/index.txt | grep -E "^V" | grep -c -E "/CN=$CLIENT\$")
|
CLIENTEXISTS=$(tail -n +2 /etc/openvpn/server/easy-rsa/pki/index.txt | grep -E "^V" | grep -c -E "/CN=$CLIENT\$")
|
||||||
if [[ $CLIENTEXISTS != '0' ]]; then
|
if [[ $CLIENTEXISTS != '0' ]]; then
|
||||||
log_error "The specified client CN was already found in easy-rsa, please choose another name."
|
log_error "The specified client CN was already found in easy-rsa, please choose another name."
|
||||||
exit
|
exit 1
|
||||||
else
|
else
|
||||||
cd /etc/openvpn/server/easy-rsa/ || return
|
cd /etc/openvpn/server/easy-rsa/ || return
|
||||||
log_info "Generating client certificate..."
|
log_info "Generating client certificate..."
|
||||||
|
|||||||
@@ -99,6 +99,29 @@ fi
|
|||||||
|
|
||||||
echo "All required files present"
|
echo "All required files present"
|
||||||
|
|
||||||
|
# =====================================================
|
||||||
|
# Test duplicate client name handling
|
||||||
|
# =====================================================
|
||||||
|
echo ""
|
||||||
|
echo "=== Testing Duplicate Client Name Handling ==="
|
||||||
|
DUPLICATE_CLIENT="testclient"
|
||||||
|
DUPLICATE_OUTPUT="/tmp/duplicate-client-output.log"
|
||||||
|
(bash /opt/openvpn-install.sh client add "$DUPLICATE_CLIENT" --cert-days 3650) 2>&1 | tee "$DUPLICATE_OUTPUT" || true
|
||||||
|
DUPLICATE_EXIT_CODE=${PIPESTATUS[0]}
|
||||||
|
|
||||||
|
if [ "$DUPLICATE_EXIT_CODE" -ne 1 ]; then
|
||||||
|
echo "FAIL: Expected exit code 1 for duplicate client name, got $DUPLICATE_EXIT_CODE"
|
||||||
|
cat "$DUPLICATE_OUTPUT"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if grep -q "The specified client CN was already found in easy-rsa" "$DUPLICATE_OUTPUT"; then
|
||||||
|
echo "PASS: Duplicate client name correctly rejected with exit code 1"
|
||||||
|
else
|
||||||
|
echo "FAIL: Expected error message for duplicate client name not found"
|
||||||
|
cat "$DUPLICATE_OUTPUT"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Copy client config to shared volume for the client container
|
# Copy client config to shared volume for the client container
|
||||||
cp /root/testclient.ovpn /shared/client.ovpn
|
cp /root/testclient.ovpn /shared/client.ovpn
|
||||||
sed -i 's/^remote .*/remote openvpn-server 1194/' /shared/client.ovpn
|
sed -i 's/^remote .*/remote openvpn-server 1194/' /shared/client.ovpn
|
||||||
|
|||||||
Reference in New Issue
Block a user