wait_for "$SCRATCH/legacy.log""Started RunwayApplication"90||{echo"ACTIVE did not start"; tail -20 "$SCRATCH/legacy.log";exit 1;}
wait_for "$SCRATCH/legacy.log""database: not configured"30
stop_host
echo"== 1.x settings =="
ck "reported as moved to the provider plugin""grep -q 'not configured: the server settings moved to the database-$PROVIDER plugin' '$SCRATCH/legacy.log'"
ck "never used to connect""! grep -q 'database: connected to' '$SCRATCH/legacy.log'"
# 2.0.0 layout. Both providers are installed, so the database plugin names one (auto would ask which). A hand-written
# plaintext password works like an encrypted one; these files are deleted with the scratch folder.
ck "ZERO bean-name/surface findings""! grep -qE \"plugin 'database[a-z-]*'.*(bean name|may not contribute)\" '$LOG'"
ck "no missing class""! grep -qiE 'NoClassDefFound|ClassNotFound' '$LOG'"
ck "HikariCP and the drivers are in lib/""ls '$EXT/plugins/database/lib/'HikariCP-*.jar '$EXT/plugins/database-postgresql/lib/'postgresql-*.jar '$EXT/plugins/database-mariadb/lib/'mariadb-java-client-*.jar"
echo"== connection =="
ck "connected after startup, on its own thread""grep -E 'database: connected to' '$LOG' | grep -qv '\\[main\\]'"
ck "the screen points to the settings page""grep -q '/__app/plugins/database/settings#db-tests' '$SCRATCH/screen.html'"
ck "the screen has no test form any more""! grep -qE 'test-new|type=\"password\"' '$SCRATCH/screen.html'"
ck "the 1.x typed test is gone""[ \"\$(ac -o /dev/null -w '%{http_code}' -X POST '$BASE/__app/database/test-new' --data-urlencode '_csrf=$(token < "$SCRATCH/screen.html")')\" != 302 ]"
echo"== settings pages =="
ac "$BASE/__app/plugins/database/settings" > "$SCRATCH/settings.html"
ck "the database page has the provider choice""grep -q 'name=\"provider\"' '$SCRATCH/settings.html'"
ck "the database page has no server fields""! grep -qE 'name=\"(host|username|password)\"' '$SCRATCH/settings.html'"
ck "the connection tests are below its form""grep -q 'id=\"db-tests\"' '$SCRATCH/settings.html' && grep -q 'Test the saved $PRODUCT settings' '$SCRATCH/settings.html'"
ck "the panel shows the running status""grep -q 'Running now:' '$SCRATCH/settings.html' && grep -q 'Connected\\.' '$SCRATCH/settings.html'"
ac "$BASE/__app/plugins/database-$PROVIDER/settings" > "$SCRATCH/provider.html"
ck "the provider page holds the server""grep -q 'value=\"$DB_HOST\"' '$SCRATCH/provider.html' && grep -q 'name=\"username\"' '$SCRATCH/provider.html'"
ck "its password box is never autofilled""grep -q 'autocomplete=\"new-password\"' '$SCRATCH/provider.html' && ! grep -q 'type=\"password\"[^>]*autocomplete=\"off\"' '$SCRATCH/provider.html'"
ck "the pages hold no password""! grep -qF -- '$DB_PASSWORD' '$SCRATCH/provider.html' '$SCRATCH/settings.html'"
if["$PROVIDER"= mariadb ];then
ck "collation is on the MariaDB page only""grep -q 'name=\"collation\"' '$SCRATCH/provider.html' && ! grep -q 'name=\"collation\"' '$SCRATCH/settings.html'"
fi
CSRF="$(token < "$SCRATCH/settings.html")"
ac -L "$BASE/__app/database/test-running" --data-urlencode "_csrf=$CSRF" > "$SCRATCH/tested.html"
ck "Test the running connection: connected""grep -qE 'Connected: (PostgreSQL|MariaDB)' '$SCRATCH/tested.html' && grep -q 'id=\"db-tests\"' '$SCRATCH/tested.html'"
ac -L "$BASE/__app/database/test-saved" --data-urlencode "_csrf=$CSRF" --data-urlencode "provider=$PROVIDER" > "$SCRATCH/saved.html"
ck "Test the saved settings: connected""grep -qE 'Connected: $PRODUCT' '$SCRATCH/saved.html'"
# Save a wrong password after startup, as the provider's form would (only a restart would apply it): the saved test
# reads the file as it is now, and the running connection is untouched.
sed -i 's/^ password: .*/ password: "not-the-password"/'"$EXT/plugin-settings/database-$PROVIDER.yml"
ac -L "$BASE/__app/database/test-saved" --data-urlencode "_csrf=$CSRF" --data-urlencode "provider=$PROVIDER" > "$SCRATCH/saved2.html"
ck "a wrong saved password is refused""grep -q 'The server refused the username or password.' '$SCRATCH/saved2.html'"
ck "the running connection is untouched""grep -q 'Connected\\.' '$SCRATCH/saved2.html'"
ac -L "$BASE/__app/database/test-saved" --data-urlencode "_csrf=$CSRF" --data-urlencode "provider=oracle" > "$SCRATCH/saved3.html"
ck "an unknown provider is answered, not tested""grep -q 'is not installed' '$SCRATCH/saved3.html'"
ck "a POST without the CSRF token is refused""[ \"\$(code -b '$SCRATCH/app.jar' -X POST '$BASE/__app/database/test-saved')\" = 403 ]"
# With the site session's own CSRF token, so a refusal comes from the permission gate, not from a missing token.
SITE_CSRF="$(sc "$BASE/__admin"| token)"
ck "nor test the saved settings""[ \"\$(code -b '$SCRATCH/site.jar' -X POST --data-urlencode '_csrf=$SITE_CSRF' --data-urlencode 'provider=$PROVIDER' '$BASE/__app/database/test-saved')\" != 302 ]"