Merge pull request #22609 from dadoonet/pr/keystore-npe
NPE when no setting name passed to elasticsearch-keystore
This commit is contained in:
commit
fef1407fd2
|
@ -64,6 +64,9 @@ class AddStringKeyStoreCommand extends EnvironmentAwareCommand {
|
|||
keystore.decrypt(new char[0] /* TODO: prompt for password when they are supported */);
|
||||
|
||||
String setting = arguments.value(options);
|
||||
if (setting == null) {
|
||||
throw new UserException(ExitCodes.USAGE, "The setting name can not be null");
|
||||
}
|
||||
if (keystore.getSettings().contains(setting) && options.has(forceOption) == false) {
|
||||
if (terminal.promptYesNo("Setting " + setting + " already exists. Overwrite?", false) == false) {
|
||||
terminal.println("Exiting without modifying keystore.");
|
||||
|
|
|
@ -127,6 +127,14 @@ public class AddStringKeyStoreCommandTests extends KeyStoreCommandTestCase {
|
|||
assertEquals("String value must contain only ASCII", e.getMessage());
|
||||
}
|
||||
|
||||
public void testNpe() throws Exception {
|
||||
createKeystore("");
|
||||
terminal.addTextInput("");
|
||||
UserException e = expectThrows(UserException.class, this::execute);
|
||||
assertEquals(ExitCodes.USAGE, e.exitCode);
|
||||
assertThat(e.getMessage(), containsString("The setting name can not be null"));
|
||||
}
|
||||
|
||||
void setInput(String inputStr) {
|
||||
input = new ByteArrayInputStream(inputStr.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue