Merge pull request #22609 from dadoonet/pr/keystore-npe

NPE when no setting name passed to elasticsearch-keystore
This commit is contained in:
David Pilato 2017-01-13 13:00:14 +01:00 committed by GitHub
commit fef1407fd2
2 changed files with 11 additions and 0 deletions

View File

@ -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.");

View File

@ -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));
}