Skip to content

Commit 5c80258

Browse files
committed
Add a test for GH-351
Just a somewhat redundant regression test to make sure GH-351 is fixed by commit c11bfcc for GH-281. Bug: #351
1 parent c11bfcc commit 5c80258

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

sshd-common/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java

+32
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.sshd.client.config.hosts;
2121

2222
import java.io.IOException;
23+
import java.net.URI;
2324
import java.net.URL;
2425
import java.util.ArrayList;
2526
import java.util.Collection;
@@ -165,6 +166,37 @@ public void testCoalescingIdentityFile() throws Exception {
165166
assertEquals("xFile,dFile", resolved.getProperty(HostConfigEntry.IDENTITY_FILE_CONFIG_PROP));
166167
}
167168

169+
@Test // See GH-351
170+
public void testProxyJump() throws Exception {
171+
HostConfigEntry bastion = new HostConfigEntry();
172+
bastion.setHost("bastion");
173+
bastion.setHostName("1.2.3.4");
174+
bastion.setUsername("username");
175+
bastion.setIdentities(Collections.singleton("yFile"));
176+
HostConfigEntry server = new HostConfigEntry();
177+
server.setHost("server*");
178+
server.setProxyJump("bastion");
179+
HostConfigEntryResolver resolver = HostConfigEntry.toHostConfigEntryResolver(GenericUtils.asList(bastion, server));
180+
HostConfigEntry resolved = resolver.resolveEffectiveHost("server1", 0, null, "someone", null, null);
181+
expect("server1", 22, "someone", resolved);
182+
Collection<String> identities = resolved.getIdentities();
183+
assertTrue("Unexpected configured identities " + identities, identities == null || identities.isEmpty());
184+
String identityProp = resolved.getProperty(HostConfigEntry.IDENTITY_FILE_CONFIG_PROP);
185+
assertNull("Unexpected IdentityFile property", identityProp);
186+
// Same handling as in SshClient.parseProxyJumps()
187+
String proxy = resolved.getProperty(HostConfigEntry.PROXY_JUMP_CONFIG_PROP);
188+
assertEquals("bastion", proxy);
189+
URI uri = URI.create("ssh://" + proxy);
190+
resolved = resolver.resolveEffectiveHost(uri.getHost(), uri.getPort(), null, uri.getUserInfo(), null, null);
191+
expect("1.2.3.4", 22, "username", resolved);
192+
identities = resolved.getIdentities();
193+
assertNotNull("Should have identities", identities);
194+
assertEquals("[yFile]", identities.toString());
195+
identityProp = resolved.getProperty(HostConfigEntry.IDENTITY_FILE_CONFIG_PROP);
196+
assertNotNull("Should have IdentityFile property", identityProp);
197+
assertEquals("yFile", identityProp);
198+
}
199+
168200
@Test
169201
public void testNegatingPatternOverridesAll() {
170202
String testHost = "37.77.34.7";

0 commit comments

Comments
 (0)