Skip to content

Commit

Permalink
Keystore location does not work for Windows (keycloak#23209)
Browse files Browse the repository at this point in the history
* Keystore location does not work for Windows

Fixes keycloak#22185

* Enable Quarkus UT for Windows

Closes keycloak#23208
  • Loading branch information
mabartos authored Sep 18, 2023
1 parent 5603ee7 commit c2fc2c2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ jobs:
name: Quarkus UT
needs: build
timeout-minutes: 15
runs-on: ubuntu-latest
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

import static org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper.fromOption;
Expand Down Expand Up @@ -50,11 +49,12 @@ private static Optional<String> validatePath(Optional<String> option, ConfigSour
throw new IllegalArgumentException("config-keystore-password must be specified");
}

Optional<String> realPath = Optional.of(String.valueOf(Paths.get(path.getValue()).toAbsolutePath().normalize()));
if (!Files.exists(Path.of(realPath.get()))) {
throw new IllegalArgumentException("config-keystore path does not exist: " + realPath.get());
final Path realPath = Path.of(path.getValue()).toAbsolutePath().normalize();
if (!Files.exists(realPath)) {
throw new IllegalArgumentException("config-keystore path does not exist: " + realPath);
}
return realPath;

return Optional.of(realPath.toUri().toString());
}

private static Optional<String> validatePassword(Optional<String> option, ConfigSourceInterceptorContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.keycloak.quarkus.runtime.Environment.isWindows;
import static org.keycloak.quarkus.runtime.configuration.ConfigArgsConfigSource.CLI_ARGS;

import java.io.File;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -266,7 +267,14 @@ public void testDatabaseDefaults() {
System.setProperty(CLI_ARGS, "--db=dev-file");
SmallRyeConfig config = createConfig();
assertEquals(H2Dialect.class.getName(), config.getConfigValue("kc.db-dialect").getValue());
assertEquals("jdbc:h2:file:" + System.getProperty("user.home") + "/data/h2/keycloakdb;;AUTO_SERVER=TRUE;NON_KEYWORDS=VALUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());

// JDBC location treated as file:// URI
final String userHomeUri = Path.of(System.getProperty("user.home"))
.toUri()
.toString()
.replaceFirst(isWindows() ? "file:///" : "file://", "");

assertEquals("jdbc:h2:file:" + userHomeUri + "data/h2/keycloakdb;;AUTO_SERVER=TRUE;NON_KEYWORDS=VALUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue());

System.setProperty(CLI_ARGS, "--db=dev-mem");
config = createConfig();
Expand Down

0 comments on commit c2fc2c2

Please sign in to comment.