Skip to content

Commit 8d4ba2b

Browse files
committed
refactor(oracle): rename withSystemPassword to withOraclePassword
Rename method for setting system user password to better reflect its purpose and align with environment variable naming. Update tests to verify system user connection instead of granting DBA privileges.
1 parent 5171d96 commit 8d4ba2b

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

modules/oracle-free/src/main/java/org/testcontainers/oracle/OracleContainer.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ public class OracleContainer extends JdbcDatabaseContainer<OracleContainer> {
6060

6161
/**
6262
* Password for Oracle system user (e.g. SYSTEM/SYS). Defaults to {@link #APP_USER_PASSWORD}
63-
* for backwards compatibility, but can be customized independently via {@link #withSystemPassword(String)}.
63+
* for backwards compatibility, but can be customized independently via {@link #withOraclePassword(String)}.
6464
*/
65-
private String oraclePassword = APP_USER_PASSWORD;
65+
private String systemPassword = APP_USER_PASSWORD;
6666

6767
/**
68-
* Tracks whether {@link #withSystemPassword(String)} was called to avoid overriding
68+
* Tracks whether {@link #withOraclePassword(String)} was called to avoid overriding
6969
* the system password when {@link #withPassword(String)} is used for the application user only.
7070
*/
7171
private boolean systemPasswordExplicitlySet = false;
@@ -125,7 +125,7 @@ public String getUsername() {
125125
@Override
126126
public String getPassword() {
127127
// When connecting via SID we authenticate as SYSTEM. Use the dedicated system password.
128-
return isUsingSid() ? oraclePassword : password;
128+
return isUsingSid() ? systemPassword : password;
129129
}
130130

131131
@Override
@@ -158,7 +158,7 @@ public OracleContainer withPassword(String password) {
158158
// Maintain backwards compatibility: if system password wasn't set explicitly,
159159
// align it with the application user's password.
160160
if (!systemPasswordExplicitlySet) {
161-
this.oraclePassword = password;
161+
this.systemPassword = password;
162162
}
163163
return self();
164164
}
@@ -167,14 +167,14 @@ public OracleContainer withPassword(String password) {
167167
* Sets the password for the Oracle system user (SYSTEM/SYS). This is independent from the
168168
* application user password set via {@link #withPassword(String)}.
169169
*
170-
* @param oraclePassword password for SYSTEM/SYS users inside the container
170+
* @param systemPassword password for SYSTEM/SYS users inside the container
171171
* @return this container instance
172172
*/
173-
public OracleContainer withSystemPassword(String oraclePassword) {
174-
if (StringUtils.isEmpty(oraclePassword)) {
173+
public OracleContainer withOraclePassword(String systemPassword) {
174+
if (StringUtils.isEmpty(systemPassword)) {
175175
throw new IllegalArgumentException("Oracle password cannot be null or empty");
176176
}
177-
this.oraclePassword = oraclePassword;
177+
this.systemPassword = systemPassword;
178178
this.systemPasswordExplicitlySet = true;
179179
return self();
180180
}
@@ -220,7 +220,7 @@ public String getTestQueryString() {
220220
@Override
221221
protected void configure() {
222222
// Configure system user password independently from application user's password
223-
withEnv("ORACLE_PASSWORD", oraclePassword);
223+
withEnv("ORACLE_PASSWORD", systemPassword);
224224

225225
// Only set ORACLE_DATABASE if different than the default.
226226
if (databaseName != DEFAULT_DATABASE_NAME) {

modules/oracle-free/src/test/java/org/testcontainers/junit/oracle/SimpleOracleTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ private void runTestSystemUser(OracleContainer container, String databaseName, S
3838
assertThat(container.getUsername()).isEqualTo(username);
3939
assertThat(container.getPassword()).isEqualTo(password);
4040

41-
//Test we can get a connection and execute a system-level command
41+
//Test we can get a connection and verify current user
4242
container.start();
43-
ResultSet resultSet = performQuery(container, "GRANT DBA TO " + username);
44-
int resultSetInt = resultSet.getInt(1);
45-
assertThat(resultSetInt).as("A basic system user query succeeds").isEqualTo(1);
43+
44+
// Verify we are connected as the system user
45+
ResultSet resultSet = performQuery(container, "SELECT USER FROM DUAL");
46+
String currentUser = resultSet.getString(1);
47+
assertThat(currentUser)
48+
.as("Connected session should run as the system user")
49+
.isEqualToIgnoringCase(username);
4650
}
4751

4852
@Test
@@ -116,7 +120,7 @@ public void testWithSystemPassword() throws SQLException {
116120
try (
117121
OracleContainer oracle = new OracleContainer(ORACLE_DOCKER_IMAGE_NAME)
118122
.usingSid()
119-
.withSystemPassword("SysP@ss1!")
123+
.withOraclePassword("SysP@ss1!")
120124
.withPassword("AppP@ss1!")
121125
) {
122126
runTestSystemUser(oracle, "freepdb1", "system", "SysP@ss1!");
@@ -127,7 +131,7 @@ public void testWithSystemPassword() throws SQLException {
127131
public void testWithPassword() throws SQLException {
128132
try (
129133
OracleContainer oracle = new OracleContainer(ORACLE_DOCKER_IMAGE_NAME)
130-
.withSystemPassword("SysP@ss2!")
134+
.withOraclePassword("SysP@ss2!")
131135
.withPassword("AppP@ss2!")
132136
) {
133137
runTest(oracle, "freepdb1", "test", "AppP@ss2!");

modules/oracle-xe/src/main/java/org/testcontainers/containers/OracleContainer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ public class OracleContainer extends JdbcDatabaseContainer<OracleContainer> {
6363

6464
/**
6565
* Password for Oracle system user (e.g. SYSTEM/SYS). Defaults to {@link #APP_USER_PASSWORD}
66-
* for backwards compatibility, but can be customized independently via {@link #withSystemPassword(String)}.
66+
* for backwards compatibility, but can be customized independently via {@link #withOraclePassword(String)}.
6767
*/
6868
private String systemPassword = APP_USER_PASSWORD;
6969

7070
/**
71-
* Tracks whether {@link #withSystemPassword(String)} was called to avoid overriding
71+
* Tracks whether {@link #withOraclePassword(String)} was called to avoid overriding
7272
* the system password when {@link #withPassword(String)} is used for the application user only.
7373
*/
7474
private boolean systemPasswordExplicitlySet = false;
@@ -176,7 +176,7 @@ public OracleContainer withPassword(String password) {
176176
throw new IllegalArgumentException("Password cannot be null or empty");
177177
}
178178
this.password = password;
179-
// Maintain backwards compatibility: if oracle password wasn't set explicitly,
179+
// Maintain backwards compatibility: if system password wasn't set explicitly,
180180
// align it with the application user's password.
181181
if (!systemPasswordExplicitlySet) {
182182
this.systemPassword = password;
@@ -188,14 +188,14 @@ public OracleContainer withPassword(String password) {
188188
* Sets the password for the Oracle system user (SYSTEM/SYS). This is independent from the
189189
* application user password set via {@link #withPassword(String)}.
190190
*
191-
* @param oraclePassword password for SYSTEM/SYS users inside the container
191+
* @param systemPassword password for SYSTEM/SYS users inside the container
192192
* @return this container instance
193193
*/
194-
public OracleContainer withSystemPassword(String oraclePassword) {
195-
if (StringUtils.isEmpty(oraclePassword)) {
194+
public OracleContainer withOraclePassword(String systemPassword) {
195+
if (StringUtils.isEmpty(systemPassword)) {
196196
throw new IllegalArgumentException("Oracle password cannot be null or empty");
197197
}
198-
this.systemPassword = oraclePassword;
198+
this.systemPassword = systemPassword;
199199
this.systemPasswordExplicitlySet = true;
200200
return self();
201201
}

modules/oracle-xe/src/test/java/org/testcontainers/junit/oracle/SimpleOracleTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ private void runTestSystemUser(OracleContainer container, String databaseName, S
3838
assertThat(container.getPassword()).isEqualTo(password);
3939

4040
container.start();
41+
42+
// Verify we are connected as the system user
4143
ResultSet resultSet = performQuery(container, "SELECT USER FROM DUAL");
4244
String currentUser = resultSet.getString(1);
4345
assertThat(currentUser)
@@ -116,7 +118,7 @@ public void testSeparateSystemAndAppPasswords() throws SQLException {
116118
try (
117119
OracleContainer oracleSid = new OracleContainer(ORACLE_DOCKER_IMAGE_NAME)
118120
.usingSid()
119-
.withSystemPassword("SysP@ss1!")
121+
.withOraclePassword("SysP@ss1!")
120122
.withPassword("AppP@ss1!")
121123
) {
122124
runTestSystemUser(oracleSid, "xepdb1", "system", "SysP@ss1!");
@@ -125,7 +127,7 @@ public void testSeparateSystemAndAppPasswords() throws SQLException {
125127
// Non-SID mode should use application user's password
126128
try (
127129
OracleContainer oraclePdb = new OracleContainer(ORACLE_DOCKER_IMAGE_NAME)
128-
.withSystemPassword("SysP@ss2!")
130+
.withOraclePassword("SysP@ss2!")
129131
.withPassword("AppP@ss2!")
130132
) {
131133
runTest(oraclePdb, "xepdb1", "test", "AppP@ss2!");

0 commit comments

Comments
 (0)