示例#1
0
 def test_defaultInitializerIgnoresExisting(self):
     """
     The default initializer for L{KnownHostsFile} disregards any existing
     contents in the save path.
     """
     hostsFile = KnownHostsFile(self.pathWithContent(sampleHashedLine))
     self.assertEqual([], list(hostsFile.iterentries()))
示例#2
0
 def test_defaultInitializerIgnoresExisting(self):
     """
     The default initializer for L{KnownHostsFile} disregards any existing
     contents in the save path.
     """
     hostsFile = KnownHostsFile(self.pathWithContent(sampleHashedLine))
     self.assertEqual([], list(hostsFile.iterentries()))
示例#3
0
 def test_iterentriesUnsaved(self):
     """
     If the save path for a L{KnownHostsFile} does not exist,
     L{KnownHostsFile.iterentries} still returns added but unsaved entries.
     """
     hostsFile = KnownHostsFile(FilePath(self.mktemp()))
     hostsFile.addHostKey("www.example.com", Key.fromString(sampleKey))
     self.assertEqual(1, len(list(hostsFile.iterentries())))
示例#4
0
 def test_iterentriesUnsaved(self):
     """
     If the save path for a L{KnownHostsFile} does not exist,
     L{KnownHostsFile.iterentries} still returns added but unsaved entries.
     """
     hostsFile = KnownHostsFile(FilePath(self.mktemp()))
     hostsFile.addHostKey("www.example.com", Key.fromString(sampleKey))
     self.assertEqual(1, len(list(hostsFile.iterentries())))
示例#5
0
    def test_savingAvoidsDuplication(self):
        """
        L{KnownHostsFile.save} only writes new entries to the save path, not
        entries which were added and already written by a previous call to
        C{save}.
        """
        path = FilePath(self.mktemp())
        knownHosts = KnownHostsFile(path)
        entry = knownHosts.addHostKey("some.example.com",
                                      Key.fromString(sampleKey))
        knownHosts.save()
        knownHosts.save()

        knownHosts = KnownHostsFile.fromPath(path)
        self.assertEqual([entry], list(knownHosts.iterentries()))
示例#6
0
    def test_saveResetsClobberState(self):
        """
        After L{KnownHostsFile.save} is used once with an instance initialized
        by the default initializer, contents of the save path are respected and
        preserved.
        """
        hostsFile = KnownHostsFile(self.pathWithContent(sampleHashedLine))
        preSave = hostsFile.addHostKey("www.example.com",
                                       Key.fromString(otherSampleKey))
        hostsFile.save()
        postSave = hostsFile.addHostKey("another.example.com",
                                        Key.fromString(thirdSampleKey))
        hostsFile.save()

        self.assertEqual([preSave, postSave], list(hostsFile.iterentries()))
示例#7
0
 def test_defaultInitializerClobbersExisting(self):
     """
     After using the default initializer for L{KnownHostsFile}, the first use
     of L{KnownHostsFile.save} overwrites any existing contents in the save
     path.
     """
     path = self.pathWithContent(sampleHashedLine)
     hostsFile = KnownHostsFile(path)
     entry = hostsFile.addHostKey("www.example.com",
                                  Key.fromString(otherSampleKey))
     hostsFile.save()
     # Check KnownHostsFile to see what it thinks the state is
     self.assertEqual([entry], list(hostsFile.iterentries()))
     # And also directly check the underlying file itself
     self.assertEqual(entry.toString() + "\n", path.getContent())
示例#8
0
    def test_savingAvoidsDuplication(self):
        """
        L{KnownHostsFile.save} only writes new entries to the save path, not
        entries which were added and already written by a previous call to
        C{save}.
        """
        path = FilePath(self.mktemp())
        knownHosts = KnownHostsFile(path)
        entry = knownHosts.addHostKey(
            "some.example.com", Key.fromString(sampleKey))
        knownHosts.save()
        knownHosts.save()

        knownHosts = KnownHostsFile.fromPath(path)
        self.assertEqual([entry], list(knownHosts.iterentries()))
示例#9
0
    def test_saveResetsClobberState(self):
        """
        After L{KnownHostsFile.save} is used once with an instance initialized
        by the default initializer, contents of the save path are respected and
        preserved.
        """
        hostsFile = KnownHostsFile(self.pathWithContent(sampleHashedLine))
        preSave = hostsFile.addHostKey(
            "www.example.com", Key.fromString(otherSampleKey))
        hostsFile.save()
        postSave = hostsFile.addHostKey(
            "another.example.com", Key.fromString(thirdSampleKey))
        hostsFile.save()

        self.assertEqual([preSave, postSave], list(hostsFile.iterentries()))
示例#10
0
 def test_defaultInitializerClobbersExisting(self):
     """
     After using the default initializer for L{KnownHostsFile}, the first use
     of L{KnownHostsFile.save} overwrites any existing contents in the save
     path.
     """
     path = self.pathWithContent(sampleHashedLine)
     hostsFile = KnownHostsFile(path)
     entry = hostsFile.addHostKey(
         "www.example.com", Key.fromString(otherSampleKey))
     hostsFile.save()
     # Check KnownHostsFile to see what it thinks the state is
     self.assertEqual([entry], list(hostsFile.iterentries()))
     # And also directly check the underlying file itself
     self.assertEqual(entry.toString() + "\n", path.getContent())