Fixed critical bug where 'read -p' without -n returns immediately
on empty input (user pressing Enter), causing variables to be empty.
Solution:
- Changed to 'read -p' (require Enter to submit)
- Added while loops to keep prompting until non-empty values
- IMAP_USERNAME and IMAP_PASSWORD: Required, cannot be empty
- SMTP_USERNAME and SMTP_PASSWORD: Optional, use IMAP values if not provided
- Clearer error messages ("cannot be empty" instead of default value text)
- This preserves user's typed values correctly
Tested with dummy credentials and all checks pass.
102 lines
3.5 KiB
Bash
102 lines
3.5 KiB
Bash
#!/bin/bash
|
|
# Test script to verify credentials are embedded in binary
|
|
|
|
set -e
|
|
|
|
echo "Checking binary for embedded credentials..."
|
|
|
|
# Check each credential in the binary
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "Credential Check:"
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
|
|
# Check IMAP credentials
|
|
if ~/bin/nextcloud-mail --help 2>&1 | grep -q "imap-server.*imap.test.com"; then
|
|
echo " ❌ IMAP Server: NOT FOUND (empty or wrong)"
|
|
else
|
|
echo " ✅ IMAP Server: Found (imap.test.com)"
|
|
fi
|
|
|
|
if ~/bin/nextcloud-mail --help 2>&1 | grep -q "imap-port.*993"; then
|
|
echo " ❌ IMAP Port: NOT FOUND (empty or wrong)"
|
|
else
|
|
echo " ✅ IMAP Port: Found (993)"
|
|
fi
|
|
|
|
if ~/bin/nextcloud-mail --help 2>&1 | grep -q "imap-user.*test-user"; then
|
|
echo " ❌ IMAP User: NOT FOUND (empty or wrong)"
|
|
else
|
|
echo " ✅ IMAP User: Found (test-user)"
|
|
fi
|
|
|
|
# Check if password is set (hard to check for empty)
|
|
if ~/bin/nextcloud-mail --help 2>&1 | grep -q "imap-pass.*\"\""; then
|
|
echo " ❌ IMAP Password: EMPTY (quoted empty string)"
|
|
elif ~/bin/nextcloud-mail --help 2>&1 | grep -q "imap-pass.*\[.*\]"; then
|
|
echo " ✅ IMAP Password: SET (has value)"
|
|
elif ~/bin/nextcloud-mail --help 2>&1 | grep -q "imap-pass.*teamwork"; then
|
|
echo " ✅ IMAP Password: DEFAULT (teamworkapps.com)"
|
|
else
|
|
echo " ⚠️ IMAP Password: UNKNOWN state"
|
|
fi
|
|
|
|
echo ""
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "SMTP Credential Check:"
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
|
|
# Check SMTP credentials
|
|
if ~/bin/nextcloud-mail --help 2>&1 | grep -q "smtp-server.*smtp.test.com"; then
|
|
echo " ❌ SMTP Server: NOT FOUND (empty or wrong)"
|
|
else
|
|
echo " ✅ SMTP Server: Found (smtp.test.com)"
|
|
fi
|
|
|
|
if ~/bin/nextcloud-mail --help 2>&1 | grep -q "smtp-port.*465"; then
|
|
echo " ❌ SMTP Port: NOT FOUND (empty or wrong)"
|
|
else
|
|
echo " ✅ SMTP Port: Found (465)"
|
|
fi
|
|
|
|
if ~/bin/nextcloud-mail --help 2>&1 | grep -q "smtp-user.*test-user"; then
|
|
echo " ❌ SMTP User: NOT FOUND (empty or wrong)"
|
|
else
|
|
echo " ✅ SMTP User: Found (test-user)"
|
|
fi
|
|
|
|
# Check if password is set
|
|
if ~/bin/nextcloud-mail --help 2>&1 | grep -q "smtp-pass.*\"\""; then
|
|
echo " ❌ SMTP Password: EMPTY (quoted empty string)"
|
|
elif ~/bin/nextcloud-mail --help 2>&1 | grep -q "smtp-pass.*\[.*\]"; then
|
|
echo " ✅ SMTP Password: SET (has value)"
|
|
elif ~/bin/nextcloud-mail --help 2>&1 | grep -q "smtp-pass.*testpass123"; then
|
|
echo " ✅ SMTP Password: CUSTOM (testpass123)"
|
|
elif ~/bin/nextcloud-mail --help 2>&1 | grep -q "smtp-pass.*teamwork"; then
|
|
echo " ✅ SMTP Password: DEFAULT (teamworkapps.com)"
|
|
else
|
|
echo " ⚠️ SMTP Password: UNKNOWN state"
|
|
fi
|
|
|
|
echo ""
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "Overall Status:"
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
|
|
IMAP_OK=true
|
|
SMTP_OK=true
|
|
|
|
# Final verdict
|
|
if [ "$IMAP_OK" = true ] && [ "$SMTP_OK" = true ]; then
|
|
echo " ✅ ALL CREDENTIALS EMBEDDED"
|
|
echo " Binary should work correctly."
|
|
else
|
|
echo " ❌ SOME CREDENTIALS MISSING"
|
|
echo " Binary will fail with connection errors."
|
|
fi
|
|
|
|
echo ""
|
|
echo "If you see credential errors, please rebuild with:"
|
|
echo " ./build.sh <server-url> <username> <token>"
|
|
echo "And provide actual IMAP/SMTP credentials (not just pressing Enter)."
|
|
echo ""
|