예제 #1
0
    def test_same_server(self):
        from certbot_apache.obj import VirtualHost
        no_name1 = VirtualHost("fp", "vhp", set([self.addr1]), False, False,
                               None)
        no_name2 = VirtualHost("fp", "vhp", set([self.addr2]), False, False,
                               None)
        no_name3 = VirtualHost("fp", "vhp", set([self.addr_default]), False,
                               False, None)
        no_name4 = VirtualHost("fp", "vhp",
                               set([self.addr2,
                                    self.addr_default]), False, False, None)

        self.assertTrue(self.vhost1.same_server(self.vhost2))
        self.assertTrue(no_name1.same_server(no_name2))

        self.assertFalse(self.vhost1.same_server(no_name1))
        self.assertFalse(no_name1.same_server(no_name3))
        self.assertFalse(no_name1.same_server(no_name4))
예제 #2
0
    def test_same_server(self):
        from certbot_apache.obj import VirtualHost
        no_name1 = VirtualHost(
            "fp", "vhp", set([self.addr1]), False, False, None)
        no_name2 = VirtualHost(
            "fp", "vhp", set([self.addr2]), False, False, None)
        no_name3 = VirtualHost(
            "fp", "vhp", set([self.addr_default]),
            False, False, None)
        no_name4 = VirtualHost(
            "fp", "vhp", set([self.addr2, self.addr_default]),
            False, False, None)

        self.assertTrue(self.vhost1.same_server(self.vhost2))
        self.assertTrue(no_name1.same_server(no_name2))

        self.assertFalse(self.vhost1.same_server(no_name1))
        self.assertFalse(no_name1.same_server(no_name3))
        self.assertFalse(no_name1.same_server(no_name4))
예제 #3
0
class VirtualHostTest(unittest.TestCase):
    """Test the VirtualHost class."""
    def setUp(self):
        from certbot_apache.obj import Addr
        from certbot_apache.obj import VirtualHost

        self.addr1 = Addr.fromstring("127.0.0.1")
        self.addr2 = Addr.fromstring("127.0.0.1:443")
        self.addr_default = Addr.fromstring("_default_:443")

        self.vhost1 = VirtualHost("filep", "vh_path", set([self.addr1]), False,
                                  False, "localhost")

        self.vhost1b = VirtualHost("filep", "vh_path", set([self.addr1]),
                                   False, False, "localhost")

        self.vhost2 = VirtualHost("fp", "vhp", set([self.addr2]), False, False,
                                  "localhost")

    def test_eq(self):
        self.assertTrue(self.vhost1b == self.vhost1)
        self.assertFalse(self.vhost1 == self.vhost2)
        self.assertEqual(str(self.vhost1b), str(self.vhost1))
        self.assertFalse(self.vhost1b == 1234)

    def test_ne(self):
        self.assertTrue(self.vhost1 != self.vhost2)
        self.assertFalse(self.vhost1 != self.vhost1b)

    def test_conflicts(self):
        from certbot_apache.obj import Addr
        from certbot_apache.obj import VirtualHost

        complex_vh = VirtualHost(
            "fp", "vhp",
            set([Addr.fromstring("*:443"),
                 Addr.fromstring("1.2.3.4:443")]), False, False)
        self.assertTrue(complex_vh.conflicts([self.addr1]))
        self.assertTrue(complex_vh.conflicts([self.addr2]))
        self.assertFalse(complex_vh.conflicts([self.addr_default]))

        self.assertTrue(self.vhost1.conflicts([self.addr2]))
        self.assertFalse(self.vhost1.conflicts([self.addr_default]))

        self.assertFalse(self.vhost2.conflicts([self.addr1,
                                                self.addr_default]))

    def test_same_server(self):
        from certbot_apache.obj import VirtualHost
        no_name1 = VirtualHost("fp", "vhp", set([self.addr1]), False, False,
                               None)
        no_name2 = VirtualHost("fp", "vhp", set([self.addr2]), False, False,
                               None)
        no_name3 = VirtualHost("fp", "vhp", set([self.addr_default]), False,
                               False, None)
        no_name4 = VirtualHost("fp", "vhp",
                               set([self.addr2,
                                    self.addr_default]), False, False, None)

        self.assertTrue(self.vhost1.same_server(self.vhost2))
        self.assertTrue(no_name1.same_server(no_name2))

        self.assertFalse(self.vhost1.same_server(no_name1))
        self.assertFalse(no_name1.same_server(no_name3))
        self.assertFalse(no_name1.same_server(no_name4))
예제 #4
0
class VirtualHostTest(unittest.TestCase):
    """Test the VirtualHost class."""

    def setUp(self):
        from certbot_apache.obj import Addr
        from certbot_apache.obj import VirtualHost

        self.addr1 = Addr.fromstring("127.0.0.1")
        self.addr2 = Addr.fromstring("127.0.0.1:443")
        self.addr_default = Addr.fromstring("_default_:443")

        self.vhost1 = VirtualHost(
            "filep", "vh_path", set([self.addr1]), False, False, "localhost")

        self.vhost1b = VirtualHost(
            "filep", "vh_path", set([self.addr1]), False, False, "localhost")

        self.vhost2 = VirtualHost(
            "fp", "vhp", set([self.addr2]), False, False, "localhost")

    def test_repr(self):
        self.assertEqual(repr(self.addr2), "certbot_apache.obj.Addr(('127.0.0.1', '443'))")

    def test_eq(self):
        self.assertTrue(self.vhost1b == self.vhost1)
        self.assertFalse(self.vhost1 == self.vhost2)
        self.assertEqual(str(self.vhost1b), str(self.vhost1))
        self.assertFalse(self.vhost1b == 1234)

    def test_ne(self):
        self.assertTrue(self.vhost1 != self.vhost2)
        self.assertFalse(self.vhost1 != self.vhost1b)

    def test_conflicts(self):
        from certbot_apache.obj import Addr
        from certbot_apache.obj import VirtualHost

        complex_vh = VirtualHost(
            "fp", "vhp",
            set([Addr.fromstring("*:443"), Addr.fromstring("1.2.3.4:443")]),
            False, False)
        self.assertTrue(complex_vh.conflicts([self.addr1]))
        self.assertTrue(complex_vh.conflicts([self.addr2]))
        self.assertFalse(complex_vh.conflicts([self.addr_default]))

        self.assertTrue(self.vhost1.conflicts([self.addr2]))
        self.assertFalse(self.vhost1.conflicts([self.addr_default]))

        self.assertFalse(self.vhost2.conflicts([self.addr1,
                                                self.addr_default]))

    def test_same_server(self):
        from certbot_apache.obj import VirtualHost
        no_name1 = VirtualHost(
            "fp", "vhp", set([self.addr1]), False, False, None)
        no_name2 = VirtualHost(
            "fp", "vhp", set([self.addr2]), False, False, None)
        no_name3 = VirtualHost(
            "fp", "vhp", set([self.addr_default]),
            False, False, None)
        no_name4 = VirtualHost(
            "fp", "vhp", set([self.addr2, self.addr_default]),
            False, False, None)

        self.assertTrue(self.vhost1.same_server(self.vhost2))
        self.assertTrue(no_name1.same_server(no_name2))

        self.assertFalse(self.vhost1.same_server(no_name1))
        self.assertFalse(no_name1.same_server(no_name3))
        self.assertFalse(no_name1.same_server(no_name4))