当前位置: 首页>>代码示例>>Python>>正文


Python StandaloneAuthenticator.perform方法代码示例

本文整理汇总了Python中letsencrypt.plugins.standalone.authenticator.StandaloneAuthenticator.perform方法的典型用法代码示例。如果您正苦于以下问题:Python StandaloneAuthenticator.perform方法的具体用法?Python StandaloneAuthenticator.perform怎么用?Python StandaloneAuthenticator.perform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在letsencrypt.plugins.standalone.authenticator.StandaloneAuthenticator的用法示例。


在下文中一共展示了StandaloneAuthenticator.perform方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PerformTest

# 需要导入模块: from letsencrypt.plugins.standalone.authenticator import StandaloneAuthenticator [as 别名]
# 或者: from letsencrypt.plugins.standalone.authenticator.StandaloneAuthenticator import perform [as 别名]
class PerformTest(unittest.TestCase):
    """Tests for perform() method."""
    def setUp(self):
        from letsencrypt.plugins.standalone.authenticator import \
            StandaloneAuthenticator
        self.authenticator = StandaloneAuthenticator(config=CONFIG, name=None)

        self.achall1 = achallenges.DVSNI(
            challb=acme_util.chall_to_challb(
                challenges.DVSNI(r="whee", nonce="foo"), "pending"),
            domain="foo.example.com", key=KEY)
        self.achall2 = achallenges.DVSNI(
            challb=acme_util.chall_to_challb(
                challenges.DVSNI(r="whee", nonce="bar"), "pending"),
            domain="bar.example.com", key=KEY)
        bad_achall = ("This", "Represents", "A Non-DVSNI", "Challenge")
        self.achalls = [self.achall1, self.achall2, bad_achall]

    def test_perform_when_already_listening(self):
        self.authenticator.already_listening = mock.Mock()
        self.authenticator.already_listening.return_value = True
        result = self.authenticator.perform([self.achall1])
        self.assertEqual(result, [None])

    def test_can_perform(self):
        """What happens if start_listener() returns True."""
        self.authenticator.start_listener = mock.Mock()
        self.authenticator.start_listener.return_value = True
        self.authenticator.already_listening = mock.Mock(return_value=False)
        result = self.authenticator.perform(self.achalls)
        self.assertEqual(len(self.authenticator.tasks), 2)
        self.assertTrue(
            self.authenticator.tasks.has_key(self.achall1.nonce_domain))
        self.assertTrue(
            self.authenticator.tasks.has_key(self.achall2.nonce_domain))
        self.assertTrue(isinstance(result, list))
        self.assertEqual(len(result), 3)
        self.assertTrue(isinstance(result[0], challenges.ChallengeResponse))
        self.assertTrue(isinstance(result[1], challenges.ChallengeResponse))
        self.assertFalse(result[2])
        self.authenticator.start_listener.assert_called_once_with(
            CONFIG.dvsni_port, KEY)

    def test_cannot_perform(self):
        """What happens if start_listener() returns False."""
        self.authenticator.start_listener = mock.Mock()
        self.authenticator.start_listener.return_value = False
        self.authenticator.already_listening = mock.Mock(return_value=False)
        result = self.authenticator.perform(self.achalls)
        self.assertEqual(len(self.authenticator.tasks), 2)
        self.assertTrue(
            self.authenticator.tasks.has_key(self.achall1.nonce_domain))
        self.assertTrue(
            self.authenticator.tasks.has_key(self.achall2.nonce_domain))
        self.assertTrue(isinstance(result, list))
        self.assertEqual(len(result), 3)
        self.assertEqual(result, [None, None, False])
        self.authenticator.start_listener.assert_called_once_with(
            CONFIG.dvsni_port, KEY)

    def test_perform_with_pending_tasks(self):
        self.authenticator.tasks = {"foononce.acme.invalid": "cert_data"}
        extra_achall = acme_util.DVSNI_P
        self.assertRaises(
            ValueError, self.authenticator.perform, [extra_achall])

    def test_perform_without_challenge_list(self):
        extra_achall = acme_util.DVSNI_P
        # This is wrong because a challenge must be specified.
        self.assertRaises(ValueError, self.authenticator.perform, [])
        # This is wrong because it must be a list, not a bare challenge.
        self.assertRaises(
            ValueError, self.authenticator.perform, extra_achall)
        # This is wrong because the list must contain at least one challenge.
        self.assertRaises(
            ValueError, self.authenticator.perform, range(20))
开发者ID:mommel,项目名称:lets-encrypt-preview,代码行数:78,代码来源:authenticator_test.py


注:本文中的letsencrypt.plugins.standalone.authenticator.StandaloneAuthenticator.perform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。