示例#1
0
 def test_caseInsensitively(self):
     """
     L{searchFileForAll} searches for names case-insensitively.
     """
     hosts = self.path()
     hosts.setContent(b"127.0.0.1     foobar.EXAMPLE.com\n")
     self.assertEqual(["127.0.0.1"], searchFileForAll(hosts, b"FOOBAR.example.com"))
示例#2
0
 def test_readError(self):
     """
     If there is an error reading the contents of the hosts file,
     L{searchFileForAll} returns an empty list.
     """
     self.assertEqual(
         [], searchFileForAll(FilePath(self.mktemp()), "example.com"))
示例#3
0
 def test_caseInsensitively(self):
     """
     L{searchFileForAll} searches for names case-insensitively.
     """
     hosts = self.path()
     hosts.setContent(b"127.0.0.1     foobar.EXAMPLE.com\n")
     self.assertEqual(["127.0.0.1"], searchFileForAll(hosts, b"FOOBAR.example.com"))
示例#4
0
 def test_readError(self):
     """
     If there is an error reading the contents of the hosts file,
     L{searchFileForAll} returns an empty list.
     """
     self.assertEqual(
         [], searchFileForAll(self.path(), b"example.com"))
示例#5
0
 def test_allAddresses(self):
     """
     L{searchFileForAll} returns a list of all addresses associated with the
     name passed to it.
     """
     hosts = self.path()
     hosts.setContent(b"127.0.0.1     foobar.example.com\n"
                      b"127.0.0.2     foobar.example.com\n"
                      b"::1           foobar.example.com\n")
     self.assertEqual(["127.0.0.1", "127.0.0.2", "::1"],
                      searchFileForAll(hosts, b"foobar.example.com"))
示例#6
0
 def test_allAddresses(self):
     """
     L{searchFileForAll} returns a list of all addresses associated with the
     name passed to it.
     """
     hosts = self.path()
     hosts.setContent(
         b"127.0.0.1     foobar.example.com\n"
         b"127.0.0.2     foobar.example.com\n"
         b"::1           foobar.example.com\n"
     )
     self.assertEqual(["127.0.0.1", "127.0.0.2", "::1"], searchFileForAll(hosts, b"foobar.example.com"))
 def test_malformedIP(self):
     """
     L{searchFileForAll} ignores any malformed IP addresses associated with
     the name passed to it.
     """
     hosts = self.path()
     hosts.setContent(b"127.0.0.1\tmiser.example.org\tmiser\n"
                      b"not-an-ip\tmiser\n"
                      b"\xffnot-ascii\t miser\n"
                      b"# miser\n"
                      b"miser\n"
                      b"::1 miser")
     self.assertEqual(
         ["127.0.0.1", "::1"],
         searchFileForAll(hosts, b"miser"),
     )