Example #1
0
 def test_searchFileForAliases(self):
     """
     For a host with a canonical name and one or more aliases,
     L{searchFileFor} can find an address given any of the names.
     """
     hosts = self.path()
     hosts.setContent(
         b"127.0.1.1\thelmut.example.org\thelmut\n" b"# a comment\n" b"::1 localhost ip6-localhost ip6-loopback\n"
     )
     self.assertEqual(searchFileFor(hosts.path, b"helmut"), "127.0.1.1")
     self.assertEqual(searchFileFor(hosts.path, b"helmut.example.org"), "127.0.1.1")
     self.assertEqual(searchFileFor(hosts.path, b"ip6-localhost"), "::1")
     self.assertEqual(searchFileFor(hosts.path, b"ip6-loopback"), "::1")
     self.assertEqual(searchFileFor(hosts.path, b"localhost"), "::1")
Example #2
0
 def test_searchFileFor(self):
     """
     L{searchFileFor} parses hosts(5) files and returns the address for
     the given name, or C{None} if the name is not found.
     """
     tmp = self.mktemp()
     f = open(tmp, 'w')
     f.write('127.0.1.1	helmut.example.org	helmut\n')
     f.write('# a comment\n')
     f.write('::1     localhost ip6-localhost ip6-loopback\n')
     f.close()
     self.assertEquals(hosts.searchFileFor(tmp, 'helmut'), '127.0.1.1')
     self.assertEquals(hosts.searchFileFor(tmp, 'ip6-localhost'), '::1')
     self.assertIdentical(hosts.searchFileFor(tmp, 'blah'), None)
 def test_searchFileFor(self):
     """
     L{searchFileFor} parses hosts(5) files and returns the address for
     the given name, or C{None} if the name is not found.
     """
     tmp = self.mktemp()
     f = open(tmp, 'w')
     f.write('127.0.1.1	helmut.example.org	helmut\n')
     f.write('# a comment\n')
     f.write('::1     localhost ip6-localhost ip6-loopback\n')
     f.close()
     self.assertEquals(hosts.searchFileFor(tmp, 'helmut'), '127.0.1.1')
     self.assertEquals(hosts.searchFileFor(tmp, 'ip6-localhost'), '::1')
     self.assertIdentical(hosts.searchFileFor(tmp, 'blah'), None)
Example #4
0
 def test_searchFileForAliases(self):
     """
     For a host with a canonical name and one or more aliases,
     L{searchFileFor} can find an address given any of the names.
     """
     hosts = self.path()
     hosts.setContent(b"127.0.1.1\thelmut.example.org\thelmut\n"
                      b"# a comment\n"
                      b"::1 localhost ip6-localhost ip6-loopback\n")
     self.assertEqual(searchFileFor(hosts.path, b'helmut'), '127.0.1.1')
     self.assertEqual(searchFileFor(hosts.path, b'helmut.example.org'),
                      '127.0.1.1')
     self.assertEqual(searchFileFor(hosts.path, b'ip6-localhost'), '::1')
     self.assertEqual(searchFileFor(hosts.path, b'ip6-loopback'), '::1')
     self.assertEqual(searchFileFor(hosts.path, b'localhost'), '::1')
Example #5
0
 def test_searchFileForAliases(self):
     """
     For a host with a canonical name and one or more aliases,
     L{searchFileFor} can find an address given any of the names.
     """
     hosts = FilePath(self.mktemp())
     hosts.setContent(
         "127.0.1.1	helmut.example.org	helmut\n"
         "# a comment\n"
         "::1     localhost ip6-localhost ip6-loopback\n")
     self.assertEqual(searchFileFor(hosts.path, 'helmut'), '127.0.1.1')
     self.assertEqual(
         searchFileFor(hosts.path, 'helmut.example.org'), '127.0.1.1')
     self.assertEqual(searchFileFor(hosts.path, 'ip6-localhost'), '::1')
     self.assertEqual(searchFileFor(hosts.path, 'ip6-loopback'), '::1')
     self.assertEqual(searchFileFor(hosts.path, 'localhost'), '::1')
Example #6
0
 def test_notFoundAddress(self):
     """
     If there is no address information for the hostname passed to
     L{searchFileFor}, L{None} is returned.
     """
     hosts = self.path()
     hosts.setContent(b"10.2.3.4 foo.example.com\n")
     self.assertIsNone(searchFileFor(hosts.path, b"bar.example.com"))
Example #7
0
 def test_findAddress(self):
     """
     If there is an IPv4 address for the hostname passed to L{searchFileFor},
     it is returned.
     """
     hosts = self.path()
     hosts.setContent(b"10.2.3.4 foo.example.com\n")
     self.assertEqual("10.2.3.4", searchFileFor(hosts.path, b"foo.example.com"))
Example #8
0
 def test_notFoundAddress(self):
     """
     If there is no address information for the hostname passed to
     L{searchFileFor}, C{None} is returned.
     """
     hosts = self.path()
     hosts.setContent(b"10.2.3.4 foo.example.com\n")
     self.assertIs(None, searchFileFor(hosts.path, b"bar.example.com"))
Example #9
0
 def test_findAddress(self):
     """
     If there is an IPv4 address for the hostname passed to L{searchFileFor},
     it is returned.
     """
     hosts = self.path()
     hosts.setContent(b"10.2.3.4 foo.example.com\n")
     self.assertEqual("10.2.3.4", searchFileFor(hosts.path, b"foo.example.com"))
Example #10
0
 def test_firstAddress(self):
     """
     The first address associated with the given hostname is returned.
     """
     hosts = self.path()
     hosts.setContent(
         b"::1 foo.example.com\n" b"10.1.2.3 foo.example.com\n" b"fe80::21b:fcff:feee:5a1d foo.example.com\n"
     )
     self.assertEqual("::1", searchFileFor(hosts.path, b"foo.example.com"))
Example #11
0
 def test_firstAddress(self):
     """
     The first address associated with the given hostname is returned.
     """
     hosts = self.path()
     hosts.setContent(b"::1 foo.example.com\n"
                      b"10.1.2.3 foo.example.com\n"
                      b"fe80::21b:fcff:feee:5a1d foo.example.com\n")
     self.assertEqual("::1", searchFileFor(hosts.path, b"foo.example.com"))
Example #12
0
 def test_notFoundAddress(self):
     """
     If there is no address information for the hostname passed to
     L{searchFileFor}, C{None} is returned.
     """
     hosts = FilePath(self.mktemp())
     hosts.setContent("10.2.3.4 foo.example.com\n")
     self.assertIdentical(None, searchFileFor(hosts.path,
                                              "bar.example.com"))