/** * Confirm that the exit code is 0 when alias password is not the same as keystore password but * specified correctly in the command line */ @Test public void testCheckDifferentAliasPasswordOK() { String commnandLine = "-c -ks " + KEYSTORE_DIFFERENT_PASSWORD_LOCATION + " -ksp " + KEYSTORE_PASSWORD + " -kt " + KEYSTORE_TYPE + " -ka different_password -kp different_password"; String argv[] = commnandLine.split(" "); try { exit.expectSystemExitWithStatus(EXIT_OK); KeystoreManagerCtrl.main(argv); } catch (Exception e) { // Confirm that we got the right exit code int exitCode = getExitCode(e); assertEquals("The program did not exist with expected status", EXIT_OK, exitCode); } }
/** * Confirm that when giving non existing parameter, help is displayed and EXIT_ERROR is returned */ @Test public void testHelpAndErrorOnWrongParameter() { String argv[] = {"--does_not_exist"}; try { exit.expectSystemExitWithStatus(EXIT_ERROR); exit.checkAssertionAfterwards( new Assertion() { public void checkAssertion() { String out = systemOutRule.getLog(); // Confirm that we got the help displayed String expected = "usage: tkeystoremanager"; assertTrue( "Can't find expected string on std out " + expected, out.contains(expected)); } }); KeystoreManagerCtrl.main(argv); } catch (Exception e) { // Confirm that we got the right exit code int exitCode = getExitCode(e); assertEquals("The program did not exist with expected status", EXIT_ERROR, exitCode); } }
/** Confirm that the exit code is 1 when wrong keystore type is given */ @Test public void testWrongkeystoreType() { String commnandLine = "-c -ks " + KEYSTORE_JCEKS_LOCATION + " -ksp " + KEYSTORE_PASSWORD + " -kt " + SecurityConf.KEYSTORE_TYPE.jks.name() + " -ka " + ALIAS_JCEKS + " -kp " + KEYSTORE_PASSWORD; String argv[] = commnandLine.split(" "); try { exit.expectSystemExitWithStatus(EXIT_ERROR); KeystoreManagerCtrl.main(argv); } catch (Exception e) { // Confirm that we got the right exit code int exitCode = getExitCode(e); assertEquals("The program did not exist with expected status", EXIT_ERROR, exitCode); } }