### Question:
LocationConfigUtils { public static OsCredential getOsCredential(ConfigBag config) { return OsCredential.newInstance(config); }  static OsCredential getOsCredential(ConfigBag config); @Deprecated static String getPrivateKeyData(ConfigBag config); @Deprecated static String getPublicKeyData(ConfigBag config); @Deprecated static String getKeyData(ConfigBag config, ConfigKey<String> dataKey, ConfigKey<String> fileKey); @Deprecated @SuppressWarnings("unchecked") static T getConfigCheckingDeprecatedAlternatives(ConfigBag configBag, ConfigKey<T> preferredKey,
            ConfigKey<?> ...deprecatedKeys); static Map<ConfigKey<String>,String> finalAndOriginalSpecs(String finalSpec, Object ...sourcesForOriginalSpec); static boolean isEnabled(ManagementContext mgmt, String prefix);  }### Answer:
@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) { } }