# HG changeset patch # User Severin Gehwolf # Date 1361360841 -3600 # Node ID 06cc96778e9475f129606ed7e6c184772a00a69e # Parent 527ed18dd3951b3a4f24e4af26970ccefaf6406f Don't allow "--version" in the Thermostat shell. Reviewed-by: neugens, rkennke Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-February/005778.html diff -r 527ed18dd395 -r 06cc96778e94 integration-tests/src/test/java/com/redhat/thermostat/itest/CliTest.java --- a/integration-tests/src/test/java/com/redhat/thermostat/itest/CliTest.java Mon Feb 11 17:45:57 2013 +0100 +++ b/integration-tests/src/test/java/com/redhat/thermostat/itest/CliTest.java Wed Feb 20 12:47:21 2013 +0100 @@ -37,6 +37,7 @@ package com.redhat.thermostat.itest; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -133,6 +134,30 @@ shell.expectClose(); } + + @Test + public void versionArgumentInShellIsNotAllowed() throws Exception { + Spawn shell = spawnThermostat("shell"); + + shell.expect(SHELL_PROMPT); + shell.send("--version\n"); + + shell.expect(SHELL_PROMPT); + + String stdOut = shell.getCurrentStandardOutContents(); + String stdErr = shell.getCurrentStandardErrContents(); + + assertFalse(stdOut.matches("Thermostat version \\d+\\.\\d+\\.\\d+\n")); + assertMatchesHelpCommandList(shell.getCurrentStandardOutContents()); + // use the Pattern.DOTALL flag (?s) so that line terminators match with + // ".*". stdOut contains the SHELL_PROMPT too. + assertTrue(stdOut.matches("(?s)^.*\nunknown command '--version'\n.*$")); + assertEquals(stdErr, ""); + + shell.send("exit\n"); + + shell.expectClose(); + } @Test public void testShellHelp() throws Exception { diff -r 527ed18dd395 -r 06cc96778e94 launcher/src/main/java/com/redhat/thermostat/launcher/internal/LauncherImpl.java --- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LauncherImpl.java Mon Feb 11 17:45:57 2013 +0100 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LauncherImpl.java Wed Feb 20 12:47:21 2013 +0100 @@ -119,7 +119,7 @@ try { if (hasNoArguments()) { runHelpCommand(); - } else if (isVersionQuery()) { + } else if (isVersionQuery(inShell)) { // We want to print the version of core // thermostat, so we use the no-arg constructor of Version Version coreVersion = new Version(); @@ -336,8 +336,13 @@ return ctx; } - private boolean isVersionQuery() { - return args[0].equals(Version.VERSION_OPTION); + private boolean isVersionQuery(boolean inShell) { + // don't allow --version in the shell + if (inShell) { + return false; + } else { + return args[0].equals(Version.VERSION_OPTION); + } } static class LoggingInitializer {