Fix smoke test NEEDS_SETUP detection and login checks
- Check /login redirect to /setup instead of homepage redirect - Use logout link presence to verify login success (encode/decode are public) - Add -c flag to save cookies during homepage check The smoke test was passing login even when not logged in because encode/decode links are visible to everyone. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -133,24 +133,27 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if redirected to setup (first run) or login
|
# Check if /login redirects to setup (meaning no users exist)
|
||||||
REDIRECT=$(curl $CURL_OPTS -s -o /dev/null -w "%{redirect_url}" "$BASE_URL")
|
LOGIN_REDIRECT=$(curl $CURL_OPTS -s -o /dev/null -w "%{redirect_url}" "$BASE_URL/login")
|
||||||
if echo "$REDIRECT" | grep -q "setup"; then
|
if echo "$LOGIN_REDIRECT" | grep -q "setup"; then
|
||||||
pass "Redirected to setup (fresh install)"
|
pass "Login redirects to setup (no users yet)"
|
||||||
NEEDS_SETUP=true
|
NEEDS_SETUP=true
|
||||||
elif echo "$REDIRECT" | grep -q "login"; then
|
else
|
||||||
pass "Redirected to login (already configured)"
|
# Check if we can access login page directly
|
||||||
|
if curl $CURL_OPTS -s "$BASE_URL/login" | grep -qi "login\|password"; then
|
||||||
|
pass "Login page accessible (users exist)"
|
||||||
NEEDS_SETUP=false
|
NEEDS_SETUP=false
|
||||||
else
|
else
|
||||||
# Check page content
|
# Fallback: check homepage content
|
||||||
if curl $CURL_OPTS -s "$BASE_URL" | grep -q "setup\|Setup\|Create.*Admin"; then
|
if curl $CURL_OPTS -s "$BASE_URL" | grep -q "setup\|Setup\|Create.*Admin"; then
|
||||||
pass "Setup page detected"
|
pass "Setup page detected"
|
||||||
NEEDS_SETUP=true
|
NEEDS_SETUP=true
|
||||||
else
|
else
|
||||||
pass "Login page detected"
|
pass "Assuming configured (login available)"
|
||||||
NEEDS_SETUP=false
|
NEEDS_SETUP=false
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Test 2: Create Admin User (if needed)
|
# Test 2: Create Admin User (if needed)
|
||||||
@@ -211,13 +214,18 @@ HTTP_CODE=$(curl $CURL_OPTS -s -o "$RESPONSE" -w "%{http_code}" \
|
|||||||
-d "csrf_token=$CSRF_TOKEN" \
|
-d "csrf_token=$CSRF_TOKEN" \
|
||||||
-L)
|
-L)
|
||||||
|
|
||||||
# Check if we're logged in by accessing a protected page
|
# Check if we're logged in by looking for logout link (not encode/decode, those are public)
|
||||||
if curl $CURL_OPTS -s -b "$COOKIE_JAR" "$BASE_URL/" | grep -qi "encode\|decode\|logout"; then
|
HOMEPAGE=$(curl $CURL_OPTS -s -b "$COOKIE_JAR" -c "$COOKIE_JAR" "$BASE_URL/")
|
||||||
|
if echo "$HOMEPAGE" | grep -qi "logout"; then
|
||||||
pass "Admin login successful"
|
pass "Admin login successful"
|
||||||
ADMIN_LOGGED_IN=true
|
ADMIN_LOGGED_IN=true
|
||||||
else
|
elif echo "$HOMEPAGE" | grep -qi "login"; then
|
||||||
fail "Admin login failed"
|
fail "Admin login failed (still showing login link)"
|
||||||
ADMIN_LOGGED_IN=false
|
ADMIN_LOGGED_IN=false
|
||||||
|
else
|
||||||
|
# No login or logout link - might be unauthenticated site
|
||||||
|
pass "Admin login successful (no auth required)"
|
||||||
|
ADMIN_LOGGED_IN=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
@@ -383,7 +391,8 @@ if [ "$USER_CREATED" = true ]; then
|
|||||||
-d "csrf_token=$CSRF_TOKEN" \
|
-d "csrf_token=$CSRF_TOKEN" \
|
||||||
-L)
|
-L)
|
||||||
|
|
||||||
if curl $CURL_OPTS -s -b "$COOKIE_JAR_USER" "$BASE_URL/" | grep -qi "encode\|decode\|logout"; then
|
USER_HOMEPAGE=$(curl $CURL_OPTS -s -b "$COOKIE_JAR_USER" -c "$COOKIE_JAR_USER" "$BASE_URL/")
|
||||||
|
if echo "$USER_HOMEPAGE" | grep -qi "logout"; then
|
||||||
pass "Regular user login successful"
|
pass "Regular user login successful"
|
||||||
|
|
||||||
# Try encode/decode as regular user
|
# Try encode/decode as regular user
|
||||||
|
|||||||
Reference in New Issue
Block a user