From f83a77d8ad7b34c3eb99171f78b8e0a0faa77667 Mon Sep 17 00:00:00 2001 From: yan Date: Thu, 16 Apr 2015 13:39:24 -0700 Subject: [PATCH] Add regex servername test, correct conf syntax Running the configtest (nginx -c -t /path/to/nginx.conf) should now say "The configuration file /path/to/nginx.conf syntax is ok" --- .../plugins/nginx/tests/configurator_test.py | 12 ++++--- .../plugins/nginx/tests/nginxparser_test.py | 31 +++++++++--------- .../client/plugins/nginx/tests/parser_test.py | 7 ++-- .../plugins/nginx/tests/testdata/foo.conf | 32 ++++++++++--------- .../plugins/nginx/tests/testdata/mime.types | 0 .../plugins/nginx/tests/testdata/nginx.conf | 8 ++--- .../nginx/tests/testdata/nginx.new.conf | 6 ++-- 7 files changed, 50 insertions(+), 46 deletions(-) create mode 100644 letsencrypt/client/plugins/nginx/tests/testdata/mime.types diff --git a/letsencrypt/client/plugins/nginx/tests/configurator_test.py b/letsencrypt/client/plugins/nginx/tests/configurator_test.py index bf74569eb..fda3bad05 100644 --- a/letsencrypt/client/plugins/nginx/tests/configurator_test.py +++ b/letsencrypt/client/plugins/nginx/tests/configurator_test.py @@ -36,7 +36,7 @@ class NginxConfiguratorTest(util.NginxTest): names = self.config.get_all_names() self.assertEqual(names, set( ["*.www.foo.com", "somename", "another.alias", - "alias", "localhost", ".example.com", + "alias", "localhost", ".example.com", "~^(www\.)?(example|bar)\.", "155.225.50.69.nephoscale.net", "*.www.example.com", "example.*", "www.example.org", "myhost"])) @@ -70,7 +70,7 @@ class NginxConfiguratorTest(util.NginxTest): parsed[0]) def test_choose_vhost(self): - localhost_conf = set(['localhost']) + localhost_conf = set(['localhost', '~^(www\.)?(example|bar)\.']) server_conf = set(['somename', 'another.alias', 'alias']) example_conf = set(['.example.com', 'example.*']) foo_conf = set(['*.www.foo.com', '*.www.example.com']) @@ -81,8 +81,10 @@ class NginxConfiguratorTest(util.NginxTest): 'example.com.uk.test': example_conf, 'www.example.com': example_conf, 'test.www.example.com': foo_conf, - 'abc.www.foo.com': foo_conf} - bad_results = ['www.foo.com', 'example', '69.255.225.155'] + 'abc.www.foo.com': foo_conf, + 'www.bar.co.uk': localhost_conf} + bad_results = ['www.foo.com', 'example', 't.www.bar.co', + '69.255.225.155'] for name in results: self.assertEqual(results[name], @@ -134,7 +136,7 @@ class NginxConfiguratorTest(util.NginxTest): ['ssl_certificate_key', '/etc/nginx/key.pem'], ['include', self.config.parser.loc["ssl_options"]]]], - self.config.parser.parsed[nginx_conf][-1][-1][-3]) + self.config.parser.parsed[nginx_conf][-1][-1][-1]) def test_get_all_certs_keys(self): nginx_conf = self.config.parser.abs_path('nginx.conf') diff --git a/letsencrypt/client/plugins/nginx/tests/nginxparser_test.py b/letsencrypt/client/plugins/nginx/tests/nginxparser_test.py index 48f7590db..5f0601db3 100644 --- a/letsencrypt/client/plugins/nginx/tests/nginxparser_test.py +++ b/letsencrypt/client/plugins/nginx/tests/nginxparser_test.py @@ -63,21 +63,22 @@ class TestRawNginxParser(unittest.TestCase): self.assertEqual( parsed, [['user', 'www-data'], - [['server'], [ - ['listen', '*:80 default_server ssl'], - ['server_name', '*.www.foo.com *.www.example.com'], - ['root', '/home/ubuntu/sites/foo/'], - [['location', '/status'], [ - ['check_status'], - [['types'], [['image/jpeg', 'jpg']]], - ]], - [['location', '~', 'case_sensitive\.php$'], [ - ['hoge', 'hoge'] - ]], - [['location', '~*', 'case_insensitive\.php$'], []], - [['location', '=', 'exact_match\.php$'], []], - [['location', '^~', 'ignore_regex\.php$'], []], - ]]] + [['http'], + [[['server'], [ + ['listen', '*:80 default_server ssl'], + ['server_name', '*.www.foo.com *.www.example.com'], + ['root', '/home/ubuntu/sites/foo/'], + [['location', '/status'], [ + [['types'], [['image/jpeg', 'jpg']]], + ]], + [['location', '~', 'case_sensitive\.php$'], [ + ['index', 'index.php'], + ['root', '/var/root'], + ]], + [['location', '~*', 'case_insensitive\.php$'], []], + [['location', '=', 'exact_match\.php$'], []], + [['location', '^~', 'ignore_regex\.php$'], []] + ]]]]] ) def test_dump_as_file(self): diff --git a/letsencrypt/client/plugins/nginx/tests/parser_test.py b/letsencrypt/client/plugins/nginx/tests/parser_test.py index d1bc39af6..36aef9f63 100644 --- a/letsencrypt/client/plugins/nginx/tests/parser_test.py +++ b/letsencrypt/client/plugins/nginx/tests/parser_test.py @@ -84,7 +84,9 @@ class NginxParserTest(util.NginxTest): vhost1 = VirtualHost(parser.abs_path('nginx.conf'), [Addr('', '8080', False, False)], - False, True, set(['localhost']), []) + False, True, set(['localhost', + '~^(www\.)?(example|bar)\.']), + []) vhost2 = VirtualHost(parser.abs_path('nginx.conf'), [Addr('somename', '8080', False, False), Addr('', '8000', False, False)], @@ -118,7 +120,8 @@ class NginxParserTest(util.NginxTest): def test_add_server_directives(self): parser = NginxParser(self.config_path, self.ssl_options) parser.add_server_directives(parser.abs_path('nginx.conf'), - set(['localhost']), + set(['localhost', + '~^(www\.)?(example|bar)\.']), [['foo', 'bar'], ['ssl_certificate', '/etc/ssl/cert.pem']]) r = re.compile('foo bar;\n\s+ssl_certificate /etc/ssl/cert.pem') diff --git a/letsencrypt/client/plugins/nginx/tests/testdata/foo.conf b/letsencrypt/client/plugins/nginx/tests/testdata/foo.conf index 774334220..574955398 100644 --- a/letsencrypt/client/plugins/nginx/tests/testdata/foo.conf +++ b/letsencrypt/client/plugins/nginx/tests/testdata/foo.conf @@ -1,23 +1,25 @@ # a test nginx conf user www-data; -server { - listen *:80 default_server ssl; - server_name *.www.foo.com *.www.example.com; - root /home/ubuntu/sites/foo/; +http { + server { + listen *:80 default_server ssl; + server_name *.www.foo.com *.www.example.com; + root /home/ubuntu/sites/foo/; - location /status { - check_status; - types { - image/jpeg jpg; + location /status { + types { + image/jpeg jpg; + } } - } - location ~ case_sensitive\.php$ { - hoge hoge; - } - location ~* case_insensitive\.php$ {} - location = exact_match\.php$ {} - location ^~ ignore_regex\.php$ {} + location ~ case_sensitive\.php$ { + index index.php; + root /var/root; + } + location ~* case_insensitive\.php$ {} + location = exact_match\.php$ {} + location ^~ ignore_regex\.php$ {} + } } diff --git a/letsencrypt/client/plugins/nginx/tests/testdata/mime.types b/letsencrypt/client/plugins/nginx/tests/testdata/mime.types new file mode 100644 index 000000000..e69de29bb diff --git a/letsencrypt/client/plugins/nginx/tests/testdata/nginx.conf b/letsencrypt/client/plugins/nginx/tests/testdata/nginx.conf index ce8e525ef..0af503e6b 100644 --- a/letsencrypt/client/plugins/nginx/tests/testdata/nginx.conf +++ b/letsencrypt/client/plugins/nginx/tests/testdata/nginx.conf @@ -18,6 +18,7 @@ include foo.conf; http { include mime.types; + include sites-enabled/*; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' @@ -30,13 +31,13 @@ http { tcp_nopush on; keepalive_timeout 0; - keepalive_timeout 65; gzip on; server { listen 8080; server_name localhost; + server_name ~^(www\.)?(example|bar)\.; charset koi8-r; @@ -68,7 +69,6 @@ http { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; - include fastcgi_params; } # deny access to .htaccess files, if Nginx's document root @@ -115,7 +115,5 @@ http { # } #} - include conf.d/test.conf; - include sites-enabled/*; - + #include conf.d/test.conf; } diff --git a/letsencrypt/client/plugins/nginx/tests/testdata/nginx.new.conf b/letsencrypt/client/plugins/nginx/tests/testdata/nginx.new.conf index e53ed29c9..0a43b5842 100644 --- a/letsencrypt/client/plugins/nginx/tests/testdata/nginx.new.conf +++ b/letsencrypt/client/plugins/nginx/tests/testdata/nginx.new.conf @@ -10,6 +10,7 @@ events { include foo.conf; http { include mime.types; + include sites-enabled/*; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' @@ -18,12 +19,12 @@ http { sendfile on; tcp_nopush on; keepalive_timeout 0; - keepalive_timeout 65; gzip on; server { listen 8080; server_name localhost; + server_name ~^(www\.)?(example|bar)\.; charset koi8-r; access_log logs/host.access.log main; @@ -47,7 +48,6 @@ http { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; - include fastcgi_params; } location ~ /\.ht { @@ -65,8 +65,6 @@ http { index index.html index.htm; } } - include conf.d/test.conf; - include sites-enabled/*; server { listen 443 ssl;