Skip to content

Commit 538386b

Browse files
committed
check
1 parent 0f82544 commit 538386b

File tree

4 files changed

+254
-2
lines changed

4 files changed

+254
-2
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Build and Test
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
pull_request:
7+
branches: [ main, master ]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up JDK 17
18+
uses: actions/setup-java@v5
19+
with:
20+
java-version: '17'
21+
distribution: 'temurin'
22+
23+
- name: Cache Maven dependencies
24+
uses: actions/cache@v3
25+
with:
26+
path: ~/.m2
27+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
28+
restore-keys: ${{ runner.os }}-m2
29+
30+
- name: Run build and test
31+
run: |
32+
cd ci
33+
chmod +x run_and_check.sh
34+
./run_and_check.sh
35+
36+
- name: Upload test logs
37+
if: failure()
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: server-logs
41+
path: target/app.log

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ test-output/
66
bin/
77
*.iml
88
.idea
9-
sp-metadata.xml
9+
sp-metadata.xml
10+
.vscode/

ci/run_and_check.sh

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
#!/bin/bash
2+
3+
# Script to launch spring-webflux-pac4j-boot-demo and verify it works
4+
# Usage: ./run_and_check.sh
5+
6+
set -e # Stop script on error
7+
8+
echo "🚀 Starting spring-webflux-pac4j-boot-demo..."
9+
10+
# Go to project directory (one level up from ci/)
11+
cd ..
12+
13+
# Clean and compile project (package jar)
14+
echo "📦 Compiling project..."
15+
mvn clean package -q
16+
17+
# Ensure target directory exists
18+
mkdir -p target
19+
20+
# Start Spring Boot jar in background
21+
JAR="target/spring-webflux-pac4j-boot-demo.jar"
22+
if [ ! -f "$JAR" ]; then
23+
# In case the finalName differs, try to find the produced boot jar
24+
JAR=$(ls -1 target/*-SNAPSHOT.jar 2>/dev/null | head -n1)
25+
if [ -z "$JAR" ]; then
26+
JAR=$(ls -1 target/*.jar 2>/dev/null | head -n1)
27+
fi
28+
fi
29+
30+
if [ ! -f "$JAR" ]; then
31+
echo "❌ Could not locate a built jar in target/." >&2
32+
ls -la target || true
33+
exit 1
34+
fi
35+
36+
echo "🌐 Starting Spring Boot application ($JAR)..."
37+
java -jar "$JAR" > target/app.log 2>&1 &
38+
APP_PID=$!
39+
40+
# Wait for server to start (maximum 60 seconds)
41+
echo "⏳ Waiting for server startup..."
42+
for i in {1..60}; do
43+
if curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 | grep -q "200"; then
44+
echo "✅ Server started successfully!"
45+
break
46+
fi
47+
if [ $i -eq 60 ]; then
48+
echo "❌ Timeout: Server did not start within 60 seconds"
49+
echo "📋 Server logs:"
50+
cat target/app.log || true
51+
kill $APP_PID 2>/dev/null || true
52+
exit 1
53+
fi
54+
sleep 1
55+
done
56+
57+
# Verify application responds correctly
58+
echo "🔍 Verifying HTTP response..."
59+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080)
60+
61+
if [ "$HTTP_CODE" = "200" ]; then
62+
echo "✅ Application responds with HTTP 200"
63+
echo "🌐 Application accessible at: http://localhost:8080"
64+
65+
# Default flags
66+
CAS_AUTH_PASSED=false
67+
68+
# Test clicking on casLink and following redirections to CAS login page
69+
echo "🔗 Testing casLink redirection to CAS login page..."
70+
71+
# Get the casLink URL from the homepage
72+
CASLINK_URL="http://localhost:8080/cas/index.html"
73+
echo "📍 Following casLink: $CASLINK_URL"
74+
75+
# Follow redirections and capture final URL and response
76+
CAS_RESPONSE=$(curl -s -L -w "FINAL_URL:%{url_effective}\nHTTP_CODE:%{http_code}" "$CASLINK_URL")
77+
CAS_HTTP_CODE=$(echo "$CAS_RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2)
78+
CAS_FINAL_URL=$(echo "$CAS_RESPONSE" | grep "FINAL_URL:" | cut -d: -f2-)
79+
CAS_CONTENT=$(echo "$CAS_RESPONSE" | sed '/^FINAL_URL:/d' | sed '/^HTTP_CODE:/d')
80+
81+
echo "🌐 Final URL: $CAS_FINAL_URL"
82+
echo "📄 HTTP Code: $CAS_HTTP_CODE"
83+
84+
# Verify we reached the CAS login page
85+
if [ "$CAS_HTTP_CODE" = "200" ] && echo "$CAS_CONTENT" | grep -q "Enter Username & Password"; then
86+
echo "✅ CAS login page test passed!"
87+
echo "🔐 Successfully redirected to CAS login page"
88+
echo "📋 Page contains login form with username/password fields"
89+
CAS_TEST_PASSED=true
90+
91+
# Simulate a CAS login using curl WITH cookies and follow redirects; then show final page content
92+
echo "🧪 Simulating CAS authentication via curl (with cookies, follow redirects)..."
93+
COOKIE_JAR="target/cas_cookies.txt"
94+
CAS_LOGIN_PAGE="target/cas_login.html"
95+
CAS_AFTER_LOGIN="target/cas_after_login.html"
96+
FINAL_APP_PAGE="target/final_app.html"
97+
98+
# 1) Fetch the login page (keep cookies) and capture the execution token
99+
echo "⬇️ Fetching CAS login page and capturing execution token..."
100+
curl -s -c "$COOKIE_JAR" -b "$COOKIE_JAR" -L "$CAS_FINAL_URL" -o "$CAS_LOGIN_PAGE" -w "FINAL_URL:%{url_effective}\nHTTP_CODE:%{http_code}\n" > target/cas_login_fetch.meta
101+
102+
EXECUTION=$(grep -Eo 'name=\"execution\"[^>]*value=\"[^\"]+\"' "$CAS_LOGIN_PAGE" | sed -E 's/.*value=\"([^\"]+)\".*/\1/' | head -n1 || true)
103+
104+
if [ -z "$EXECUTION" ]; then
105+
echo "❌ Could not extract CAS execution token from login page."
106+
echo " Saved page: $CAS_LOGIN_PAGE"
107+
CAS_AUTH_PASSED=false
108+
else
109+
echo "🔑 Found execution token: $EXECUTION"
110+
111+
# 2) Post credentials to CAS with cookies and follow redirects (do NOT send service explicitly)
112+
echo "📤 Posting credentials to CAS and following redirects..."
113+
CAS_POST_RESPONSE=$(curl -s -c "$COOKIE_JAR" -b "$COOKIE_JAR" -L -o "$CAS_AFTER_LOGIN" -w "FINAL_URL:%{url_effective}\nHTTP_CODE:%{http_code}" \
114+
--data-urlencode "username=leleuj@gmail.com" \
115+
--data-urlencode "password=password" \
116+
--data-urlencode "execution=$EXECUTION" \
117+
--data-urlencode "_eventId=submit" \
118+
"$CAS_FINAL_URL")
119+
120+
CAS_POST_HTTP_CODE=$(echo "$CAS_POST_RESPONSE" | grep "HTTP_CODE:" | cut -d: -f2)
121+
CAS_POST_FINAL_URL=$(echo "$CAS_POST_RESPONSE" | grep "FINAL_URL:" | cut -d: -f2-)
122+
123+
echo "🌐 After login final URL: $CAS_POST_FINAL_URL"
124+
echo "📄 HTTP Code: $CAS_POST_HTTP_CODE"
125+
126+
# 3) Fetch the application page after CAS login with cookies and show content
127+
echo "📥 Fetching final app page content..."
128+
TARGET_URL="$CAS_POST_FINAL_URL"
129+
# In WebFlux, the callback may be the last URL. If so, request a protected page explicitly.
130+
if echo "$TARGET_URL" | grep -q "/callback"; then
131+
TARGET_URL="http://localhost:8080/protected/index.html"
132+
fi
133+
FINAL_META=$(curl -s -c "$COOKIE_JAR" -b "$COOKIE_JAR" -L -o "$FINAL_APP_PAGE" -w "FINAL_URL:%{url_effective}\nHTTP_CODE:%{http_code}" "$TARGET_URL")
134+
FINAL_URL=$(echo "$FINAL_META" | grep "FINAL_URL:" | cut -d: -f2-)
135+
FINAL_APP_CODE=$(echo "$FINAL_META" | grep "HTTP_CODE:" | cut -d: -f2)
136+
137+
echo "🌐 Final app URL after redirects: $FINAL_URL"
138+
echo "📄 Final app HTTP Code: $FINAL_APP_CODE"
139+
140+
if [ "$FINAL_APP_CODE" = "200" ]; then
141+
echo "✅ Demo reachable after CAS login (HTTP 200)"
142+
CAS_AUTH_PASSED=true
143+
echo "----- Final page content (begin) -----"
144+
cat "$FINAL_APP_PAGE"
145+
echo "\n----- Final page content (end) -----"
146+
147+
# Verify that the expected authenticated email is present in the page
148+
if grep -q "leleuj@gmail.com" "$FINAL_APP_PAGE"; then
149+
echo "✅ Email 'leleuj@gmail.com' found in final page content"
150+
else
151+
echo "❌ Email 'leleuj@gmail.com' NOT found in final page content"
152+
CAS_AUTH_PASSED=false
153+
fi
154+
else
155+
echo "❌ Demo not reachable after CAS login (HTTP $FINAL_APP_CODE)"
156+
CAS_AUTH_PASSED=false
157+
fi
158+
fi
159+
160+
else
161+
echo "❌ CAS login page test failed!"
162+
echo "🚫 Expected CAS login page but got:"
163+
echo " HTTP Code: $CAS_HTTP_CODE"
164+
echo " Final URL: $CAS_FINAL_URL"
165+
if [ ${#CAS_CONTENT} -lt 500 ]; then
166+
echo " Content preview: $CAS_CONTENT"
167+
else
168+
echo " Content preview: $(echo "$CAS_CONTENT" | head -c 500)..."
169+
fi
170+
CAS_TEST_PASSED=false
171+
CAS_AUTH_PASSED=false
172+
fi
173+
else
174+
echo "❌ Initial test failed! HTTP code received: $HTTP_CODE"
175+
echo "📋 Server logs:"
176+
cat target/app.log || true
177+
CAS_TEST_PASSED=false
178+
CAS_AUTH_PASSED=false
179+
fi
180+
181+
# Always stop the server
182+
echo "🛑 Stopping server..."
183+
kill $APP_PID 2>/dev/null || true
184+
185+
# Wait a moment for graceful shutdown
186+
sleep 2
187+
188+
# Force kill if still running
189+
kill -9 $APP_PID 2>/dev/null || true
190+
191+
if [ "$HTTP_CODE" = "200" ] && [ "$CAS_TEST_PASSED" = "true" ] && [ "$CAS_AUTH_PASSED" = "true" ]; then
192+
echo "🎉 spring-webflux-pac4j-boot-demo test completed successfully!"
193+
echo "✅ All tests passed:"
194+
echo " - Application responds with HTTP 200"
195+
echo " - CAS link redirects correctly to login page"
196+
echo " - CAS login succeeds and demo is reachable"
197+
exit 0
198+
else
199+
echo "💥 spring-webflux-pac4j-boot-demo test failed!"
200+
if [ "$HTTP_CODE" != "200" ]; then
201+
echo "❌ Application HTTP test failed (code: $HTTP_CODE)"
202+
fi
203+
if [ "$CAS_TEST_PASSED" != "true" ]; then
204+
echo "❌ CAS redirection test failed"
205+
fi
206+
if [ "$CAS_AUTH_PASSED" != "true" ]; then
207+
echo "❌ CAS authentication/redirect to demo failed"
208+
fi
209+
exit 1
210+
fi

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>org.springframework.boot</groupId>
2525
<artifactId>spring-boot-starter-parent</artifactId>
26-
<version>3.5.6</version>
26+
<version>2.7.6</version>
2727
</parent>
2828

2929
<properties>

0 commit comments

Comments
 (0)