From e32a5024ad8b0515a9648c8d7a6a359c48785db4 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 27 Sep 2022 13:46:24 -0400 Subject: [PATCH] Use hashed host for known_hosts tests The `192.168.1.61` is Private Use IP. It is an intranet IP address, which is usually allocated to mobile phones, desktops, laptops, TVs, smart speakers and other devices. The logic is taken from a similar test class in the Apache MINA project --- .../session/ResourceKnownHostsServerKeyVerifierTests.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/session/ResourceKnownHostsServerKeyVerifierTests.java b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/session/ResourceKnownHostsServerKeyVerifierTests.java index 34a80feb98..70b39ac95c 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/session/ResourceKnownHostsServerKeyVerifierTests.java +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/session/ResourceKnownHostsServerKeyVerifierTests.java @@ -39,6 +39,7 @@ import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.net.SshdSocketAddress; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable; import org.junit.jupiter.api.condition.EnabledIf; import org.mockito.Mockito; @@ -53,6 +54,8 @@ import org.springframework.core.io.FileSystemResource; @EnabledIf("isDefaultKnownHostsFilePresent") public class ResourceKnownHostsServerKeyVerifierTests { + private static final String HASHED_HOST = "192.168.1.61"; + private static final Map HOST_KEYS = new TreeMap<>(SshdSocketAddress.BY_HOST_AND_PORT); @BeforeAll @@ -99,7 +102,7 @@ public class ResourceKnownHostsServerKeyVerifierTests { int pos = line.indexOf(' '); String patterns = line.substring(0, pos); if (entry.getHashedEntry() != null) { - hostsMap.put(new SshdSocketAddress("localhost", 0), entry); + hostsMap.put(new SshdSocketAddress(HASHED_HOST, 0), entry); } else { String[] addrs = GenericUtils.split(patterns, ',');