def setUp(self):
     from letsencrypt.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',
     }
class DVSNITest(unittest.TestCase):
    def setUp(self):
        from letsencrypt.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_json(self):
        self.assertEqual(self.jmsg, self.msg.to_json())

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

    def test_from_json_invalid_r_length(self):
        from letsencrypt.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 letsencrypt.acme.challenges import DVSNI
        self.jmsg['nonce'] = 'abcd'
        self.assertRaises(jose.DeserializationError, DVSNI.from_json,
                          self.jmsg)
 def setUp(self):
     from letsencrypt.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_z_and_domain(self):
     from letsencrypt.acme.challenges import DVSNI
     challenge = DVSNI(
         r="O*\xb4-\xad\xec\x95>\xed\xa9\r0\x94\xe8\x97\x9c&6"
         "\xbf'\xb3\xed\x9a9nX\x0f'\\m\xe7\x12",
         nonce=long('439736375371401115242521957580409149254868992063'
                    '44333654741504362774620418661L'))
     # pylint: disable=invalid-name
     z = '38e612b0397cc2624a07d351d7ef50e46134c0213d9ed52f7d7c611acaeed41b'
     self.assertEqual(z, self.msg.z(challenge))
     self.assertEqual('{0}.acme.invalid'.format(z),
                      self.msg.z_domain(challenge))
class DVSNITest(unittest.TestCase):

    def setUp(self):
        from letsencrypt.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 letsencrypt.acme.challenges import DVSNI
        self.assertEqual(self.msg, DVSNI.from_json(self.jmsg))

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

    def test_from_json_invalid_r_length(self):
        from letsencrypt.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 letsencrypt.acme.challenges import DVSNI
        self.jmsg['nonce'] = 'abcd'
        self.assertRaises(
            jose.DeserializationError, DVSNI.from_json, self.jmsg)
 def test_from_json_hashable(self):
     from letsencrypt.acme.challenges import DVSNI
     hash(DVSNI.from_json(self.jmsg))
 def test_from_json(self):
     from letsencrypt.acme.challenges import DVSNI
     self.assertEqual(self.msg, DVSNI.from_json(self.jmsg))
 def test_from_json(self):
     from letsencrypt.acme.challenges import DVSNI
     self.assertEqual(self.msg, DVSNI.from_json(self.jmsg))
 def test_from_json_hashable(self):
     from letsencrypt.acme.challenges import DVSNI
     hash(DVSNI.from_json(self.jmsg))