diff --git a/src/main/java/net/schmizz/sshj/transport/verification/FingerprintVerifier.java b/src/main/java/net/schmizz/sshj/transport/verification/FingerprintVerifier.java index 24045ed87..58656bf50 100644 --- a/src/main/java/net/schmizz/sshj/transport/verification/FingerprintVerifier.java +++ b/src/main/java/net/schmizz/sshj/transport/verification/FingerprintVerifier.java @@ -26,7 +26,6 @@ import net.schmizz.sshj.common.Buffer; import net.schmizz.sshj.common.SSHRuntimeException; import net.schmizz.sshj.common.SecurityUtils; -import net.schmizz.sshj.transport.verification.HostKeyVerifier; public class FingerprintVerifier implements HostKeyVerifier { private static final Pattern MD5_FINGERPRINT_PATTERN = Pattern.compile("[0-9a-f]{2}+(:[0-9a-f]{2}+){15}+"); @@ -121,4 +120,8 @@ public boolean verify(String hostname, int port, PublicKey key) { return Arrays.equals(fingerprintData, digestData); } + @Override + public String toString() { + return "FingerprintVerifier{digestAlgorithm='" + digestAlgorithm + "'}"; + } } \ No newline at end of file diff --git a/src/main/java/net/schmizz/sshj/transport/verification/OpenSSHKnownHosts.java b/src/main/java/net/schmizz/sshj/transport/verification/OpenSSHKnownHosts.java index dfcaebf8d..3fbd14010 100644 --- a/src/main/java/net/schmizz/sshj/transport/verification/OpenSSHKnownHosts.java +++ b/src/main/java/net/schmizz/sshj/transport/verification/OpenSSHKnownHosts.java @@ -440,4 +440,10 @@ public static Marker fromString(String str) { return null; } } + + @Override + public String toString() { + return "OpenSSHKnownHosts{khFile='" + khFile + "'}"; + } + } diff --git a/src/test/groovy/com/hierynomus/sshj/transport/verification/OpenSSHKnownHostsSpec.groovy b/src/test/groovy/com/hierynomus/sshj/transport/verification/OpenSSHKnownHostsSpec.groovy index 1eb20d90a..ec0029c03 100644 --- a/src/test/groovy/com/hierynomus/sshj/transport/verification/OpenSSHKnownHostsSpec.groovy +++ b/src/test/groovy/com/hierynomus/sshj/transport/verification/OpenSSHKnownHostsSpec.groovy @@ -132,6 +132,18 @@ host1 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBL h << ["schmizz.net", "69.163.155.180"] } + def "should produce meaningful toString()"() { + given: + def f = knownHosts("schmizz.net,69.163.155.180 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6P9Hlwdahh250jGZYKg2snRq2j2lFJVdKSHyxqbJiVy9VX9gTkN3K2MD48qyrYLYOyGs3vTttyUk+cK++JMzURWsrP4piby7LpeOT+3Iq8CQNj4gXZdcH9w15Vuk2qS11at6IsQPVHpKD9HGg9//EFUccI/4w06k4XXLm/IxOGUwj6I2AeWmEOL3aDi+fe07TTosSdLUD6INtR0cyKsg0zC7Da24ixoShT8Oy3x2MpR7CY3PQ1pUVmvPkr79VeA+4qV9F1JM09WdboAMZgWQZ+XrbtuBlGsyhpUHSCQOya+kOJ+bYryS+U7A+6nmTW3C9FX4FgFqTF89UHOC7V0zZQ==") + + when: + def knownhosts = new OpenSSHKnownHosts(f) + + def toStringValue = knownhosts.toString() + then: + toStringValue == "OpenSSHKnownHosts{khFile='" + f + "'}" + } + def knownHosts(String s) { def f = temp.newFile("known_hosts") f.write(s) diff --git a/src/test/groovy/net/schmizz/sshj/transport/verification/FingerprintVerifierSpec.groovy b/src/test/groovy/net/schmizz/sshj/transport/verification/FingerprintVerifierSpec.groovy index c7093c125..2293a4d69 100644 --- a/src/test/groovy/net/schmizz/sshj/transport/verification/FingerprintVerifierSpec.groovy +++ b/src/test/groovy/net/schmizz/sshj/transport/verification/FingerprintVerifierSpec.groovy @@ -49,6 +49,16 @@ class FingerprintVerifierSpec extends Specification { } + def "should produce meaningful toString()"() { + given: + def verifier = FingerprintVerifier.getInstance("SHA1:2Fo8c/96zv32xc8GZWbOGYOlRak") + + when: + def toStringValue = verifier.toString() + + then: + toStringValue == "FingerprintVerifier{digestAlgorithm='SHA-1'}" + } def getPublicKey() { def lines = new File("src/test/resources/keytypes/test_ed25519.pub").readLines()