|
20 | 20 | package org.apache.sshd.client.config.hosts;
|
21 | 21 |
|
22 | 22 | import java.io.IOException;
|
| 23 | +import java.net.URI; |
23 | 24 | import java.net.URL;
|
24 | 25 | import java.util.ArrayList;
|
25 | 26 | import java.util.Collection;
|
@@ -165,6 +166,37 @@ public void testCoalescingIdentityFile() throws Exception {
|
165 | 166 | assertEquals("xFile,dFile", resolved.getProperty(HostConfigEntry.IDENTITY_FILE_CONFIG_PROP));
|
166 | 167 | }
|
167 | 168 |
|
| 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 | + |
168 | 200 | @Test
|
169 | 201 | public void testNegatingPatternOverridesAll() {
|
170 | 202 | String testHost = "37.77.34.7";
|
|
0 commit comments