mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-06 13:08:29 +00:00
Print message when attempting to delete a user that doesn't exist
Previously the userdel command always returned success regardless of whether the user exists or not. When the user does not exist, a message is now shown indicating that the user was not found. Closes elastic/elasticsearch#346 Original commit: elastic/x-pack-elasticsearch@fb45d844ca
This commit is contained in:
parent
a59b389967
commit
17d2d0b1f9
@ -168,6 +168,11 @@ public class ESUsersTool extends CliTool {
|
||||
public ExitStatus execute(Settings settings, Environment env) throws Exception {
|
||||
Path file = FileUserPasswdStore.resolveFile(settings, env);
|
||||
Map<String, char[]> users = new HashMap<>(FileUserPasswdStore.parseFile(file, null));
|
||||
if (!users.containsKey(username)) {
|
||||
terminal.println("User [%s] doesn't exist", username);
|
||||
return ExitStatus.NO_USER;
|
||||
}
|
||||
|
||||
if (Files.exists(file)) {
|
||||
char[] passwd = users.remove(username);
|
||||
if (passwd != null) {
|
||||
|
@ -220,11 +220,16 @@ public class ESUsersToolTests extends CliToolTestCase {
|
||||
.put("shield.authc.esusers.files.users", userFile)
|
||||
.put("shield.authc.esusers.files.users_roles", userRolesFile)
|
||||
.build();
|
||||
CaptureOutputTerminal terminal = new CaptureOutputTerminal();
|
||||
|
||||
ESUsersTool.Userdel cmd = new ESUsersTool.Userdel(new MockTerminal(), "user2");
|
||||
ESUsersTool.Userdel cmd = new ESUsersTool.Userdel(terminal, "user2");
|
||||
|
||||
CliTool.ExitStatus status = execute(cmd, settings);
|
||||
assertThat(status, is(CliTool.ExitStatus.OK));
|
||||
assertThat(status, is(CliTool.ExitStatus.NO_USER));
|
||||
|
||||
List<String> output = terminal.getTerminalOutput();
|
||||
assertThat(output, hasSize(equalTo(1)));
|
||||
assertThat(output, hasItem(startsWith("User [user2] doesn't exist")));
|
||||
|
||||
assertFileExists(userFile);
|
||||
List<String> lines = Files.readLines(userFile, Charsets.UTF_8);
|
||||
@ -248,7 +253,7 @@ public class ESUsersToolTests extends CliToolTestCase {
|
||||
ESUsersTool.Userdel cmd = new ESUsersTool.Userdel(new MockTerminal(), "user2");
|
||||
|
||||
CliTool.ExitStatus status = execute(cmd, settings);
|
||||
assertThat(status, is(CliTool.ExitStatus.OK));
|
||||
assertThat(status, is(CliTool.ExitStatus.NO_USER));
|
||||
|
||||
assertThat(userFile.exists(), is(false));
|
||||
assertThat(userRolesFile.exists(), is(false));
|
||||
|
Loading…
x
Reference in New Issue
Block a user