def test_hasLaterAddedKey(self): """ L{KnownHostsFile.hasHostKey} returns C{True} when a key for the given hostname is present in the file, even if it is only added to the file after the L{KnownHostsFile} instance is initialized. """ key = Key.fromString(sampleKey) entry = PlainEntry(["brandnew.example.com"], key.sshType(), key, "") hostsFile = self.loadSampleHostsFile() with hostsFile._savePath.open("a") as hostsFileObj: hostsFileObj.write(entry.toString() + "\n") self.assertEqual(True, hostsFile.hasHostKey("brandnew.example.com", key))
def test_hasLaterAddedKey(self): """ L{KnownHostsFile.hasHostKey} returns C{True} when a key for the given hostname is present in the file, even if it is only added to the file after the L{KnownHostsFile} instance is initialized. """ key = Key.fromString(sampleKey) entry = PlainEntry(["brandnew.example.com"], key.sshType(), key, "") hostsFile = self.loadSampleHostsFile() with hostsFile.savePath.open("a") as hostsFileObj: hostsFileObj.write(entry.toString() + "\n") self.assertEqual( True, hostsFile.hasHostKey("brandnew.example.com", key))
def test_matchesHostIP(self): """ A "hostname,ip" formatted line will match both the host and the IP. """ self.entry = PlainEntry.fromString(self.hostIPLine) self.assertEqual(True, self.entry.matchesHost("198.49.126.131")) self.test_matchesHost()
def test_toString(self): """ L{PlainEntry.toString} generates the serialized OpenSSL format string for the entry, sans newline. """ self.assertEqual(self.entry.toString(), self.plaintextLine.rstrip("\n")) multiHostEntry = PlainEntry.fromString(self.hostIPLine) self.assertEqual(multiHostEntry.toString(), self.hostIPLine.rstrip("\n"))
def setUp(self): """ Set 'entry' to a sample plain-text entry with sampleKey as its key. """ self.entry = PlainEntry.fromString(self.plaintextLine)