Skip to content

Commit

Permalink
Add a test for GH-351
Browse files Browse the repository at this point in the history
Just a somewhat redundant regression test to make sure GH-351 is fixed
by commit c11bfcc for GH-281.

Bug: #351
  • Loading branch information
tomaswolf committed Apr 9, 2023
1 parent c11bfcc commit 5c80258
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.sshd.client.config.hosts;

import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -165,6 +166,37 @@ public void testCoalescingIdentityFile() throws Exception {
assertEquals("xFile,dFile", resolved.getProperty(HostConfigEntry.IDENTITY_FILE_CONFIG_PROP));
}

@Test // See GH-351
public void testProxyJump() throws Exception {
HostConfigEntry bastion = new HostConfigEntry();
bastion.setHost("bastion");
bastion.setHostName("1.2.3.4");
bastion.setUsername("username");
bastion.setIdentities(Collections.singleton("yFile"));
HostConfigEntry server = new HostConfigEntry();
server.setHost("server*");
server.setProxyJump("bastion");
HostConfigEntryResolver resolver = HostConfigEntry.toHostConfigEntryResolver(GenericUtils.asList(bastion, server));
HostConfigEntry resolved = resolver.resolveEffectiveHost("server1", 0, null, "someone", null, null);
expect("server1", 22, "someone", resolved);
Collection<String> identities = resolved.getIdentities();
assertTrue("Unexpected configured identities " + identities, identities == null || identities.isEmpty());
String identityProp = resolved.getProperty(HostConfigEntry.IDENTITY_FILE_CONFIG_PROP);
assertNull("Unexpected IdentityFile property", identityProp);
// Same handling as in SshClient.parseProxyJumps()
String proxy = resolved.getProperty(HostConfigEntry.PROXY_JUMP_CONFIG_PROP);
assertEquals("bastion", proxy);
URI uri = URI.create("ssh://" + proxy);
resolved = resolver.resolveEffectiveHost(uri.getHost(), uri.getPort(), null, uri.getUserInfo(), null, null);
expect("1.2.3.4", 22, "username", resolved);
identities = resolved.getIdentities();
assertNotNull("Should have identities", identities);
assertEquals("[yFile]", identities.toString());
identityProp = resolved.getProperty(HostConfigEntry.IDENTITY_FILE_CONFIG_PROP);
assertNotNull("Should have IdentityFile property", identityProp);
assertEquals("yFile", identityProp);
}

@Test
public void testNegatingPatternOverridesAll() {
String testHost = "37.77.34.7";
Expand Down

0 comments on commit 5c80258

Please sign in to comment.