Mercurial > hg > release > thermostat-1.4
changeset 1809:3dc082384025
Don't ask for the agent password if client and agent usernames are the same in CLI setup
During CLI setup first the client credentials are asked and then the
agent's. The agent user's password prompt need not appear if the client
and agent usernames are the same during CLI setup.
Reviewed-by: omajid, jerboaa
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-September/016331.html
PR2643
author | Anirudhan Mukundan <amukunda@redhat.com> |
---|---|
date | Wed, 23 Sep 2015 11:53:49 -0400 |
parents | e4292781c523 |
children | c99480ceed02 |
files | setup/command/src/main/java/com/redhat/thermostat/setup/command/internal/cli/CLISetup.java setup/command/src/test/java/com/redhat/thermostat/setup/command/internal/cli/CLISetupTest.java |
diffstat | 2 files changed, 12 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/setup/command/src/main/java/com/redhat/thermostat/setup/command/internal/cli/CLISetup.java Mon Sep 21 14:56:42 2015 -0400 +++ b/setup/command/src/main/java/com/redhat/thermostat/setup/command/internal/cli/CLISetup.java Wed Sep 23 11:53:49 2015 -0400 @@ -98,35 +98,36 @@ char[] clientPassword; String agentUsername; char[] agentPassword; - boolean isValid = false; + boolean isUsernameValid = false; + LocalizedString passwordPrompt; + LocalizedString passwordPromptRepeat; println(LocaleResources.CLI_SETUP_THERMOSTAT_USER_CREDS_INTRO); do { LocalizedString clientUsernamePrompt = t.localize(LocaleResources.CLI_SETUP_THERMOSTAT_CLIENT_USERNAME_PROMPT); UsernameCredentialsReader clientUserReader = new UsernameCredentialsReader(console, clientUsernamePrompt); clientUsername = clientUserReader.read(); - LocalizedString passwordPrompt = t.localize(LocaleResources.CLI_SETUP_PASSWORD_PROMPT, clientUsername); - LocalizedString passwordPromptRepeat = t.localize(LocaleResources.CLI_SETUP_PASSWORD_REPEAT_PROMPT, clientUsername); + passwordPrompt = t.localize(LocaleResources.CLI_SETUP_PASSWORD_PROMPT, clientUsername); + passwordPromptRepeat = t.localize(LocaleResources.CLI_SETUP_PASSWORD_REPEAT_PROMPT, clientUsername); PasswordCredentialsReader clientPasswordReader = new PasswordCredentialsReader(console, passwordPrompt, passwordPromptRepeat); clientPassword = clientPasswordReader.readPassword(); LocalizedString agentUsernamePrompt = t.localize(LocaleResources.CLI_SETUP_THERMOSTAT_AGENT_USERNAME_PROMPT); UsernameCredentialsReader agentUserReader = new UsernameCredentialsReader(console, agentUsernamePrompt); agentUsername = agentUserReader.read(); - passwordPrompt = t.localize(LocaleResources.CLI_SETUP_PASSWORD_PROMPT, agentUsername); - passwordPromptRepeat = t.localize(LocaleResources.CLI_SETUP_PASSWORD_REPEAT_PROMPT, agentUsername); - PasswordCredentialsReader agentPasswordReader = new PasswordCredentialsReader(console, passwordPrompt, passwordPromptRepeat); - agentPassword = agentPasswordReader.readPassword(); try { checkUsernamesNotIdentical(clientUsername, agentUsername); - isValid = true; + isUsernameValid = true; } catch (IdenticalUsernameException e) { Arrays.fill(clientPassword, '\0'); - Arrays.fill(agentPassword, '\0'); printErr(LocaleResources.CLI_SETUP_USERNAMES_IDENTICAL, clientUsername); } - } while (!isValid); + } while (!isUsernameValid); + passwordPrompt = t.localize(LocaleResources.CLI_SETUP_PASSWORD_PROMPT, agentUsername); + passwordPromptRepeat = t.localize(LocaleResources.CLI_SETUP_PASSWORD_REPEAT_PROMPT, agentUsername); + PasswordCredentialsReader agentPasswordReader = new PasswordCredentialsReader(console, passwordPrompt, passwordPromptRepeat); + agentPassword = agentPasswordReader.readPassword(); thermostatSetup.createClientAdminUser(clientUsername, clientPassword); thermostatSetup.createAgentUser(agentUsername, agentPassword); }
--- a/setup/command/src/test/java/com/redhat/thermostat/setup/command/internal/cli/CLISetupTest.java Mon Sep 21 14:56:42 2015 -0400 +++ b/setup/command/src/test/java/com/redhat/thermostat/setup/command/internal/cli/CLISetupTest.java Wed Sep 23 11:53:49 2015 -0400 @@ -185,7 +185,7 @@ @Test public void testReadThermostatCredsWithIdenticalUsernames() throws IOException { - String incorrectInput = "identical-user\nt\nt\nidentical-user\nb\nb\n"; + String incorrectInput = "identical-user\nt\nt\nidentical-user\n"; String correctInput = "client-user\nt\nt\nagent-user\nb\nb\n"; ByteArrayInputStream mockInStream = new ByteArrayInputStream((incorrectInput + correctInput).getBytes()); when(console.getInput()).thenReturn(mockInStream);