only print deprecation warning when --standalone-supported-challenges is set

This commit is contained in:
Brad Warren 2016-08-29 13:32:19 -07:00
parent 7467794637
commit 24cc03d1f6
2 changed files with 22 additions and 5 deletions

View file

@ -13,6 +13,7 @@ import zope.interface
from acme import challenges
from acme import standalone as acme_standalone
from certbot import cli
from certbot import errors
from certbot import interfaces
@ -120,10 +121,11 @@ def supported_challenges_validator(data):
It should be passed as `type` argument to `add_argument`.
"""
sys.stderr.write(
"WARNING: The standalone specific "
"supported challenges flag is deprecated\n")
sys.stderr.write("Please use the --preferred-challenges flag instead.\n")
if cli.set_by_cli("standalone_supported_challenges"):
sys.stderr.write(
"WARNING: The standalone specific "
"supported challenges flag is deprecated.\n"
"Please use the --preferred-challenges flag instead.\n")
challs = data.split(",")
# tls-sni-01 was dvsni during private beta

View file

@ -67,10 +67,25 @@ class ServerManagerTest(unittest.TestCase):
class SupportedChallengesValidatorTest(unittest.TestCase):
"""Tests for plugins.standalone.supported_challenges_validator."""
def setUp(self):
self.set_by_cli_patch = mock.patch(
"certbot.plugins.standalone.cli.set_by_cli")
self.stderr_patch = mock.patch("certbot.plugins.standalone.sys.stderr")
self.set_by_cli_patch.start().return_value = True
self.stderr = self.stderr_patch.start()
def tearDown(self):
self.set_by_cli_patch.stop()
self.stderr_patch.stop()
def _call(self, data):
from certbot.plugins.standalone import (
supported_challenges_validator)
return supported_challenges_validator(data)
return_value = supported_challenges_validator(data)
self.assertTrue(self.stderr.write.called) # pylint: disable=no-member
self.stderr.write.reset_mock() # pylint: disable=no-member
return return_value
def test_correct(self):
self.assertEqual("tls-sni-01", self._call("tls-sni-01"))