testcontainers-java
testcontainers-java copied to clipboard
Add support to configure system password for Oracle database
…; fix ORACLE_PASSWORD mapping
Introduce an independent system user password for Oracle containers and map it correctly to the ORACLE_PASSWORD env.
- Add withOraclePassword(String) to configure SYSTEM/SYS password independently from the app user password
- Use system password in SID connections (getPassword returns system password in SID mode)
- Keep backward compatibility: withPassword also sets system password unless withOraclePassword was called
- Update Oracle XE and Oracle Free containers to use the new internal oraclePassword
- Add OracleContainerTest to verify system vs app password behavior in SID and non-SID modes
This resolves the issue where ORACLE_PASSWORD was effectively bound to the app user password, making it impossible to set the system user password correctly.
Summary
Fix Oracle container password handling so ORACLE_PASSWORD configures the system user (SYSTEM/SYS) password, not the app user’s password. Add withOraclePassword(String) to configure it independently while keeping backward compatibility.
Problem
ORACLE_PASSWORDwas populated from the application user password.- In SID mode,
getUsername()returnssystem, butgetPassword()returned the app user’s password, causing authentication mismatches and preventing a distinct system user password.
Changes
- Add a dedicated system user password field and API:
- New:
withOraclePassword(String oraclePassword)for SYSTEM/SYS. - Existing:
withPassword(String password)continues to set the application user password.
- New:
- Correct container env mapping:
ORACLE_PASSWORD← system user password.APP_USER_PASSWORD← app user password.
- In SID mode, use the system credentials:
getUsername()returnssystem.getPassword()now returns the system password.
- Backward compatibility:
- If
withOraclePassword(...)is not used,withPassword(...)sets both the app and system passwords (preserving previous behavior).
- If
Why getPassword() changed
return isUsingSid() ? oraclePassword : password;
- In SID mode we authenticate as
system. Returning the app user’s password was incorrect and led to login failures. Now the password matches the user being used.
Affected modules
testcontainers-oracle-xetestcontainers-oracle-free
Tests
- Extended existing
SimpleOracleTest(no new test classes):- SID tests run a system-level statement to validate the system password.
- Non-SID tests validate the app user password.
- Added cases verifying independent system vs app passwords.
Usage examples
// Different passwords for SYSTEM and app user
new OracleContainer(IMAGE)
.withOraclePassword("SysP@ss1!")
.withPassword("AppP@ss1!")
.start();
// SID mode (connects as SYSTEM → uses system password)
new OracleContainer(IMAGE)
.usingSid()
.withOraclePassword("SysOnly")
.start();
Migration / Compatibility
- No breaking change.
- Existing usage of
.withPassword(...)continues to work (sets both passwords unless.withOraclePassword(...)is used). - Use
.withOraclePassword(...)to set a distinct system password.
How to verify locally
- Style and formatting:
- Unix/macOS:
./gradlew checkstyleMain checkstyleTest spotlessApply - Windows:
.\gradlew.bat checkstyleMain checkstyleTest spotlessApply
- Unix/macOS:
- Run module tests:
./gradlew :testcontainers-oracle-xe:test :testcontainers-oracle-free:test
Documentation
- Clarify:
ORACLE_PASSWORDconfigures the SYSTEM/SYS password.APP_USER_PASSWORDconfigures the app user’s password.
Changelog entry
- feat(oracle): add
withOraclePasswordand fixORACLE_PASSWORDmapping to system user; use system password in SID mode; maintain backward compatibility withwithPassword.
Related issues
- (If applicable) Fixes: #