def test_verifyBadKey(self): """ L{default.verifyHostKey} should return a L{Deferred} which fails with L{HostKeyChanged} if the host key is incorrect. """ l = [] default.verifyHostKey(self.fakeTransport, "4.3.2.1", otherSampleKey, "Again, not required.").addErrback(l.append) l[0].trap(HostKeyChanged)
def test_verifyBadKey(self): """ L{default.verifyHostKey} should return a L{Deferred} which fails with L{HostKeyChanged} if the host key is incorrect. """ l = [] default.verifyHostKey(self.fakeTransport, "4.3.2.1", otherSampleKey, "Again, not required.").addErrback(l.append) l[0].trap(HostKeyChanged)
def test_verifyOKKey(self): """ L{default.verifyHostKey} should return a L{Deferred} which fires with C{1} when passed a host, IP, and key which already match the known_hosts file it is supposed to check. """ l = [] default.verifyHostKey(self.fakeTransport, "4.3.2.1", sampleKey, "I don't care.").addCallback(l.append) self.assertEqual([1], l)
def test_verifyOKKey(self): """ L{default.verifyHostKey} should return a L{Deferred} which fires with C{1} when passed a host, IP, and key which already match the known_hosts file it is supposed to check. """ l = [] default.verifyHostKey(self.fakeTransport, "4.3.2.1", sampleKey, "I don't care.").addCallback(l.append) self.assertEqual([1], l)
def test_verifyBadKey(self): """ L{default.verifyHostKey} should return a L{Deferred} which fails with L{HostKeyChanged} if the host key is incorrect. """ d = default.verifyHostKey(self.fakeTransport, "4.3.2.1", otherSampleKey, "Again, not required.") return self.assertFailure(d, HostKeyChanged)
def test_noKnownHostsOption(self): """ L{default.verifyHostKey} should find your known_hosts file in ~/.ssh/known_hosts if you don't specify one explicitly on the command line. """ l = [] tmpdir = self.mktemp() oldHostsOption = self.hostsOption hostsNonOption = FilePath(tmpdir).child(".ssh").child("known_hosts") hostsNonOption.parent().makedirs() FilePath(oldHostsOption).moveTo(hostsNonOption) self.replaceHome(tmpdir) self.options['known-hosts'] = None default.verifyHostKey(self.fakeTransport, "4.3.2.1", sampleKey, "I don't care.").addCallback(l.append) self.assertEqual([1], l)
def test_noKnownHostsOption(self): """ L{default.verifyHostKey} should find your known_hosts file in ~/.ssh/known_hosts if you don't specify one explicitly on the command line. """ l = [] tmpdir = self.mktemp() oldHostsOption = self.hostsOption hostsNonOption = FilePath(tmpdir).child(".ssh").child("known_hosts") hostsNonOption.parent().makedirs() FilePath(oldHostsOption).moveTo(hostsNonOption) self.replaceHome(tmpdir) self.options['known-hosts'] = None default.verifyHostKey(self.fakeTransport, "4.3.2.1", sampleKey, "I don't care.").addCallback(l.append) self.assertEqual([1], l)
def test_verifyBadKey(self): """ L{default.verifyHostKey} should return a L{Deferred} which fails with L{HostKeyChanged} if the host key is incorrect. """ d = default.verifyHostKey( self.fakeTransport, "4.3.2.1", otherSampleKey, "Again, not required.") return self.assertFailure(d, HostKeyChanged)
def test_verifyHostButNotIP(self): """ L{default.verifyHostKey} should return a L{Deferred} which fires with C{1} when passed a host which matches with an IP is not present in its known_hosts file, and should also warn the user that it has added the IP address. """ l = [] default.verifyHostKey(self.fakeTransport, "8.7.6.5", sampleKey, "Fingerprint not required.").addCallback(l.append) self.assertEqual( ["Warning: Permanently added the RSA host key for IP address " "'8.7.6.5' to the list of known hosts."], self.fakeFile.outchunks) self.assertEqual([1], l) knownHostsFile = KnownHostsFile.fromPath(FilePath(self.hostsOption)) self.assertEqual(True, knownHostsFile.hasHostKey("8.7.6.5", Key.fromString(sampleKey)))
def test_verifyQuestion(self): """ L{default.verifyHostKey} should return a L{Default} which fires with C{0} when passed a unknown host that the user refuses to acknowledge. """ self.fakeTransport.factory.options['host'] = 'fake.example.com' l = [] self.fakeFile.inlines.append("no") default.verifyHostKey(self.fakeTransport, "9.8.7.6", otherSampleKey, "No fingerprint!").addErrback(l.append) self.assertEqual([ "The authenticity of host 'fake.example.com (9.8.7.6)' " "can't be established.\n" "RSA key fingerprint is " "57:a1:c2:a1:07:a0:2b:f4:ce:b5:e5:b7:ae:cc:e1:99.\n" "Are you sure you want to continue connecting (yes/no)? "], self.fakeFile.outchunks) l[0].trap(UserRejectedKey)
def test_verifyQuestion(self): """ L{default.verifyHostKey} should return a L{Default} which fires with C{0} when passed a unknown host that the user refuses to acknowledge. """ self.fakeTransport.factory.options['host'] = 'fake.example.com' l = [] self.fakeFile.inlines.append("no") default.verifyHostKey(self.fakeTransport, "9.8.7.6", otherSampleKey, "No fingerprint!").addErrback(l.append) self.assertEqual([ "The authenticity of host 'fake.example.com (9.8.7.6)' " "can't be established.\n" "RSA key fingerprint is " "57:a1:c2:a1:07:a0:2b:f4:ce:b5:e5:b7:ae:cc:e1:99.\n" "Are you sure you want to continue connecting (yes/no)? " ], self.fakeFile.outchunks) l[0].trap(UserRejectedKey)
def test_verifyQuestion(self): """ L{default.verifyHostKey} should return a L{Default} which fires with C{0} when passed an unknown host that the user refuses to acknowledge. """ self.fakeTransport.factory.options['host'] = b'fake.example.com' self.fakeFile.inlines.append(b"no") d = default.verifyHostKey(self.fakeTransport, b"9.8.7.6", otherSampleKey, b"No fingerprint!") self.assertEqual([ b"The authenticity of host 'fake.example.com (9.8.7.6)' " b"can't be established.\n" b"RSA key fingerprint is " b"SHA256:vD0YydsNIUYJa7yLZl3tIL8h0vZvQ8G+HPG7JLmQV0s=.\n" b"Are you sure you want to continue connecting (yes/no)? " ], self.fakeFile.outchunks) return self.assertFailure(d, UserRejectedKey)
def test_verifyQuestion(self): """ L{default.verifyHostKey} should return a L{Default} which fires with C{0} when passed an unknown host that the user refuses to acknowledge. """ self.fakeTransport.factory.options['host'] = b'fake.example.com' self.fakeFile.inlines.append(b"no") d = default.verifyHostKey( self.fakeTransport, b"9.8.7.6", otherSampleKey, b"No fingerprint!") self.assertEqual( [b"The authenticity of host 'fake.example.com (9.8.7.6)' " b"can't be established.\n" b"RSA key fingerprint is " b"SHA256:vD0YydsNIUYJa7yLZl3tIL8h0vZvQ8G+HPG7JLmQV0s=.\n" b"Are you sure you want to continue connecting (yes/no)? "], self.fakeFile.outchunks) return self.assertFailure(d, UserRejectedKey)