diff --git a/certbot-nginx/certbot_nginx/parser.py b/certbot-nginx/certbot_nginx/parser.py index 536602e27..cf1f3c1db 100644 --- a/certbot-nginx/certbot_nginx/parser.py +++ b/certbot-nginx/certbot_nginx/parser.py @@ -540,7 +540,7 @@ def _comment_directive(block, location): if isinstance(next_entry, list): if "Certbot" in next_entry[-1]: return - next_entry = next_entry.spaced[0] + next_entry = next_entry.spaced[0] # pylint: disable=no-member block.insert(location + 1, COMMENT[:]) if "\n" not in next_entry: block.insert(location + 2, '\n') @@ -584,17 +584,3 @@ def _add_directive(block, directive, replace): 'tried to insert directive "{0}" but found ' 'conflicting "{1}".'.format(directive, block[location])) - -def _comment_spaced_block(block): - """Adds a "managed by Certbot" comment to every directive.""" - comment = " # managed by Certbot" - indent = 80 - len(comment) - for i, entry in enumerate(block): - if isinstance(entry, list): - line = "".join(entry) - line = "".join(c for c in line if c != "\n") - linelength = len(line) - extra = indent - linelength - if extra < 0: - extra = 0 - block[i][-1] += extra * " " + comment diff --git a/certbot-nginx/certbot_nginx/tests/parser_test.py b/certbot-nginx/certbot_nginx/tests/parser_test.py index 09b1cfd0b..963b4c815 100644 --- a/certbot-nginx/certbot_nginx/tests/parser_test.py +++ b/certbot-nginx/certbot_nginx/tests/parser_test.py @@ -219,6 +219,23 @@ class NginxParserTest(util.NginxTest): self.assertEqual(winner, parser.get_best_match(target_name, names[i])) + def test_comment_directive(self): + # pylint: disable=protected-access + block = nginxparser.UnspacedList([ + ["\n", "a", " ", "b", "\n"], + ["c", " ", "d"], + ["\n", "e", " ", "f"]]) + from certbot_nginx.parser import _comment_directive, COMMENT + _comment_directive(block, 1) + _comment_directive(block, 0) + self.assertEqual(block.spaced, [ + ["\n", "a", " ", "b", "\n"], + COMMENT, + "\n", + ["c", " ", "d"], + COMMENT, + ["\n", "e", " ", "f"]]) + def test_get_all_certs_keys(self): nparser = parser.NginxParser(self.config_path, self.ssl_options) filep = nparser.abs_path('sites-enabled/example.com')