LocationConfigUtils { public static OsCredential getOsCredential(ConfigBag config) { return OsCredential.newInstance(config); }  static OsCredential getOsCredential(ConfigBag config); static Map<ConfigKey<String>,String> finalAndOriginalSpecs(String finalSpec, Object ...sourcesForOriginalSpec); static boolean isResolverPrefixEnabled(ManagementContext mgmt, String resolverIdPrefix); static boolean isEnabled(ManagementContext mgmt, String key); static String BROOKLYN_LOCATION_PREFIX; }
@Test(expectedExceptions=IllegalStateException.class) public void testInvalidKeyData() throws Exception { ConfigBag config = ConfigBag.newInstance(); config.put(LocationConfigKeys.PRIVATE_KEY_DATA, "mydata"); LocationConfigUtils.OsCredential creds = LocationConfigUtils.getOsCredential(config).doKeyValidation(false); Assert.assertTrue(creds.hasKey()); Assert.assertFalse(creds.getWarningMessages().isEmpty()); creds.checkNoErrors(); }
@Test(groups="Integration") public void testReadsPrivateKeyFileWithTildePath() throws Exception { ConfigBag config = ConfigBag.newInstance(); config.put(LocationConfigKeys.PRIVATE_KEY_FILE, SSH_PRIVATE_KEY_FILE_WITH_TILDE); String data = LocationConfigUtils.getOsCredential(config).doKeyValidation(false).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) { } }
@Test(groups="Integration") public void testReadsPublicKeyFileWithTildePath() throws Exception { ConfigBag config = ConfigBag.newInstance(); config.put(LocationConfigKeys.PUBLIC_KEY_FILE, SSH_PUBLIC_KEY_FILE_WITH_TILDE); String data = LocationConfigUtils.getOsCredential(config).doKeyValidation(false).getPublicKeyData(); assertTrue(data != null && data.length() > 0); }