Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/1074#discussion_r46030279
--- Diff:
core/src/test/java/org/apache/brooklyn/util/core/internal/ssh/SshToolAbstractIntegrationTest.java
---
@@ -264,8 +271,44 @@ public void testSshKeyWithPassphrase() throws
Exception {
}
@Test(groups = {"Integration"})
+ public void testSshKeyWithNoKeyDefaultsToIdrsa() throws Exception {
+ final SshTool localtool =
newTool(ImmutableMap.<String,Object>builder()
+ .put(SshTool.PROP_HOST.getName(), "localhost")
+ .build());
+ tools.add(localtool);
+ localtool.connect();
+ assertEquals(localtool.execScript(MutableMap.<String,Object>of(),
ImmutableList.of("date")), 0);
+ }
+
+ @Test(groups = {"Integration"})
+ public void testSshKeyWithPrivateKeyData() throws Exception {
+ final SshTool localtool =
newTool(ImmutableMap.<String,Object>builder()
+ .put(SshTool.PROP_HOST.getName(), "localhost")
+ .put(SshTool.PROP_PRIVATE_KEY_DATA.getName(), new
String(Files.toByteArray(new File(Os.tidyPath(SSH_DEFAULT_KEYFILE))),
StandardCharsets.UTF_8))
+ .build());
+ localtool.connect();
+
+ assertEquals(localtool.execScript(MutableMap.<String,Object>of(),
ImmutableList.of("date")), 0);
+
+ // Also needs the negative test to prove that we're really using
an ssh-key with a passphrase
+ try {
+ final SshTool localtool2 =
newTool(ImmutableMap.<String,Object>builder()
+ .put(SshTool.PROP_HOST.getName(), "localhost")
+ .put(SshTool.PROP_PRIVATE_KEY_DATA.getName(), "invalid
data")
+ .build());
+ localtool2.connect();
+ localtool2.execScript(MutableMap.<String,Object>of(),
ImmutableList.of("date"));
+ // Notice that executing a command may succeed for
SshCliToolIntegrationTest.testSshKeyWithPrivateKeyData if you already have
valid keys loaded in the ssh-agent
+ fail();
--- End diff --
you can use `Asserts.shouldHaveFailedPreviously()` then
`Asserts.expectedFailureContains(SshException.class.getSimpleName())` for a
more readable test.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---