certbot/certbot-apache/certbot_apache/_internal/tests/obj_test.py

141 lines
5 KiB
Python
Raw Permalink Normal View History

Make the contents of the apache plugin private (#7579) Part of #5775. Tree: ``` certbot-apache/certbot_apache ├── __init__.py ├── _internal │   ├── apache_util.py │   ├── augeas_lens │   │   ├── httpd.aug │   │   └── README │   ├── centos-options-ssl-apache.conf │   ├── configurator.py │   ├── constants.py │   ├── display_ops.py │   ├── entrypoint.py │   ├── http_01.py │   ├── __init__.py │   ├── obj.py │   ├── options-ssl-apache.conf │   ├── override_arch.py │   ├── override_centos.py │   ├── override_darwin.py │   ├── override_debian.py │   ├── override_fedora.py │   ├── override_gentoo.py │   ├── override_suse.py │   └── parser.py └── tests ├── ... ``` * Create _internal folder for certbot_apache * Move apache_util.py to _internal * Move display_ops.py to _internal * Move override_centos.py to _internal * Move override_gentoo.py to _internal * Move override_darwin.py to _internal * Move override_suse.py to _internal * Move override_debian.py to _internal * Move override_fedora.py to _internal * Move override_arch.py to _internal * Move parser.py to _internal * Move obj.py to _internal * Move http_01.py to _internal * Move entrypoint.py to _internal * Move constants.py to _internal * Move configurator.py to _internal * Move augeas_lens to _internal * Move options-ssl-apache.conf files to _internal * move augeas_lens in MANIFEST * Clean up some stray references to certbot_apache that could use _internal * Correct imports and lint
2019-11-25 12:44:40 -05:00
"""Tests for certbot_apache._internal.obj."""
import sys
2014-12-19 18:49:29 -05:00
import unittest
import pytest
2014-12-19 18:49:29 -05:00
class VirtualHostTest(unittest.TestCase):
"""Test the VirtualHost class."""
2014-12-19 18:49:29 -05:00
def setUp(self):
Make the contents of the apache plugin private (#7579) Part of #5775. Tree: ``` certbot-apache/certbot_apache ├── __init__.py ├── _internal │   ├── apache_util.py │   ├── augeas_lens │   │   ├── httpd.aug │   │   └── README │   ├── centos-options-ssl-apache.conf │   ├── configurator.py │   ├── constants.py │   ├── display_ops.py │   ├── entrypoint.py │   ├── http_01.py │   ├── __init__.py │   ├── obj.py │   ├── options-ssl-apache.conf │   ├── override_arch.py │   ├── override_centos.py │   ├── override_darwin.py │   ├── override_debian.py │   ├── override_fedora.py │   ├── override_gentoo.py │   ├── override_suse.py │   └── parser.py └── tests ├── ... ``` * Create _internal folder for certbot_apache * Move apache_util.py to _internal * Move display_ops.py to _internal * Move override_centos.py to _internal * Move override_gentoo.py to _internal * Move override_darwin.py to _internal * Move override_suse.py to _internal * Move override_debian.py to _internal * Move override_fedora.py to _internal * Move override_arch.py to _internal * Move parser.py to _internal * Move obj.py to _internal * Move http_01.py to _internal * Move entrypoint.py to _internal * Move constants.py to _internal * Move configurator.py to _internal * Move augeas_lens to _internal * Move options-ssl-apache.conf files to _internal * move augeas_lens in MANIFEST * Clean up some stray references to certbot_apache that could use _internal * Correct imports and lint
2019-11-25 12:44:40 -05:00
from certbot_apache._internal.obj import Addr
from certbot_apache._internal.obj import VirtualHost
2015-07-23 04:34:51 -04:00
self.addr1 = Addr.fromstring("127.0.0.1")
self.addr2 = Addr.fromstring("127.0.0.1:443")
self.addr_default = Addr.fromstring("_default_:443")
2015-01-10 01:25:36 -05:00
self.vhost1 = VirtualHost(
"filep", "vh_path", {self.addr1}, False, False, "localhost")
2015-07-23 04:34:51 -04:00
self.vhost1b = VirtualHost(
"filep", "vh_path", {self.addr1}, False, False, "localhost")
2015-07-23 04:34:51 -04:00
self.vhost2 = VirtualHost(
"fp", "vhp", {self.addr2}, False, False, "localhost")
2014-12-19 18:49:29 -05:00
2016-06-25 13:51:14 -04:00
def test_repr(self):
assert repr(self.addr2) == \
"certbot_apache._internal.obj.Addr(('127.0.0.1', '443'))"
2016-06-25 13:51:14 -04:00
2014-12-19 18:49:29 -05:00
def test_eq(self):
assert self.vhost1b == self.vhost1
assert self.vhost1 != self.vhost2
assert str(self.vhost1b) == str(self.vhost1)
assert self.vhost1b != 1234
2015-07-23 04:34:51 -04:00
def test_ne(self):
assert self.vhost1 != self.vhost2
assert self.vhost1 == self.vhost1b
2015-07-23 04:34:51 -04:00
def test_conflicts(self):
Make the contents of the apache plugin private (#7579) Part of #5775. Tree: ``` certbot-apache/certbot_apache ├── __init__.py ├── _internal │   ├── apache_util.py │   ├── augeas_lens │   │   ├── httpd.aug │   │   └── README │   ├── centos-options-ssl-apache.conf │   ├── configurator.py │   ├── constants.py │   ├── display_ops.py │   ├── entrypoint.py │   ├── http_01.py │   ├── __init__.py │   ├── obj.py │   ├── options-ssl-apache.conf │   ├── override_arch.py │   ├── override_centos.py │   ├── override_darwin.py │   ├── override_debian.py │   ├── override_fedora.py │   ├── override_gentoo.py │   ├── override_suse.py │   └── parser.py └── tests ├── ... ``` * Create _internal folder for certbot_apache * Move apache_util.py to _internal * Move display_ops.py to _internal * Move override_centos.py to _internal * Move override_gentoo.py to _internal * Move override_darwin.py to _internal * Move override_suse.py to _internal * Move override_debian.py to _internal * Move override_fedora.py to _internal * Move override_arch.py to _internal * Move parser.py to _internal * Move obj.py to _internal * Move http_01.py to _internal * Move entrypoint.py to _internal * Move constants.py to _internal * Move configurator.py to _internal * Move augeas_lens to _internal * Move options-ssl-apache.conf files to _internal * move augeas_lens in MANIFEST * Clean up some stray references to certbot_apache that could use _internal * Correct imports and lint
2019-11-25 12:44:40 -05:00
from certbot_apache._internal.obj import Addr
from certbot_apache._internal.obj import VirtualHost
2015-07-23 04:34:51 -04:00
complex_vh = VirtualHost(
"fp", "vhp",
{Addr.fromstring("*:443"), Addr.fromstring("1.2.3.4:443")},
2015-07-23 04:34:51 -04:00
False, False)
assert complex_vh.conflicts([self.addr1]) is True
assert complex_vh.conflicts([self.addr2]) is True
assert complex_vh.conflicts([self.addr_default]) is False
2015-07-23 04:34:51 -04:00
assert self.vhost1.conflicts([self.addr2]) is True
assert self.vhost1.conflicts([self.addr_default]) is False
2015-07-23 04:34:51 -04:00
assert self.vhost2.conflicts([self.addr1, self.addr_default]) is False
2015-07-23 04:34:51 -04:00
def test_same_server(self):
Make the contents of the apache plugin private (#7579) Part of #5775. Tree: ``` certbot-apache/certbot_apache ├── __init__.py ├── _internal │   ├── apache_util.py │   ├── augeas_lens │   │   ├── httpd.aug │   │   └── README │   ├── centos-options-ssl-apache.conf │   ├── configurator.py │   ├── constants.py │   ├── display_ops.py │   ├── entrypoint.py │   ├── http_01.py │   ├── __init__.py │   ├── obj.py │   ├── options-ssl-apache.conf │   ├── override_arch.py │   ├── override_centos.py │   ├── override_darwin.py │   ├── override_debian.py │   ├── override_fedora.py │   ├── override_gentoo.py │   ├── override_suse.py │   └── parser.py └── tests ├── ... ``` * Create _internal folder for certbot_apache * Move apache_util.py to _internal * Move display_ops.py to _internal * Move override_centos.py to _internal * Move override_gentoo.py to _internal * Move override_darwin.py to _internal * Move override_suse.py to _internal * Move override_debian.py to _internal * Move override_fedora.py to _internal * Move override_arch.py to _internal * Move parser.py to _internal * Move obj.py to _internal * Move http_01.py to _internal * Move entrypoint.py to _internal * Move constants.py to _internal * Move configurator.py to _internal * Move augeas_lens to _internal * Move options-ssl-apache.conf files to _internal * move augeas_lens in MANIFEST * Clean up some stray references to certbot_apache that could use _internal * Correct imports and lint
2019-11-25 12:44:40 -05:00
from certbot_apache._internal.obj import VirtualHost
2015-07-23 04:34:51 -04:00
no_name1 = VirtualHost(
"fp", "vhp", {self.addr1}, False, False, None)
2015-07-23 04:34:51 -04:00
no_name2 = VirtualHost(
"fp", "vhp", {self.addr2}, False, False, None)
2015-07-23 04:34:51 -04:00
no_name3 = VirtualHost(
"fp", "vhp", {self.addr_default},
2015-07-23 04:34:51 -04:00
False, False, None)
no_name4 = VirtualHost(
"fp", "vhp", {self.addr2, self.addr_default},
2015-07-23 04:34:51 -04:00
False, False, None)
assert self.vhost1.same_server(self.vhost2) is True
assert no_name1.same_server(no_name2) is True
2014-12-19 18:49:29 -05:00
assert self.vhost1.same_server(no_name1) is False
assert no_name1.same_server(no_name3) is False
assert no_name1.same_server(no_name4) is False
2015-02-02 13:47:44 -05:00
2015-07-19 22:49:44 -04:00
class AddrTest(unittest.TestCase):
"""Test obj.Addr."""
def setUp(self):
Make the contents of the apache plugin private (#7579) Part of #5775. Tree: ``` certbot-apache/certbot_apache ├── __init__.py ├── _internal │   ├── apache_util.py │   ├── augeas_lens │   │   ├── httpd.aug │   │   └── README │   ├── centos-options-ssl-apache.conf │   ├── configurator.py │   ├── constants.py │   ├── display_ops.py │   ├── entrypoint.py │   ├── http_01.py │   ├── __init__.py │   ├── obj.py │   ├── options-ssl-apache.conf │   ├── override_arch.py │   ├── override_centos.py │   ├── override_darwin.py │   ├── override_debian.py │   ├── override_fedora.py │   ├── override_gentoo.py │   ├── override_suse.py │   └── parser.py └── tests ├── ... ``` * Create _internal folder for certbot_apache * Move apache_util.py to _internal * Move display_ops.py to _internal * Move override_centos.py to _internal * Move override_gentoo.py to _internal * Move override_darwin.py to _internal * Move override_suse.py to _internal * Move override_debian.py to _internal * Move override_fedora.py to _internal * Move override_arch.py to _internal * Move parser.py to _internal * Move obj.py to _internal * Move http_01.py to _internal * Move entrypoint.py to _internal * Move constants.py to _internal * Move configurator.py to _internal * Move augeas_lens to _internal * Move options-ssl-apache.conf files to _internal * move augeas_lens in MANIFEST * Clean up some stray references to certbot_apache that could use _internal * Correct imports and lint
2019-11-25 12:44:40 -05:00
from certbot_apache._internal.obj import Addr
2015-07-19 22:49:44 -04:00
self.addr = Addr.fromstring("*:443")
self.addr1 = Addr.fromstring("127.0.0.1")
self.addr2 = Addr.fromstring("127.0.0.1:*")
2015-07-23 04:34:51 -04:00
self.addr_defined = Addr.fromstring("127.0.0.1:443")
self.addr_default = Addr.fromstring("_default_:443")
2015-07-19 22:49:44 -04:00
def test_wildcard(self):
assert self.addr.is_wildcard() is False
assert self.addr1.is_wildcard() is True
assert self.addr2.is_wildcard() is True
2015-07-19 22:49:44 -04:00
def test_get_sni_addr(self):
Make the contents of the apache plugin private (#7579) Part of #5775. Tree: ``` certbot-apache/certbot_apache ├── __init__.py ├── _internal │   ├── apache_util.py │   ├── augeas_lens │   │   ├── httpd.aug │   │   └── README │   ├── centos-options-ssl-apache.conf │   ├── configurator.py │   ├── constants.py │   ├── display_ops.py │   ├── entrypoint.py │   ├── http_01.py │   ├── __init__.py │   ├── obj.py │   ├── options-ssl-apache.conf │   ├── override_arch.py │   ├── override_centos.py │   ├── override_darwin.py │   ├── override_debian.py │   ├── override_fedora.py │   ├── override_gentoo.py │   ├── override_suse.py │   └── parser.py └── tests ├── ... ``` * Create _internal folder for certbot_apache * Move apache_util.py to _internal * Move display_ops.py to _internal * Move override_centos.py to _internal * Move override_gentoo.py to _internal * Move override_darwin.py to _internal * Move override_suse.py to _internal * Move override_debian.py to _internal * Move override_fedora.py to _internal * Move override_arch.py to _internal * Move parser.py to _internal * Move obj.py to _internal * Move http_01.py to _internal * Move entrypoint.py to _internal * Move constants.py to _internal * Move configurator.py to _internal * Move augeas_lens to _internal * Move options-ssl-apache.conf files to _internal * move augeas_lens in MANIFEST * Clean up some stray references to certbot_apache that could use _internal * Correct imports and lint
2019-11-25 12:44:40 -05:00
from certbot_apache._internal.obj import Addr
assert self.addr.get_sni_addr("443") == Addr.fromstring("*:443")
assert self.addr.get_sni_addr("225") == Addr.fromstring("*:225")
assert self.addr1.get_sni_addr("443") == Addr.fromstring("127.0.0.1")
2015-07-19 22:49:44 -04:00
2015-07-23 04:34:51 -04:00
def test_conflicts(self):
# Note: Defined IP is more important than defined port in match
assert self.addr.conflicts(self.addr1) is True
assert self.addr.conflicts(self.addr2) is True
assert self.addr.conflicts(self.addr_defined) is True
assert self.addr.conflicts(self.addr_default) is False
2015-07-23 04:34:51 -04:00
assert self.addr1.conflicts(self.addr) is False
assert self.addr1.conflicts(self.addr_defined) is True
assert self.addr1.conflicts(self.addr_default) is False
2015-07-23 04:34:51 -04:00
assert self.addr_defined.conflicts(self.addr1) is False
assert self.addr_defined.conflicts(self.addr2) is False
assert self.addr_defined.conflicts(self.addr) is False
assert self.addr_defined.conflicts(self.addr_default) is False
2015-07-23 04:34:51 -04:00
assert self.addr_default.conflicts(self.addr) is True
assert self.addr_default.conflicts(self.addr1) is True
assert self.addr_default.conflicts(self.addr_defined) is True
2015-07-23 04:34:51 -04:00
# Self test
assert self.addr.conflicts(self.addr) is True
assert self.addr1.conflicts(self.addr1) is True
2015-07-23 04:34:51 -04:00
# This is a tricky one...
assert self.addr1.conflicts(self.addr2) is True
2015-07-23 04:34:51 -04:00
2015-07-19 22:49:44 -04:00
def test_equal(self):
assert self.addr1 == self.addr2
assert self.addr != self.addr1
assert self.addr != 123
2015-07-19 22:49:44 -04:00
def test_not_equal(self):
assert self.addr1 == self.addr2
assert self.addr != self.addr1
2015-07-19 22:49:44 -04:00
2015-02-02 13:47:44 -05:00
if __name__ == "__main__":
sys.exit(pytest.main(sys.argv[1:] + [__file__])) # pragma: no cover