8000 Validate .conf extension for --config-file option by griffonbyte · Pull Request #47696 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
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 @@ -107,6 +107,10 @@ public void setProfile(String profile) {
description = "Set the path to a configuration file. By default, configuration properties are read from the \"keycloak.conf\" file in the \"conf\" directory.",
paramLabel = "file")
public void setConfigFile(String path) {
if (!path.endsWith(".conf")) {
throw new CommandLine.ParameterException(spec.commandLine(),
String.format("Configuration file specified via '%s' or '%s' must have the '.conf' extension.", CONFIG_FILE_LONG_NAME, CONFIG_FILE_SHORT_NAME));
}
if (Files.notExists(Path.of(path))) {
throw new CommandLine.ParameterException(spec.commandLine(),
String.format("File specified via '%s' or '%s' option does not exist.", CONFIG_FILE_LONG_NAME, CONFIG_FILE_SHORT_NAME));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public Path getConfigurationFile() {
return null;
}

if (!filePath.endsWith(".conf")) {
throw new RuntimeException(
String.format("Configuration file '%s' must have the '.conf' extension.", filePath));
}

return Paths.get(filePath);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ void testInvalidConfigFileOption(CLIResult cliResult) {
cliResult.assertError(String.format("Try '%s --help' for more information on the available options.", KeycloakDistribution.SCRIPT_CMD));
}

@DryRun
@Test
@Launch({CONFIG_FILE_LONG_NAME + "=src/test/resources/keycloak.properties", "start", "--db=dev-file"})
void testConfigFileWithWrongExtension(CLIResult cliResult) {
cliResult.assertError("Configuration file specified via '--config-file' or '-cf' must have the '.conf' extension.");
}

@RawDistOnly(reason = "Containers are immutable")
@Test
void testRuntimeValuesAreNotCaptured(KeycloakDistribution dist) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# test config with wrong extension
Loading
0