Skip to content

Move test database properties to test resources#3628

Draft
duanemay wants to merge 5 commits into
developfrom
fix/test_props
Draft

Move test database properties to test resources#3628
duanemay wants to merge 5 commits into
developfrom
fix/test_props

Conversation

@duanemay

@duanemay duanemay commented Sep 19, 2025

Copy link
Copy Markdown
Member

What

application-mysql.properties/application-postgresql.properties in server/src/main/resources shipped hardcoded database.username=root/database.password=changeme/a 127.0.0.1/local JDBC URL — these look like local test/dev fixtures, not production defaults, and end up packaged into the WAR. This moves those values into src/test/resources (kept for the test suite, which needs them), leaving only database.driverClassName in the packaged application-mysql.properties/application-postgresql.properties.

This is not a fix for an exploitable default: UAA falls back to the hsqldb profile with zero configuration (YamlServletProfileInitializer.applySpringProfiles), so these values are only ever read if an operator explicitly activates the mysql/postgresql profile. It's hygiene — don't ship plausible-looking credentials in the production artifact.

Follow-up fix included

Removing these from src/main/resources broke three local/CI flows that relied on them being present in the packaged artifact when the mysql/postgresql profile is active, with no other credentials supplied:

  • ./gradlew run / bootRun with -Dspring.profiles.active=postgresql or mysql (documented in README.md)
  • the embedded integrationTest auto-start (java -jar launch in uaa/build.gradle.kts)
  • CI's external-Tomcat integration test matrix (scripts/tomcat/integration_tests_tomcat.sh, .github/workflows/integration-tests.yml, mysql/postgresql matrix)

All three now supply the same root/changeme local-dev credentials via explicit -D system properties (still overridable) instead of relying on the packaged properties files. Verified by running bootRun -Dspring.profiles.active=postgresql against a real local Postgres — UAA started and Flyway created all tables as expected.

Test plan

  • ./gradlew :cloudfoundry-identity-uaa:bootRun -Dspring.profiles.active=postgresql -Ddatabase.url=jdbc:postgresql://localhost:5433/uaa against a local Postgres with a root/changeme superuser — UAA started, Flyway created all 16 tables
  • shellcheck scripts/tomcat/integration_tests_tomcat.sh — no new findings
  • CI mysql/postgresql integration test matrix (this PR)

@fhanik

fhanik commented Nov 13, 2025

Copy link
Copy Markdown
Contributor

rebased on develop branch

duanemay added 2 commits July 13, 2026 11:40
…tion tests

application-mysql.properties/application-postgresql.properties no longer ship
database.username/password/url, since those are packaged into the WAR. bootRun,
the embedded integrationTest auto-start, and the CI external-Tomcat integration
tests (scripts/tomcat/integration_tests_tomcat.sh) all relied on those defaults
to reach the root/changeme database that lib_db_helper.sh boots locally/in CI.
Supply the same values via -D system properties instead, so those flows keep
working without reintroducing the credentials into the shipped artifact.
duanemay added 3 commits July 13, 2026 12:47
Gradle's gradle.taskGraph.whenReady block only forwarded spring.profiles.active,
testId, and zones.paths.enabled into forked Test-task JVMs; arbitrary -D flags
passed on the command line (e.g. -Ddatabase.username) are never propagated to a
forked test JVM automatically. Once application-mysql.properties/application-
postgresql.properties stopped shipping database.username/password/url, any test
that builds a DatabaseConfiguration context (e.g. ClientAdminBootstrapProdEncoderTest)
under the mysql/postgresql profile got a null database URL and failed to create a
DataSource. Forward the same root/changeme local-dev credentials used for
bootRun/integrationTest/CI Tomcat into every Test task's active profile. Also
apply the same fix to bootWarRun for consistency.

Verified locally against a real Postgres: ClientAdminBootstrapProdEncoderTest now
passes under -Dspring.profiles.active=postgresql, reproducing and fixing the CI
db-integration-test/tomcat-integration-test failures on PR #3628.
The previous commit forwarded database.username/password/url into every Test
task, but the plain `test` task includes tests (DatabasePropertiesTest,
YamlServletProfileInitializerTest) that deliberately exercise their own
per-profile/custom database property fixtures (e.g. hsqldb's "sa" default, a
mysql URL pattern, a custom "donkey" YAML value). Since JVM system properties
take precedence over everything else in Spring's Environment, the blanket
override clobbered those fixtures and broke db-unit-test in CI. Restrict the
override to the integrationTest task, which is the one that actually needs it
(it connects to a real external mysql/postgresql with no per-test property
source of its own).

Verified locally: DatabasePropertiesTest and YamlServletProfileInitializerTest
pass again under -Dspring.profiles.active=postgresql, the full
:cloudfoundry-identity-server:test suite passes (4819/4820, the one failure is
an unrelated collation/locale artifact of the local Postgres install), and
ClientAdminBootstrapProdEncoderTest still passes under integrationTest.
…ncher

The mysql JDBC URL contains an unescaped & (...useSSL=true&trustServerCertificate=true).
The doFirst block builds a raw command string passed straight to `bash -c`, which
parses it fresh (unlike the CATALINA_OPTS case in integration_tests_tomcat.sh, where
the same value only ever appears via variable expansion, so control-operator lexing
doesn't apply). An unquoted & there is lexed as a background-job operator, splitting
the command mid-argument and silently truncating the java -jar invocation, which is
why db-integration-test (mysql-8.0/8.4/9) kept failing to start UAA within 300s while
the postgresql matrix (no & in its URL) passed. Single-quote each -D value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants