Fix password property for Oracle container

See gh-37044
3.1.x
Joe Steel 1 year ago committed by Stephane Nicoll
parent 6780b80673
commit ab1e521388

@ -42,12 +42,12 @@ class OracleEnvironment {
private String extractPassword(Map<String, String> env) { private String extractPassword(Map<String, String> env) {
if (env.containsKey("APP_USER")) { 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"); Assert.state(StringUtils.hasLength(password), "No Oracle app password found");
return password; return password;
} }
Assert.state(!env.containsKey("ORACLE_RANDOM_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"); String password = env.get("ORACLE_PASSWORD");
Assert.state(StringUtils.hasLength(password), "No Oracle password found"); Assert.state(StringUtils.hasLength(password), "No Oracle password found");
return password; return password;

@ -34,7 +34,7 @@ class OracleEnvironmentTests {
@Test @Test
void getUsernameWhenHasAppUser() { 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"); assertThat(environment.getUsername()).isEqualTo("alice");
} }
@ -46,7 +46,7 @@ class OracleEnvironmentTests {
@Test @Test
void getPasswordWhenHasAppPassword() { 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"); assertThat(environment.getPassword()).isEqualTo("secret");
} }
@ -59,14 +59,14 @@ class OracleEnvironmentTests {
@Test @Test
void createWhenRandomPasswordAndAppPasswordDoesNotThrow() { void createWhenRandomPasswordAndAppPasswordDoesNotThrow() {
assertThatNoException().isThrownBy(() -> new OracleEnvironment( 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 @Test
void createWhenRandomPasswordThrowsException() { void createWhenRandomPasswordThrowsException() {
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> new OracleEnvironment(Map.of("ORACLE_RANDOM_PASSWORD", "true"))) .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 @Test
@ -78,7 +78,7 @@ class OracleEnvironmentTests {
@Test @Test
void createWhenAppUserAndEmptyAppPasswordThrowsException() { void createWhenAppUserAndEmptyAppPasswordThrowsException() {
assertThatIllegalStateException() 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"); .withMessage("No Oracle app password found");
} }

@ -20,6 +20,7 @@ import java.sql.Driver;
import java.time.Duration; import java.time.Duration;
import org.awaitility.Awaitility; import org.awaitility.Awaitility;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.OS; import org.junit.jupiter.api.condition.OS;
@ -41,9 +42,11 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
@DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64", @DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64",
disabledReason = "The Oracle image has no ARM support") disabledReason = "The Oracle image has no ARM support")
class OracleJdbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests { class OracleJdbcDockerComposeConnectionDetailsFactoryIntegrationTests {
OracleJdbcDockerComposeConnectionDetailsFactoryIntegrationTests() { @Nested
class OracleJdbcDockerComposeConnectionDetailsFactoryDefaultSettingsIntegrationTests extends AbstractDockerComposeIntegrationTests {
OracleJdbcDockerComposeConnectionDetailsFactoryDefaultSettingsIntegrationTests() {
super("oracle-compose.yaml", DockerImageNames.oracleXe()); super("oracle-compose.yaml", DockerImageNames.oracleXe());
} }
@ -66,5 +69,32 @@ class OracleJdbcDockerComposeConnectionDetailsFactoryIntegrationTests extends Ab
.isEqualTo("Hello"); .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");
});
}
}
} }

@ -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
Loading…
Cancel
Save