def setUp(self): from certbot_nginx.obj import VirtualHost from certbot_nginx.obj import Addr raw1 = [['listen', '69.50.225.155:9000'], [['if', '($scheme', '!=', '"https") '], [['return', '301', 'https://$host$request_uri']]], ['#', ' managed by Certbot']] self.vhost1 = VirtualHost("filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw1, []) raw2 = [['listen', '69.50.225.155:9000'], [['if', '($scheme', '!=', '"https") '], [['return', '301', 'https://$host$request_uri']]]] self.vhost2 = VirtualHost("filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw2, []) raw3 = [['listen', '69.50.225.155:9000'], [ 'rewrite', '^(.*)$', '$scheme://www.domain.com$1', 'permanent' ]] self.vhost3 = VirtualHost("filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw3, []) raw4 = [['listen', '69.50.225.155:9000'], ['server_name', 'return.com']] self.vhost4 = VirtualHost("filp", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw4, [])
def setUp(self): from certbot_nginx.obj import VirtualHost from certbot_nginx.obj import Addr raw1 = [ ['listen', '69.50.225.155:9000'], [['if', '($scheme', '!=', '"https") '], [['return', '301', 'https://$host$request_uri']] ], ['#', ' managed by Certbot'] ] self.vhost1 = VirtualHost( "filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw1, []) raw2 = [ ['listen', '69.50.225.155:9000'], [['if', '($scheme', '!=', '"https") '], [['return', '301', 'https://$host$request_uri']] ] ] self.vhost2 = VirtualHost( "filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw2, []) raw3 = [ ['listen', '69.50.225.155:9000'], ['rewrite', '^(.*)$', '$scheme://www.domain.com$1', 'permanent'] ] self.vhost3 = VirtualHost( "filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw3, []) raw4 = [ ['listen', '69.50.225.155:9000'], ['server_name', 'return.com'] ] self.vhost4 = VirtualHost( "filp", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw4, []) raw_has_hsts = [ ['listen', '69.50.225.155:9000'], ['server_name', 'return.com'], ['add_header', 'always', 'set', 'Strict-Transport-Security', '\"max-age=31536000\"'], ] self.vhost_has_hsts = VirtualHost( "filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw_has_hsts, [])
def setUp(self): from certbot_nginx.obj import VirtualHost from certbot_nginx.obj import Addr self.vhost1 = VirtualHost( "filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), [], [])
def test_eq(self): from certbot_nginx.obj import Addr from certbot_nginx.obj import VirtualHost vhost1b = VirtualHost("filep", set([Addr.fromstring("localhost blah")]), False, False, set(['localhost']), [], []) self.assertEqual(vhost1b, self.vhost1) self.assertEqual(str(vhost1b), str(self.vhost1)) self.assertFalse(vhost1b == 1234)
def test_contains_list(self): from certbot_nginx.obj import VirtualHost from certbot_nginx.obj import Addr from certbot_nginx.configurator import TEST_REDIRECT_BLOCK test_needle = TEST_REDIRECT_BLOCK test_haystack = [['listen', '80'], ['root', '/var/www/html'], ['index', 'index.html index.htm index.nginx-debian.html'], ['server_name', 'two.functorkitten.xyz'], ['listen', '443 ssl'], ['#', ' managed by Certbot'], ['ssl_certificate', '/etc/letsencrypt/live/two.functorkitten.xyz/fullchain.pem'], ['#', ' managed by Certbot'], ['ssl_certificate_key', '/etc/letsencrypt/live/two.functorkitten.xyz/privkey.pem'], ['#', ' managed by Certbot'], [['if', '($scheme != "https")'], [['return', '301 https://$host$request_uri']]], ['#', ' managed by Certbot'], []] vhost_haystack = VirtualHost( "filp", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), test_haystack, []) test_bad_haystack = [['listen', '80'], ['root', '/var/www/html'], ['index', 'index.html index.htm index.nginx-debian.html'], ['server_name', 'two.functorkitten.xyz'], ['listen', '443 ssl'], ['#', ' managed by Certbot'], ['ssl_certificate', '/etc/letsencrypt/live/two.functorkitten.xyz/fullchain.pem'], ['#', ' managed by Certbot'], ['ssl_certificate_key', '/etc/letsencrypt/live/two.functorkitten.xyz/privkey.pem'], ['#', ' managed by Certbot'], [['if', '($scheme != "https")'], [['return', '302 https://$host$request_uri']]], ['#', ' managed by Certbot'], []] vhost_bad_haystack = VirtualHost( "filp", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), test_bad_haystack, []) self.assertTrue(vhost_haystack.contains_list(test_needle)) self.assertFalse(vhost_bad_haystack.contains_list(test_needle))
def setUp(self): from certbot_nginx.obj import VirtualHost from certbot_nginx.obj import Addr raw1 = [ ['listen', '69.50.225.155:9000'], [['if', '($scheme != "https") '], [['return', '301 https://$host$request_uri']] ], ['#', ' managed by Certbot'] ] self.vhost1 = VirtualHost( "filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw1, []) raw2 = [ ['listen', '69.50.225.155:9000'], [['if', '($scheme != "https") '], [['return', '301 https://$host$request_uri']] ] ] self.vhost2 = VirtualHost( "filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw2, []) raw3 = [ ['listen', '69.50.225.155:9000'], ['rewrite', '^(.*)$ $scheme://www.domain.com$1 permanent;'] ] self.vhost3 = VirtualHost( "filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw3, []) raw4 = [ ['listen', '69.50.225.155:9000'], ['server_name', 'return.com'] ] self.vhost4 = VirtualHost( "filp", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw4, [])
class VirtualHostTest(unittest.TestCase): """Test the VirtualHost class.""" def setUp(self): from certbot_nginx.obj import VirtualHost from certbot_nginx.obj import Addr raw1 = [['listen', '69.50.225.155:9000'], [['if', '($scheme', '!=', '"https") '], [['return', '301', 'https://$host$request_uri']]], ['#', ' managed by Certbot']] self.vhost1 = VirtualHost("filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw1, []) raw2 = [['listen', '69.50.225.155:9000'], [['if', '($scheme', '!=', '"https") '], [['return', '301', 'https://$host$request_uri']]]] self.vhost2 = VirtualHost("filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw2, []) raw3 = [['listen', '69.50.225.155:9000'], [ 'rewrite', '^(.*)$', '$scheme://www.domain.com$1', 'permanent' ]] self.vhost3 = VirtualHost("filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw3, []) raw4 = [['listen', '69.50.225.155:9000'], ['server_name', 'return.com']] self.vhost4 = VirtualHost("filp", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw4, []) raw_has_hsts = [ ['listen', '69.50.225.155:9000'], ['server_name', 'return.com'], [ 'add_header', 'always', 'set', 'Strict-Transport-Security', '\"max-age=31536000\"' ], ] self.vhost_has_hsts = VirtualHost("filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw_has_hsts, []) def test_eq(self): from certbot_nginx.obj import Addr from certbot_nginx.obj import VirtualHost vhost1b = VirtualHost("filep", set([Addr.fromstring("localhost blah")]), False, False, set(['localhost']), [], []) self.assertEqual(vhost1b, self.vhost1) self.assertEqual(str(vhost1b), str(self.vhost1)) self.assertFalse(vhost1b == 1234) def test_str(self): stringified = '\n'.join([ 'file: filep', 'addrs: localhost', "names: ['localhost']", 'ssl: False', 'enabled: False' ]) self.assertEqual(stringified, str(self.vhost1)) def test_has_header(self): self.assertTrue( self.vhost_has_hsts.has_header('Strict-Transport-Security')) self.assertFalse(self.vhost_has_hsts.has_header('Bogus-Header')) self.assertFalse(self.vhost1.has_header('Strict-Transport-Security')) self.assertFalse(self.vhost1.has_header('Bogus-Header')) def test_contains_list(self): from certbot_nginx.obj import VirtualHost from certbot_nginx.obj import Addr from certbot_nginx.configurator import _test_block_from_block test_block = [[ '\n ', 'return', ' ', '301', ' ', 'https://$host$request_uri' ], ['\n']] test_needle = _test_block_from_block(test_block) test_haystack = [ ['listen', '80'], ['root', '/var/www/html'], ['index', 'index.html index.htm index.nginx-debian.html'], ['server_name', 'two.functorkitten.xyz'], ['listen', '443 ssl'], ['#', ' managed by Certbot'], [ 'ssl_certificate', '/etc/letsencrypt/live/two.functorkitten.xyz/fullchain.pem' ], ['#', ' managed by Certbot'], [ 'ssl_certificate_key', '/etc/letsencrypt/live/two.functorkitten.xyz/privkey.pem' ], ['#', ' managed by Certbot'], ['return', '301', 'https://$host$request_uri'], ['#', ' managed by Certbot'], [] ] vhost_haystack = VirtualHost("filp", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), test_haystack, []) test_bad_haystack = [ ['listen', '80'], ['root', '/var/www/html'], ['index', 'index.html index.htm index.nginx-debian.html'], ['server_name', 'two.functorkitten.xyz'], ['listen', '443 ssl'], ['#', ' managed by Certbot'], [ 'ssl_certificate', '/etc/letsencrypt/live/two.functorkitten.xyz/fullchain.pem' ], ['#', ' managed by Certbot'], [ 'ssl_certificate_key', '/etc/letsencrypt/live/two.functorkitten.xyz/privkey.pem' ], ['#', ' managed by Certbot'], [['if', '($scheme', '!=', '"https")'], [['return', '302', 'https://$host$request_uri']]], ['#', ' managed by Certbot'], [] ] vhost_bad_haystack = VirtualHost("filp", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), test_bad_haystack, []) self.assertTrue(vhost_haystack.contains_list(test_needle)) self.assertFalse(vhost_bad_haystack.contains_list(test_needle))
class VirtualHostTest(unittest.TestCase): """Test the VirtualHost class.""" def setUp(self): from certbot_nginx.obj import VirtualHost from certbot_nginx.obj import Addr raw1 = [ ['listen', '69.50.225.155:9000'], [['if', '($scheme', '!=', '"https") '], [['return', '301', 'https://$host$request_uri']] ], ['#', ' managed by Certbot'] ] self.vhost1 = VirtualHost( "filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw1, []) raw2 = [ ['listen', '69.50.225.155:9000'], [['if', '($scheme', '!=', '"https") '], [['return', '301', 'https://$host$request_uri']] ] ] self.vhost2 = VirtualHost( "filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw2, []) raw3 = [ ['listen', '69.50.225.155:9000'], ['rewrite', '^(.*)$', '$scheme://www.domain.com$1', 'permanent'] ] self.vhost3 = VirtualHost( "filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw3, []) raw4 = [ ['listen', '69.50.225.155:9000'], ['server_name', 'return.com'] ] self.vhost4 = VirtualHost( "filp", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw4, []) def test_eq(self): from certbot_nginx.obj import Addr from certbot_nginx.obj import VirtualHost vhost1b = VirtualHost( "filep", set([Addr.fromstring("localhost blah")]), False, False, set(['localhost']), [], []) self.assertEqual(vhost1b, self.vhost1) self.assertEqual(str(vhost1b), str(self.vhost1)) self.assertFalse(vhost1b == 1234) def test_str(self): stringified = '\n'.join(['file: filep', 'addrs: localhost', "names: ['localhost']", 'ssl: False', 'enabled: False']) self.assertEqual(stringified, str(self.vhost1)) def test_has_redirect(self): self.assertTrue(self.vhost1.has_redirect()) self.assertTrue(self.vhost2.has_redirect()) self.assertTrue(self.vhost3.has_redirect()) self.assertFalse(self.vhost4.has_redirect()) def test_contains_list(self): from certbot_nginx.obj import VirtualHost from certbot_nginx.obj import Addr from certbot_nginx.configurator import TEST_REDIRECT_BLOCK test_needle = TEST_REDIRECT_BLOCK test_haystack = [['listen', '80'], ['root', '/var/www/html'], ['index', 'index.html index.htm index.nginx-debian.html'], ['server_name', 'two.functorkitten.xyz'], ['listen', '443 ssl'], ['#', ' managed by Certbot'], ['ssl_certificate', '/etc/letsencrypt/live/two.functorkitten.xyz/fullchain.pem'], ['#', ' managed by Certbot'], ['ssl_certificate_key', '/etc/letsencrypt/live/two.functorkitten.xyz/privkey.pem'], ['#', ' managed by Certbot'], [['if', '($scheme', '!=', '"https")'], [['return', '301', 'https://$host$request_uri']] ], ['#', ' managed by Certbot'], []] vhost_haystack = VirtualHost( "filp", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), test_haystack, []) test_bad_haystack = [['listen', '80'], ['root', '/var/www/html'], ['index', 'index.html index.htm index.nginx-debian.html'], ['server_name', 'two.functorkitten.xyz'], ['listen', '443 ssl'], ['#', ' managed by Certbot'], ['ssl_certificate', '/etc/letsencrypt/live/two.functorkitten.xyz/fullchain.pem'], ['#', ' managed by Certbot'], ['ssl_certificate_key', '/etc/letsencrypt/live/two.functorkitten.xyz/privkey.pem'], ['#', ' managed by Certbot'], [['if', '($scheme', '!=', '"https")'], [['return', '302', 'https://$host$request_uri']] ], ['#', ' managed by Certbot'], []] vhost_bad_haystack = VirtualHost( "filp", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), test_bad_haystack, []) self.assertTrue(vhost_haystack.contains_list(test_needle)) self.assertFalse(vhost_bad_haystack.contains_list(test_needle))
class VirtualHostTest(unittest.TestCase): """Test the VirtualHost class.""" def setUp(self): from certbot_nginx.obj import VirtualHost from certbot_nginx.obj import Addr raw1 = [['listen', '69.50.225.155:9000'], [['if', '($scheme != "https") '], [['return', '301 https://$host$request_uri']]], ['#', ' managed by Certbot']] self.vhost1 = VirtualHost("filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw1, []) raw2 = [['listen', '69.50.225.155:9000'], [['if', '($scheme != "https") '], [['return', '301 https://$host$request_uri']]]] self.vhost2 = VirtualHost("filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw2, []) raw3 = [['listen', '69.50.225.155:9000'], ['rewrite', '^(.*)$ $scheme://www.domain.com$1 permanent;']] self.vhost3 = VirtualHost("filep", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw3, []) raw4 = [['listen', '69.50.225.155:9000'], ['server_name', 'return.com']] self.vhost4 = VirtualHost("filp", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), raw4, []) def test_eq(self): from certbot_nginx.obj import Addr from certbot_nginx.obj import VirtualHost vhost1b = VirtualHost("filep", set([Addr.fromstring("localhost blah")]), False, False, set(['localhost']), [], []) self.assertEqual(vhost1b, self.vhost1) self.assertEqual(str(vhost1b), str(self.vhost1)) self.assertFalse(vhost1b == 1234) def test_str(self): stringified = '\n'.join([ 'file: filep', 'addrs: localhost', "names: set(['localhost'])", 'ssl: False', 'enabled: False' ]) self.assertEqual(stringified, str(self.vhost1)) def test_has_redirect(self): self.assertTrue(self.vhost1.has_redirect()) self.assertTrue(self.vhost2.has_redirect()) self.assertTrue(self.vhost3.has_redirect()) self.assertFalse(self.vhost4.has_redirect()) def test_contains_list(self): from certbot_nginx.obj import VirtualHost from certbot_nginx.obj import Addr from certbot_nginx.configurator import TEST_REDIRECT_BLOCK test_needle = TEST_REDIRECT_BLOCK test_haystack = [ ['listen', '80'], ['root', '/var/www/html'], ['index', 'index.html index.htm index.nginx-debian.html'], ['server_name', 'two.functorkitten.xyz'], ['listen', '443 ssl'], ['#', ' managed by Certbot'], [ 'ssl_certificate', '/etc/letsencrypt/live/two.functorkitten.xyz/fullchain.pem' ], ['#', ' managed by Certbot'], [ 'ssl_certificate_key', '/etc/letsencrypt/live/two.functorkitten.xyz/privkey.pem' ], ['#', ' managed by Certbot'], [['if', '($scheme != "https")'], [['return', '301 https://$host$request_uri']]], ['#', ' managed by Certbot'], [] ] vhost_haystack = VirtualHost("filp", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), test_haystack, []) test_bad_haystack = [ ['listen', '80'], ['root', '/var/www/html'], ['index', 'index.html index.htm index.nginx-debian.html'], ['server_name', 'two.functorkitten.xyz'], ['listen', '443 ssl'], ['#', ' managed by Certbot'], [ 'ssl_certificate', '/etc/letsencrypt/live/two.functorkitten.xyz/fullchain.pem' ], ['#', ' managed by Certbot'], [ 'ssl_certificate_key', '/etc/letsencrypt/live/two.functorkitten.xyz/privkey.pem' ], ['#', ' managed by Certbot'], [['if', '($scheme != "https")'], [['return', '302 https://$host$request_uri']]], ['#', ' managed by Certbot'], [] ] vhost_bad_haystack = VirtualHost("filp", set([Addr.fromstring("localhost")]), False, False, set(['localhost']), test_bad_haystack, []) self.assertTrue(vhost_haystack.contains_list(test_needle)) self.assertFalse(vhost_bad_haystack.contains_list(test_needle))