From 1611df4120bc6ed5bbbe9202070b52c6d2db0741 Mon Sep 17 00:00:00 2001 From: ohemorange Date: Wed, 26 Apr 2017 18:44:06 -0700 Subject: [PATCH] Allow empty nginx blocks (#4555) * modify test config file to allow valid config that fails to parse in parser.py * make failing tests pass by fixing the problem --- certbot-nginx/certbot_nginx/parser.py | 2 +- certbot-nginx/certbot_nginx/tests/parser_test.py | 6 +++--- .../certbot_nginx/tests/testdata/etc_nginx/nginx.conf | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/certbot-nginx/certbot_nginx/parser.py b/certbot-nginx/certbot_nginx/parser.py index 6f3f344db..9f1a08b3b 100644 --- a/certbot-nginx/certbot_nginx/parser.py +++ b/certbot-nginx/certbot_nginx/parser.py @@ -110,7 +110,7 @@ class NginxParser(object): srv = servers[filename] # workaround undefined loop var in lambdas # Find all the server blocks - _do_for_subarray(tree, lambda x: x[0] == ['server'], + _do_for_subarray(tree, lambda x: len(x) >= 2 and x[0] == ['server'], lambda x, y: srv.append((x[1], y))) # Find 'include' statements in server blocks and append their trees diff --git a/certbot-nginx/certbot_nginx/tests/parser_test.py b/certbot-nginx/certbot_nginx/tests/parser_test.py index 9c2b8656e..8a8bd0ff1 100644 --- a/certbot-nginx/certbot_nginx/tests/parser_test.py +++ b/certbot-nginx/certbot_nginx/tests/parser_test.py @@ -125,13 +125,13 @@ class NginxParserTest(util.NginxTest): False, True, set(['localhost', r'~^(www\.)?(example|bar)\.']), - [], [9, 1, 9]) + [], [10, 1, 9]) vhost2 = obj.VirtualHost(nparser.abs_path('nginx.conf'), [obj.Addr('somename', '8080', False, False), obj.Addr('', '8000', False, False)], False, True, set(['somename', 'another.alias', 'alias']), - [], [9, 1, 12]) + [], [10, 1, 12]) vhost3 = obj.VirtualHost(nparser.abs_path('sites-enabled/example.com'), [obj.Addr('69.50.225.155', '9000', False, False), @@ -186,7 +186,7 @@ class NginxParserTest(util.NginxTest): None, None, None, set(['localhost', r'~^(www\.)?(example|bar)\.']), - None, [9, 1, 9]) + None, [10, 1, 9]) nparser.add_server_directives(mock_vhost, [['foo', 'bar'], ['\n ', 'ssl_certificate', ' ', '/etc/ssl/cert.pem']], diff --git a/certbot-nginx/certbot_nginx/tests/testdata/etc_nginx/nginx.conf b/certbot-nginx/certbot_nginx/tests/testdata/etc_nginx/nginx.conf index 0af503e6b..ccce4dc1b 100644 --- a/certbot-nginx/certbot_nginx/tests/testdata/etc_nginx/nginx.conf +++ b/certbot-nginx/certbot_nginx/tests/testdata/etc_nginx/nginx.conf @@ -14,6 +14,9 @@ events { worker_connections 1024; } +empty { +} + include foo.conf; http {