Skip to content

Commit

Permalink
Fix and speed up compatibility-tests
Browse files Browse the repository at this point in the history
* Fix nginx-compatibility tests

* sleep is overrated
  • Loading branch information
bmw committed Jun 21, 2017
1 parent 15c6c13 commit ade9b4a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Tests Certbot plugins against different server configurations."""
import argparse
import filecmp
import functools
import logging
import os
import shutil
Expand Down Expand Up @@ -64,12 +63,12 @@ def test_authenticator(plugin, config, temp_dir):
type(achalls[i]), achalls[i].domain, config)
success = False
elif isinstance(responses[i], challenges.TLSSNI01Response):
verify = functools.partial(responses[i].simple_verify, achalls[i].chall,
achalls[i].domain,
util.JWK.public_key(),
host="127.0.0.1",
port=plugin.https_port)
if _try_until_true(verify):
verified = responses[i].simple_verify(achalls[i].chall,
achalls[i].domain,
util.JWK.public_key(),
host="127.0.0.1",
port=plugin.https_port)
if verified:
logger.info(
"tls-sni-01 verification for %s succeeded", achalls[i].domain)
else:
Expand Down Expand Up @@ -155,10 +154,11 @@ def test_deploy_cert(plugin, temp_dir, domains):
return False

success = True
time.sleep(3)
for domain in domains:
verify = functools.partial(validator.Validator().certificate, cert,
domain, "127.0.0.1", plugin.https_port)
if not _try_until_true(verify):
verified = validator.Validator().certificate(
cert, domain, "127.0.0.1", plugin.https_port)
if not verified:
logger.error("**** Could not verify certificate for domain %s", domain)
success = False

Expand All @@ -181,10 +181,8 @@ def test_enhancements(plugin, domains):

for domain, info in domains_and_info:
try:
verify = functools.partial(validator.Validator().any_redirect,
"localhost", plugin.http_port,
headers={"Host": domain})
previous_redirect = _try_until_true(verify)
previous_redirect = validator.Validator().any_redirect(
"localhost", plugin.http_port, headers={"Host": domain})
info.append(previous_redirect)
plugin.enhance(domain, "redirect")
plugin.save() # Needed by the Apache plugin
Expand All @@ -204,9 +202,9 @@ def test_enhancements(plugin, domains):
for domain, info in domains_and_info:
previous_redirect = info[0]
if not previous_redirect:
verify = functools.partial(validator.Validator().redirect, "localhost",
plugin.http_port, headers={"Host": domain})
if not _try_until_true(verify):
verified = validator.Validator().redirect(
"localhost", plugin.http_port, headers={"Host": domain})
if not verified:
logger.error("*** Improper redirect for domain %s", domain)
success = False

Expand All @@ -216,17 +214,6 @@ def test_enhancements(plugin, domains):
return success


def _try_until_true(func, max_tries=5, sleep_time=0.5):
"""Calls func up to max_tries times until it returns True"""
for _ in xrange(0, max_tries):
if func():
return True
else:
time.sleep(sleep_time)

return False


def _save_and_restart(plugin, title=None):
"""Saves and restart the plugin, returning True if no errors occurred"""
try:
Expand Down
Binary file not shown.

0 comments on commit ade9b4a

Please sign in to comment.