From 1774ab64c4590014f425ebfaa913ede3d586ad06 Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Sun, 4 Oct 2015 20:24:53 +0000 Subject: [PATCH] Add SupportedChallengesValidatorTest. --- letsencrypt/plugins/standalone.py | 8 ++++++-- letsencrypt/plugins/standalone_test.py | 27 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/letsencrypt/plugins/standalone.py b/letsencrypt/plugins/standalone.py index 17e99073f..05a9f1655 100644 --- a/letsencrypt/plugins/standalone.py +++ b/letsencrypt/plugins/standalone.py @@ -115,7 +115,11 @@ SUPPORTED_CHALLENGES = set([challenges.DVSNI, challenges.SimpleHTTP]) def supported_challenges_validator(data): - """Supported challenges validator.""" + """Supported challenges validator for the `argparse`. + + It should be passed as `type` argument to `add_argument`. + + """ challs = data.split(",") unrecognized = [name for name in challs if name not in challenges.Challenge.TYPES] @@ -127,7 +131,7 @@ def supported_challenges_validator(data): if not set(challs).issubset(choices): raise argparse.ArgumentTypeError( "Plugin does not support the following (valid) " - "challenges: {0}".format(", ".join(challs - choices))) + "challenges: {0}".format(", ".join(set(challs) - choices))) return data diff --git a/letsencrypt/plugins/standalone_test.py b/letsencrypt/plugins/standalone_test.py index 4a077a36f..1cd310107 100644 --- a/letsencrypt/plugins/standalone_test.py +++ b/letsencrypt/plugins/standalone_test.py @@ -1,4 +1,5 @@ """Tests for letsencrypt.plugins.standalone.""" +import argparse import socket import unittest @@ -63,6 +64,28 @@ class ServerManagerTest(unittest.TestCase): self.assertEqual(self.mgr.running(), {}) +class SupportedChallengesValidatorTest(unittest.TestCase): + """Tests for plugins.standalone.supported_challenges_validator.""" + + def _call(self, data): + from letsencrypt.plugins.standalone import ( + supported_challenges_validator) + return supported_challenges_validator(data) + + def test_correct(self): + self.assertEqual("dvsni", self._call("dvsni")) + self.assertEqual("simpleHttp", self._call("simpleHttp")) + self.assertEqual("dvsni,simpleHttp", self._call("dvsni,simpleHttp")) + self.assertEqual("simpleHttp,dvsni", self._call("simpleHttp,dvsni")) + + def test_unrecognized(self): + assert "foo" not in challenges.Challenge.TYPES + self.assertRaises(argparse.ArgumentTypeError, self._call, "foo") + + def test_not_subset(self): + self.assertRaises(argparse.ArgumentTypeError, self._call, "dns") + + class AuthenticatorTest(unittest.TestCase): """Tests for letsencrypt.plugins.standalone.Authenticator.""" @@ -72,6 +95,10 @@ class AuthenticatorTest(unittest.TestCase): standalone_supported_challenges="dvsni,simpleHttp") self.auth = Authenticator(self.config, name="standalone") + def test_supported_challenges(self): + self.assertEqual(self.auth.supported_challenges, + set([challenges.DVSNI, challenges.SimpleHTTP])) + def test_more_info(self): self.assertTrue(isinstance(self.auth.more_info(), six.string_types))