@Test(groups="Integration") // requires ~/.ssh/id_rsa public void testReadsPrivateKeyFileWithTildePath() throws Exception { ConfigBag config = ConfigBag.newInstance(); config.put(LocationConfigKeys.PRIVATE_KEY_FILE, SSH_PRIVATE_KEY_FILE_WITH_TILDE); // don't mind if it has a passphrase String data = LocationConfigUtils.getOsCredential(config).doKeyValidation(false).getPreferredCredential(); assertTrue(data != null && data.length() > 0); }
public void testPreferPublicKeyDataOverFileAndNoPrivateKeyRequired() throws Exception { ConfigBag config = ConfigBag.newInstance(); config.put(LocationConfigKeys.PUBLIC_KEY_DATA, "mydata"); config.put(LocationConfigKeys.PUBLIC_KEY_FILE, SSH_PUBLIC_KEY_FILE); config.put(LocationConfigKeys.PRIVATE_KEY_FILE, ""); LocationConfigUtils.OsCredential creds = LocationConfigUtils.getOsCredential(config); String data = creds.getPublicKeyData(); assertEquals(data, "mydata"); Assert.assertNull(creds.getPreferredCredential()); Assert.assertFalse(creds.hasPassword()); Assert.assertFalse(creds.hasKey()); // and not even any warnings here Assert.assertTrue(creds.getWarningMessages().isEmpty()); }
public void testReadsPrivateKeyFileWithMultipleColonSeparatedFilesWithGoodFirst() throws Exception { ConfigBag config = ConfigBag.newInstance(); config.put(LocationConfigKeys.PRIVATE_KEY_FILE, SSH_PRIVATE_KEY_FILE+File.pathSeparator+"/path/does/not/exist"); String data = LocationConfigUtils.getOsCredential(config).getPreferredCredential(); assertTrue(data != null && data.length() > 0); }
@Test(groups="Integration") public void testReadsPrivateKeyFileWithPassphrase() throws Exception { ConfigBag config = ConfigBag.newInstance(); config.put(LocationConfigKeys.PRIVATE_KEY_FILE, SSH_PRIVATE_KEY_FILE_WITH_PASSPHRASE); LocationConfigUtils.OsCredential cred = LocationConfigUtils.getOsCredential(config).doKeyValidation(false); String data = cred.getPreferredCredential(); assertTrue(data != null && data.length() > 0); Assert.assertFalse(data.isEmpty()); cred.doKeyValidation(true); try { cred.checkNoErrors(); Assert.fail("check should fail as passphrase needed"); } catch (IllegalStateException exception) { } config.put(LocationConfigKeys.PRIVATE_KEY_PASSPHRASE, "passphrase"); cred.checkNoErrors(); config.put(LocationConfigKeys.PRIVATE_KEY_PASSPHRASE, "wrong_passphrase"); try { cred.checkNoErrors(); Assert.fail("check should fail as passphrase needed"); } catch (IllegalStateException exception) { } }
public void testReadsPrivateKeyFileWithMultipleColonSeparatedFilesWithGoodLast() throws Exception { ConfigBag config = ConfigBag.newInstance(); config.put(LocationConfigKeys.PRIVATE_KEY_FILE, "/path/does/not/exist"+File.pathSeparator+SSH_PRIVATE_KEY_FILE); String data = LocationConfigUtils.getOsCredential(config).getPreferredCredential(); assertTrue(data != null && data.length() > 0); }