mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 19:14:54 +02:00
Go back to hasattr and add a test.
This commit is contained in:
@@ -131,12 +131,14 @@ class NginxParserTest(util.NginxTest):
|
|||||||
ssl_re = re.compile(r'\n\s+ssl_certificate /etc/ssl/cert.pem')
|
ssl_re = re.compile(r'\n\s+ssl_certificate /etc/ssl/cert.pem')
|
||||||
dump = nginxparser.dumps(nparser.parsed[nparser.abs_path('nginx.conf')])
|
dump = nginxparser.dumps(nparser.parsed[nparser.abs_path('nginx.conf')])
|
||||||
self.assertEqual(1, len(re.findall(ssl_re, dump)))
|
self.assertEqual(1, len(re.findall(ssl_re, dump)))
|
||||||
nparser.add_server_directives(nparser.abs_path('server.conf'),
|
|
||||||
|
server_conf = nparser.abs_path('server.conf')
|
||||||
|
nparser.add_server_directives(server_conf,
|
||||||
set(['alias', 'another.alias',
|
set(['alias', 'another.alias',
|
||||||
'somename']),
|
'somename']),
|
||||||
[['foo', 'bar'], ['ssl_certificate',
|
[['foo', 'bar'], ['ssl_certificate',
|
||||||
'/etc/ssl/cert2.pem']])
|
'/etc/ssl/cert2.pem']])
|
||||||
self.assertEqual(nparser.parsed[nparser.abs_path('server.conf')],
|
self.assertEqual(nparser.parsed[server_conf],
|
||||||
[['ssl_certificate', '/etc/ssl/cert2.pem'],
|
[['ssl_certificate', '/etc/ssl/cert2.pem'],
|
||||||
['foo', 'bar'],
|
['foo', 'bar'],
|
||||||
['server_name', 'somename alias another.alias']])
|
['server_name', 'somename alias another.alias']])
|
||||||
@@ -152,6 +154,12 @@ class NginxParserTest(util.NginxTest):
|
|||||||
self.assertTrue(util.contains_at_depth(root, ['http'], 1))
|
self.assertTrue(util.contains_at_depth(root, ['http'], 1))
|
||||||
self.assertTrue(util.contains_at_depth(root, block, 2))
|
self.assertTrue(util.contains_at_depth(root, block, 2))
|
||||||
|
|
||||||
|
# Check that our server block got inserted first among all server
|
||||||
|
# blocks.
|
||||||
|
http_block = filter(lambda x: x[0] == ['http'], root)[0][1]
|
||||||
|
server_blocks = filter(lambda x: x[0] == ['server'], http_block)
|
||||||
|
self.assertEqual(server_blocks[0], block)
|
||||||
|
|
||||||
def test_replace_server_directives(self):
|
def test_replace_server_directives(self):
|
||||||
nparser = parser.NginxParser(self.config_path, self.ssl_options)
|
nparser = parser.NginxParser(self.config_path, self.ssl_options)
|
||||||
target = set(['.example.com', 'example.*'])
|
target = set(['.example.com', 'example.*'])
|
||||||
|
|||||||
@@ -93,7 +93,9 @@ def contains_at_depth(haystack, needle, n):
|
|||||||
Return true if the needle is present in one of the sub-iterables in haystack
|
Return true if the needle is present in one of the sub-iterables in haystack
|
||||||
at depth n. Haystack must be an iterable.
|
at depth n. Haystack must be an iterable.
|
||||||
"""
|
"""
|
||||||
if not isinstance(haystack, collections.Iterable):
|
# Specifically use hasattr rather than isinstance(..., collections.Iterable)
|
||||||
|
# because we want to include lists but reject strings.
|
||||||
|
if not hasattr(haystack, '__iter__'):
|
||||||
return False
|
return False
|
||||||
if n == 0:
|
if n == 0:
|
||||||
return needle in haystack
|
return needle in haystack
|
||||||
|
|||||||
Reference in New Issue
Block a user