Skip to content

Commit 4a2d686

Browse files
committed
Create a new Github action to test the web-based installer.
1 parent 89243b1 commit 4a2d686

File tree

1 file changed

+191
-0
lines changed

1 file changed

+191
-0
lines changed
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
name: Test WebCalendar Web-Based Installer
2+
3+
on:
4+
push:
5+
branches: [ master, release ]
6+
pull_request:
7+
release:
8+
types: [ published ]
9+
10+
jobs:
11+
web_installation:
12+
name: Test WebCalendar web-based installer with SQLite
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check out the repo
16+
uses: actions/checkout@v4
17+
18+
- name: Set up PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: '8.1' # Use PHP 8.1 for sqlite3 support
22+
extensions: sqlite3, pdo_sqlite # sqlite3 is sufficient
23+
tools: none # No Composer needed
24+
ini-values: display_errors=On, error_reporting=E_ALL # Enable error reporting
25+
26+
- name: Create SQLite database
27+
run: |
28+
mkdir -p database
29+
sqlite3 database/webcalendar.sqlite "VACUUM;" # Create empty SQLite DB
30+
ls -l database/webcalendar.sqlite # Debug: Verify DB file
31+
32+
- name: Create settings.php from settings.php.orig
33+
run: |
34+
cp includes/settings.php.orig includes/settings.php
35+
sed -i 's|db_type:.*|db_type: sqlite3|' includes/settings.php
36+
sed -i 's|db_database:.*|db_database: ../database/webcalendar.sqlite|' includes/settings.php
37+
sed -i 's|db_host:.*|db_host: localhost|' includes/settings.php
38+
sed -i 's|db_login:.*|db_login: ""|' includes/settings.php
39+
sed -i 's|db_password:.*|db_password: ""|' includes/settings.php
40+
sed -i 's|install_password:.*|install_password: test123|' includes/settings.php
41+
sed -i 's|single_user:.*|single_user: false|' includes/settings.php
42+
sed -i 's|use_http_auth:.*|use_http_auth: false|' includes/settings.php
43+
sed -i 's|user_inc:.*|user_inc: user.php|' includes/settings.php
44+
echo "CSRF_PROTECTION: N" >> includes/settings.php # Disable CSRF for installer
45+
cat includes/settings.php # Debug: Show settings.php
46+
47+
- name: Verify required files
48+
run: |
49+
ls -l install/sql/tables-sqlite3.php || { echo "Missing tables-sqlite3.php"; exit 1; }
50+
ls -l install/headless.php || { echo "Missing headless.php"; exit 1; }
51+
ls -l includes/dbi4php.php || { echo "Missing dbi4php.php"; exit 1; }
52+
ls -l includes/translate.php || { echo "Missing translate.php"; exit 1; }
53+
ls -l install/default_config.php || { echo "Missing default_config.php"; exit 1; }
54+
ls -l install/install_functions.php || { echo "Missing install_functions.php"; exit 1; }
55+
ls -l install/sql/upgrade_matrix.php || { echo "Missing upgrade_matrix.php"; exit 1; }
56+
57+
- name: Start PHP server
58+
run: |
59+
php -S localhost:8000 -t . > php_server.log 2>&1 &
60+
sleep 5 # Wait for server to start
61+
62+
- name: Run web-based installer with cURL
63+
run: |
64+
COOKIE_JAR=cookies.txt
65+
touch $COOKIE_JAR
66+
67+
# Step 1: GET install/index.php to start installer and capture CSRF token
68+
RESPONSE=$(curl -s -c $COOKIE_JAR -b $COOKIE_JAR http://localhost:8000/install/index.php -o step1_response.html)
69+
CSRF_TOKEN=$(grep -oP 'name="csrf_form_key" value="\K[^"]+' step1_response.html || echo "")
70+
if [ -z "$CSRF_TOKEN" ]; then
71+
echo "Error: Could not extract CSRF token from install/index.php"
72+
cat step1_response.html
73+
cat php_server.log
74+
exit 1
75+
fi
76+
echo "Extracted CSRF token: $CSRF_TOKEN"
77+
78+
# Step 2: POST to welcome/action (assuming it's the first form)
79+
http_code=$(curl -s -c $COOKIE_JAR -b $COOKIE_JAR -o step2_response.html -w "%{http_code}" -X POST http://localhost:8000/install/index.php -d "action=welcome&csrf_form_key=$CSRF_TOKEN")
80+
if [ "$http_code" != "302" ]; then
81+
echo "Failed welcome step, expected HTTP 302, got $http_code"
82+
cat step2_response.html
83+
cat php_server.log
84+
exit 1
85+
fi
86+
87+
# Step 3: POST to phpsettings/action
88+
RESPONSE=$(curl -s -c $COOKIE_JAR -b $COOKIE_JAR http://localhost:8000/install/index.php?action=phpsettings -o step3_response.html)
89+
CSRF_TOKEN=$(grep -oP 'name="csrf_form_key" value="\K[^"]+' step3_response.html || echo "")
90+
http_code=$(curl -s -c $COOKIE_JAR -b $COOKIE_JAR -o step3_response.html -w "%{http_code}" -X POST http://localhost:8000/install/index.php -d "action=phpsettings&csrf_form_key=$CSRF_TOKEN")
91+
if [ "$http_code" != "302" ]; then
92+
echo "Failed phpsettings step, expected HTTP 302, got $http_code"
93+
cat step3_response.html
94+
cat php_server.log
95+
exit 1
96+
fi
97+
98+
# Step 4: POST to appsettings/action
99+
RESPONSE=$(curl -s -c $COOKIE_JAR -b $COOKIE_JAR http://localhost:8000/install/index.php?action=appsettings -o step4_response.html)
100+
CSRF_TOKEN=$(grep -oP 'name="csrf_form_key" value="\K[^"]+' step4_response.html || echo "")
101+
http_code=$(curl -s -c $COOKIE_JAR -b $COOKIE_JAR -o step4_response.html -w "%{http_code}" -X POST http://localhost:8000/install/index.php -d "action=appsettings&user_inc=user.php&csrf_form_key=$CSRF_TOKEN")
102+
if [ "$http_code" != "302" ]; then
103+
echo "Failed appsettings step, expected HTTP 302, got $http_code"
104+
cat step4_response.html
105+
cat php_server.log
106+
exit 1
107+
fi
108+
109+
# Step 5: POST to dbsettings/action (main DB config, simulate AJAX test)
110+
RESPONSE=$(curl -s -c $COOKIE_JAR -b $COOKIE_JAR http://localhost:8000/install/index.php?action=dbsettings -o step5_response.html)
111+
CSRF_TOKEN=$(grep -oP 'name="csrf_form_key" value="\K[^"]+' step5_response.html || echo "")
112+
# Simulate AJAX DB test (optional, but to mimic)
113+
ajax_code=$(curl -s -c $COOKIE_JAR -b $COOKIE_JAR -o ajax_response.json -w "%{http_code}" -X POST http://localhost:8000/install/install_ajax.php -d "dbType=sqlite3&server=localhost&login=&password=&dbName=../database/webcalendar.sqlite&dbCacheDir=&request=test-db-connection&csrf_form_key=$CSRF_TOKEN")
114+
if [ "$ajax_code" != "200" ]; then
115+
echo "Failed AJAX DB test, expected HTTP 200, got $ajax_code"
116+
cat ajax_response.json
117+
cat php_server.log
118+
exit 1
119+
fi
120+
# Submit DB config form
121+
http_code=$(curl -s -c $COOKIE_JAR -b $COOKIE_JAR -o step5_response.html -w "%{http_code}" -X POST http://localhost:8000/install/index.php -d "action=dbsettings&db_type=sqlite3&db_host=localhost&db_login=&db_password=&db_database=../database/webcalendar.sqlite&db_cachedir=&db_debug=N&csrf_form_key=$CSRF_TOKEN")
122+
if [ "$http_code" != "302" ]; then
123+
echo "Failed dbsettings step, expected HTTP 302, got $http_code"
124+
cat step5_response.html
125+
cat php_server.log
126+
exit 1
127+
fi
128+
129+
# Step 6: POST to createdb/action
130+
RESPONSE=$(curl -s -c $COOKIE_JAR -b $COOKIE_JAR http://localhost:8000/install/index.php?action=createdb -o step6_response.html)
131+
CSRF_TOKEN=$(grep -oP 'name="csrf_form_key" value="\K[^"]+' step6_response.html || echo "")
132+
http_code=$(curl -s -c $COOKIE_JAR -b $COOKIE_JAR -o step6_response.html -w "%{http_code}" -X POST http://localhost:8000/install/index.php -d "action=createdb&csrf_form_key=$CSRF_TOKEN")
133+
if [ "$http_code" != "302" ]; then
134+
echo "Failed createdb step, expected HTTP 302, got $http_code"
135+
cat step6_response.html
136+
cat php_server.log
137+
exit 1
138+
fi
139+
140+
# Step 7: POST to dbtables/action
141+
RESPONSE=$(curl -s -c $COOKIE_JAR -b $COOKIE_JAR http://localhost:8000/install/index.php?action=dbtables -o step7_response.html)
142+
CSRF_TOKEN=$(grep -oP 'name="csrf_form_key" value="\K[^"]+' step7_response.html || echo "")
143+
http_code=$(curl -s -c $COOKIE_JAR -b $COOKIE_JAR -o step7_response.html -w "%{http_code}" -X POST http://localhost:8000/install/index.php -d "action=dbtables&csrf_form_key=$CSRF_TOKEN")
144+
if [ "$http_code" != "302" ]; then
145+
echo "Failed dbtables step, expected HTTP 302, got $http_code"
146+
cat step7_response.html
147+
cat php_server.log
148+
exit 1
149+
fi
150+
151+
# Step 8: POST to adminuser/action
152+
RESPONSE=$(curl -s -c $COOKIE_JAR -b $COOKIE_JAR http://localhost:8000/install/index.php?action=adminuser -o step8_response.html)
153+
CSRF_TOKEN=$(grep -oP 'name="csrf_form_key" value="\K[^"]+' step8_response.html || echo "")
154+
http_code=$(curl -s -c $COOKIE_JAR -b $COOKIE_JAR -o step8_response.html -w "%{http_code}" -X POST http://localhost:8000/install/index.php -d "action=adminuser&csrf_form_key=$CSRF_TOKEN")
155+
if [ "$http_code" != "302" ]; then
156+
echo "Failed adminuser step, expected HTTP 302, got $http_code"
157+
cat step8_response.html
158+
cat php_server.log
159+
exit 1
160+
fi
161+
162+
# Step 9: GET finish page
163+
finish_code=$(curl -s -L -b $COOKIE_JAR -c $COOKIE_JAR -o step9_response.html -w "%{http_code}" http://localhost:8000/install/index.php?action=finish)
164+
if [ "$finish_code" != "200" ]; then
165+
echo "Failed finish step, expected HTTP 200, got $finish_code"
166+
cat step9_response.html
167+
cat php_server.log
168+
exit 1
169+
fi
170+
if ! grep -qi "Launch WebCalendar" step9_response.html; then
171+
echo "Error: finish page does not contain expected content"
172+
cat step9_response.html
173+
cat php_server.log
174+
exit 1
175+
fi
176+
echo "Web-based installer completed successfully"
177+
178+
- name: Verify database installation
179+
run: |
180+
# Check if core tables exist
181+
sqlite3 database/webcalendar.sqlite "SELECT name FROM sqlite_master WHERE type='table' AND name='webcal_config';" | grep webcal_config
182+
sqlite3 database/webcalendar.sqlite "SELECT name FROM sqlite_master WHERE type='table' AND name='webcal_entry';" | grep webcal_entry
183+
sqlite3 database/webcalendar.sqlite "SELECT name FROM sqlite_master WHERE type='table' AND name='webcal_user';" | grep webcal_user
184+
# Verify version in database
185+
sqlite3 database/webcalendar.sqlite "SELECT cal_value FROM webcal_config WHERE cal_setting='WEBCAL_PROGRAM_VERSION';" | grep -E 'v[0-9]+\.[0-9]+\.[0-9]+'
186+
# Debug admin user password
187+
sqlite3 database/webcalendar.sqlite "SELECT cal_login, cal_passwd FROM webcal_user WHERE cal_login='admin';" || { echo "Failed to query webcal_user"; exit 1; }
188+
189+
- name: Clean up
190+
run: |
191+
kill $(pgrep -f "php -S localhost:8000") || true

0 commit comments

Comments
 (0)