Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Boot Docker Compose support for Oracle looks for APP_PASSWORD but should look for APP_USER_PASSWORD #37044

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class OracleEnvironment {

private String extractPassword(Map<String, String> env) {
if (env.containsKey("APP_USER")) {
String password = env.get("APP_PASSWORD");
String password = env.get("APP_USER_PASSWORD");
Assert.state(StringUtils.hasLength(password), "No Oracle app password found");
return password;
}
Assert.state(!env.containsKey("ORACLE_RANDOM_PASSWORD"),
"ORACLE_RANDOM_PASSWORD is not supported without APP_USER and APP_PASSWORD");
"ORACLE_RANDOM_PASSWORD is not supported without APP_USER and APP_USER_PASSWORD");
String password = env.get("ORACLE_PASSWORD");
Assert.state(StringUtils.hasLength(password), "No Oracle password found");
return password;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OracleEnvironmentTests {

@Test
void getUsernameWhenHasAppUser() {
OracleEnvironment environment = new OracleEnvironment(Map.of("APP_USER", "alice", "APP_PASSWORD", "secret"));
OracleEnvironment environment = new OracleEnvironment(Map.of("APP_USER", "alice", "APP_USER_PASSWORD", "secret"));
assertThat(environment.getUsername()).isEqualTo("alice");
}

Expand All @@ -46,7 +46,7 @@ void getUsernameWhenHasNoAppUser() {

@Test
void getPasswordWhenHasAppPassword() {
OracleEnvironment environment = new OracleEnvironment(Map.of("APP_USER", "alice", "APP_PASSWORD", "secret"));
OracleEnvironment environment = new OracleEnvironment(Map.of("APP_USER", "alice", "APP_USER_PASSWORD", "secret"));
assertThat(environment.getPassword()).isEqualTo("secret");
}

Expand All @@ -59,14 +59,14 @@ void getPasswordWhenHasOraclePassword() {
@Test
void createWhenRandomPasswordAndAppPasswordDoesNotThrow() {
assertThatNoException().isThrownBy(() -> new OracleEnvironment(
Map.of("APP_USER", "alice", "APP_PASSWORD", "secret", "ORACLE_RANDOM_PASSWORD", "true")));
Map.of("APP_USER", "alice", "APP_USER_PASSWORD", "secret", "ORACLE_RANDOM_PASSWORD", "true")));
}

@Test
void createWhenRandomPasswordThrowsException() {
assertThatIllegalStateException()
.isThrownBy(() -> new OracleEnvironment(Map.of("ORACLE_RANDOM_PASSWORD", "true")))
.withMessage("ORACLE_RANDOM_PASSWORD is not supported without APP_USER and APP_PASSWORD");
.withMessage("ORACLE_RANDOM_PASSWORD is not supported without APP_USER and APP_USER_PASSWORD");
}

@Test
Expand All @@ -78,7 +78,7 @@ void createWhenAppUserAndNoAppPasswordThrowsException() {
@Test
void createWhenAppUserAndEmptyAppPasswordThrowsException() {
assertThatIllegalStateException()
.isThrownBy(() -> new OracleEnvironment(Map.of("APP_USER", "alice", "APP_PASSWORD", "")))
.isThrownBy(() -> new OracleEnvironment(Map.of("APP_USER", "alice", "APP_USER_PASSWORD", "")))
.withMessage("No Oracle app password found");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.time.Duration;

import org.awaitility.Awaitility;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.OS;

Expand All @@ -41,30 +42,59 @@
*/
@DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64",
disabledReason = "The Oracle image has no ARM support")
class OracleJdbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {
class OracleJdbcDockerComposeConnectionDetailsFactoryIntegrationTests {

OracleJdbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("oracle-compose.yaml", DockerImageNames.oracleXe());
}
@Nested
class OracleJdbcDockerComposeConnectionDetailsFactoryDefaultSettingsIntegrationTests extends AbstractDockerComposeIntegrationTests {
OracleJdbcDockerComposeConnectionDetailsFactoryDefaultSettingsIntegrationTests() {
super("oracle-compose.yaml", DockerImageNames.oracleXe());
}

@Test
@SuppressWarnings("unchecked")
void runCreatesConnectionDetailsThatCanBeUsedToAccessDatabase() throws Exception {
JdbcConnectionDetails connectionDetails = run(JdbcConnectionDetails.class);
assertThat(connectionDetails.getUsername()).isEqualTo("system");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:oracle:thin:@").endsWith("/xepdb1");
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setUrl(connectionDetails.getJdbcUrl());
dataSource.setUsername(connectionDetails.getUsername());
dataSource.setPassword(connectionDetails.getPassword());
dataSource.setDriverClass((Class<? extends Driver>) ClassUtils.forName(connectionDetails.getDriverClassName(),
getClass().getClassLoader()));
Awaitility.await().atMost(Duration.ofMinutes(1)).ignoreExceptions().untilAsserted(() -> {
JdbcTemplate template = new JdbcTemplate(dataSource);
assertThat(template.queryForObject(DatabaseDriver.ORACLE.getValidationQuery(), String.class))
.isEqualTo("Hello");
});
@Test
@SuppressWarnings("unchecked")
void runCreatesConnectionDetailsThatCanBeUsedToAccessDatabase() throws Exception {
JdbcConnectionDetails connectionDetails = run(JdbcConnectionDetails.class);
assertThat(connectionDetails.getUsername()).isEqualTo("system");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:oracle:thin:@").endsWith("/xepdb1");
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setUrl(connectionDetails.getJdbcUrl());
dataSource.setUsername(connectionDetails.getUsername());
dataSource.setPassword(connectionDetails.getPassword());
dataSource.setDriverClass((Class<? extends Driver>) ClassUtils.forName(connectionDetails.getDriverClassName(),
getClass().getClassLoader()));
Awaitility.await().atMost(Duration.ofMinutes(1)).ignoreExceptions().untilAsserted(() -> {
JdbcTemplate template = new JdbcTemplate(dataSource);
assertThat(template.queryForObject(DatabaseDriver.ORACLE.getValidationQuery(), String.class))
.isEqualTo("Hello");
});
}
}

@Nested
class OracleJdbcDockerComposeConnectionDetailsFactoryNonDefaultSettingsIntegrationTests extends AbstractDockerComposeIntegrationTests {
protected OracleJdbcDockerComposeConnectionDetailsFactoryNonDefaultSettingsIntegrationTests() {
super("oracle-non-default-compose.yaml", DockerImageNames.oracleXe());
}

@Test
@SuppressWarnings("unchecked")
void runCreatesConnectionDetailsWithNonDefaultUsernameAndPasswordThatCanBeUsedToAccessDatabase() throws Exception {
JdbcConnectionDetails connectionDetails = run(JdbcConnectionDetails.class);
assertThat(connectionDetails.getUsername()).isEqualTo("app_user");
assertThat(connectionDetails.getPassword()).isEqualTo("app_user_secret");
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:oracle:thin:@").endsWith("/xepdb1");
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setUrl(connectionDetails.getJdbcUrl());
dataSource.setUsername(connectionDetails.getUsername());
dataSource.setPassword(connectionDetails.getPassword());
dataSource.setDriverClass((Class<? extends Driver>) ClassUtils.forName(connectionDetails.getDriverClassName(),
getClass().getClassLoader()));
Awaitility.await().atMost(Duration.ofMinutes(1)).ignoreExceptions().untilAsserted(() -> {
JdbcTemplate template = new JdbcTemplate(dataSource);
assertThat(template.queryForObject(DatabaseDriver.ORACLE.getValidationQuery(), String.class))
.isEqualTo("Hello");
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
database:
image: '{imageName}'
ports:
- '1521'
environment:
- 'APP_USER=app_user'
- 'APP_USER_PASSWORD=app_user_secret'
- 'ORACLE_PASSWORD=secret'
healthcheck:
test: ["CMD-SHELL", "healthcheck.sh"]
interval: 10s
timeout: 5s
retries: 10