mirror of
https://github.com/certbot/certbot.git
synced 2026-08-02 03:11:55 +02:00
Add SupportedChallengesValidatorTest.
This commit is contained in:
@@ -115,7 +115,11 @@ SUPPORTED_CHALLENGES = set([challenges.DVSNI, challenges.SimpleHTTP])
|
|||||||
|
|
||||||
|
|
||||||
def supported_challenges_validator(data):
|
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(",")
|
challs = data.split(",")
|
||||||
unrecognized = [name for name in challs
|
unrecognized = [name for name in challs
|
||||||
if name not in challenges.Challenge.TYPES]
|
if name not in challenges.Challenge.TYPES]
|
||||||
@@ -127,7 +131,7 @@ def supported_challenges_validator(data):
|
|||||||
if not set(challs).issubset(choices):
|
if not set(challs).issubset(choices):
|
||||||
raise argparse.ArgumentTypeError(
|
raise argparse.ArgumentTypeError(
|
||||||
"Plugin does not support the following (valid) "
|
"Plugin does not support the following (valid) "
|
||||||
"challenges: {0}".format(", ".join(challs - choices)))
|
"challenges: {0}".format(", ".join(set(challs) - choices)))
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
"""Tests for letsencrypt.plugins.standalone."""
|
"""Tests for letsencrypt.plugins.standalone."""
|
||||||
|
import argparse
|
||||||
import socket
|
import socket
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
@@ -63,6 +64,28 @@ class ServerManagerTest(unittest.TestCase):
|
|||||||
self.assertEqual(self.mgr.running(), {})
|
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):
|
class AuthenticatorTest(unittest.TestCase):
|
||||||
"""Tests for letsencrypt.plugins.standalone.Authenticator."""
|
"""Tests for letsencrypt.plugins.standalone.Authenticator."""
|
||||||
|
|
||||||
@@ -72,6 +95,10 @@ class AuthenticatorTest(unittest.TestCase):
|
|||||||
standalone_supported_challenges="dvsni,simpleHttp")
|
standalone_supported_challenges="dvsni,simpleHttp")
|
||||||
self.auth = Authenticator(self.config, name="standalone")
|
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):
|
def test_more_info(self):
|
||||||
self.assertTrue(isinstance(self.auth.more_info(), six.string_types))
|
self.assertTrue(isinstance(self.auth.more_info(), six.string_types))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user