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


Python DVSNI.to_partial_json方法代码示例

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


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

示例1: DVSNITest

# 需要导入模块: from acme.challenges import DVSNI [as 别名]
# 或者: from acme.challenges.DVSNI import to_partial_json [as 别名]
class DVSNITest(unittest.TestCase):

    def setUp(self):
        from acme.challenges import DVSNI
        self.msg = DVSNI(
            token=jose.b64decode('a82d5ff8ef740d12881f6d3c2277ab2e'))
        self.jmsg = {
            'type': 'dvsni',
            'token': 'a82d5ff8ef740d12881f6d3c2277ab2e',
        }

    def test_to_partial_json(self):
        self.assertEqual(self.jmsg, self.msg.to_partial_json())

    def test_from_json(self):
        from acme.challenges import DVSNI
        self.assertEqual(self.msg, DVSNI.from_json(self.jmsg))

    def test_from_json_hashable(self):
        from acme.challenges import DVSNI
        hash(DVSNI.from_json(self.jmsg))

    def test_from_json_invalid_token_length(self):
        from acme.challenges import DVSNI
        self.jmsg['token'] = jose.encode_b64jose(b'abcd')
        self.assertRaises(
            jose.DeserializationError, DVSNI.from_json, self.jmsg)

    def test_gen_response(self):
        key = jose.JWKRSA(key=KEY)
        from acme.challenges import DVSNI
        self.assertEqual(self.msg, DVSNI.json_loads(
            self.msg.gen_response(key).validation.payload.decode()))
开发者ID:fmarier,项目名称:letsencrypt,代码行数:35,代码来源:challenges_test.py

示例2: DVSNITest

# 需要导入模块: from acme.challenges import DVSNI [as 别名]
# 或者: from acme.challenges.DVSNI import to_partial_json [as 别名]
class DVSNITest(unittest.TestCase):

    def setUp(self):
        from acme.challenges import DVSNI
        self.msg = DVSNI(
            r="O*\xb4-\xad\xec\x95>\xed\xa9\r0\x94\xe8\x97\x9c&6"
              "\xbf'\xb3\xed\x9a9nX\x0f'\\m\xe7\x12",
            nonce='\xa8-_\xf8\xeft\r\x12\x88\x1fm<"w\xab.')
        self.jmsg = {
            'type': 'dvsni',
            'r': 'Tyq0La3slT7tqQ0wlOiXnCY2vyez7Zo5blgPJ1xt5xI',
            'nonce': 'a82d5ff8ef740d12881f6d3c2277ab2e',
        }

    def test_nonce_domain(self):
        self.assertEqual('a82d5ff8ef740d12881f6d3c2277ab2e.acme.invalid',
                         self.msg.nonce_domain)

    def test_to_partial_json(self):
        self.assertEqual(self.jmsg, self.msg.to_partial_json())

    def test_from_json(self):
        from acme.challenges import DVSNI
        self.assertEqual(self.msg, DVSNI.from_json(self.jmsg))

    def test_from_json_hashable(self):
        from acme.challenges import DVSNI
        hash(DVSNI.from_json(self.jmsg))

    def test_from_json_invalid_r_length(self):
        from acme.challenges import DVSNI
        self.jmsg['r'] = 'abcd'
        self.assertRaises(
            jose.DeserializationError, DVSNI.from_json, self.jmsg)

    def test_from_json_invalid_nonce_length(self):
        from acme.challenges import DVSNI
        self.jmsg['nonce'] = 'abcd'
        self.assertRaises(
            jose.DeserializationError, DVSNI.from_json, self.jmsg)
开发者ID:kepstin,项目名称:letsencrypt,代码行数:42,代码来源:challenges_test.py

示例3: DVSNITest

# 需要导入模块: from acme.challenges import DVSNI [as 别名]
# 或者: from acme.challenges.DVSNI import to_partial_json [as 别名]
class DVSNITest(unittest.TestCase):

    def setUp(self):
        from acme.challenges import DVSNI
        self.msg = DVSNI(
            r=b"O*\xb4-\xad\xec\x95>\xed\xa9\r0\x94\xe8\x97\x9c&6"
              b"\xbf'\xb3\xed\x9a9nX\x0f'\\m\xe7\x12",
            nonce=b'\xa8-_\xf8\xeft\r\x12\x88\x1fm<"w\xab.')
        self.jmsg = {
            'type': 'dvsni',
            'r': 'Tyq0La3slT7tqQ0wlOiXnCY2vyez7Zo5blgPJ1xt5xI',
            'nonce': 'a82d5ff8ef740d12881f6d3c2277ab2e',
        }

    def test_nonce_domain(self):
        self.assertEqual(b'a82d5ff8ef740d12881f6d3c2277ab2e.acme.invalid',
                         self.msg.nonce_domain)

    def test_to_partial_json(self):
        self.assertEqual(self.jmsg, self.msg.to_partial_json())

    def test_from_json(self):
        from acme.challenges import DVSNI
        self.assertEqual(self.msg, DVSNI.from_json(self.jmsg))

    def test_from_json_hashable(self):
        from acme.challenges import DVSNI
        hash(DVSNI.from_json(self.jmsg))

    def test_from_json_invalid_r_length(self):
        from acme.challenges import DVSNI
        self.jmsg['r'] = 'abcd'
        self.assertRaises(
            jose.DeserializationError, DVSNI.from_json, self.jmsg)

    def test_from_json_invalid_nonce_length(self):
        from acme.challenges import DVSNI
        self.jmsg['nonce'] = 'abcd'
        self.assertRaises(
            jose.DeserializationError, DVSNI.from_json, self.jmsg)

    @mock.patch('acme.challenges.socket.gethostbyname')
    @mock.patch('acme.challenges.crypto_util._probe_sni')
    def test_probe_cert(self, mock_probe_sni, mock_gethostbyname):
        mock_gethostbyname.return_value = '127.0.0.1'
        self.msg.probe_cert('foo.com')
        mock_gethostbyname.assert_called_once_with('foo.com')
        mock_probe_sni.assert_called_once_with(
            host='127.0.0.1', port=self.msg.PORT,
            name=b'a82d5ff8ef740d12881f6d3c2277ab2e.acme.invalid')

        self.msg.probe_cert('foo.com', host='8.8.8.8')
        mock_probe_sni.assert_called_with(
            host='8.8.8.8', port=mock.ANY, name=mock.ANY)

        self.msg.probe_cert('foo.com', port=1234)
        mock_probe_sni.assert_called_with(
            host=mock.ANY, port=1234, name=mock.ANY)

        self.msg.probe_cert('foo.com', bar='baz')
        mock_probe_sni.assert_called_with(
            host=mock.ANY, port=mock.ANY, name=mock.ANY, bar='baz')

        self.msg.probe_cert('foo.com', name=b'xxx')
        mock_probe_sni.assert_called_with(
            host=mock.ANY, port=mock.ANY,
            name=b'a82d5ff8ef740d12881f6d3c2277ab2e.acme.invalid')
开发者ID:rfxn,项目名称:letsencrypt,代码行数:69,代码来源:challenges_test.py


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