class AuthorizationRequestTest(unittest.TestCase):

    def setUp(self):
        self.responses = (
            challenges.SimpleHTTPSResponse(path='Hf5GrX4Q7EBax9hc2jJnfw'),
            None,  # null
            challenges.RecoveryTokenResponse(token='23029d88d9e123e'),
        )
        self.contact = ("mailto:[email protected]", "tel:+12025551212")
        signature = other.Signature(
            alg=jose.RS256, jwk=jose.JWKRSA(key=KEY.publickey()),
            sig='-v\xd8\xc2\xa3\xba0\xd6\x92\x16\xb5.\xbe\xa1[\x04\xbe'
                '\x1b\xa1X\xd2)\x18\x94\x8f\xd7\xd0\xc0\xbbcI`W\xdf v'
                '\xe4\xed\xe8\x03J\xe8\xc8<?\xc8W\x94\x94cj(\xe7\xaa$'
                '\x92\xe9\x96\x11\xc2\xefx\x0bR',
            nonce='\xab?\x08o\xe6\x81$\x9f\xa1\xc9\x025\x1c\x1b\xa5+')

        from letsencrypt.acme.messages import AuthorizationRequest
        self.msg = AuthorizationRequest(
            session_id='aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
            nonce='\xec\xd6\xf2oYH\xeb\x13\xd5#q\xe0\xdd\xa2\x92\xa9',
            responses=self.responses,
            signature=signature,
            contact=self.contact,
        )

        self.jmsg_to = {
            'type': 'authorizationRequest',
            'sessionID': 'aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
            'nonce': '7Nbyb1lI6xPVI3Hg3aKSqQ',
            'responses': self.responses,
            'signature': signature,
            'contact': self.contact,
        }
        self.jmsg_from = {
            'type': 'authorizationRequest',
            'sessionID': 'aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
            'nonce': '7Nbyb1lI6xPVI3Hg3aKSqQ',
            'responses': [None if response is None
                          else response.fully_serialize()
                          for response in self.responses],
            'signature': signature.fully_serialize(),
            # TODO: schema validation doesn't recognize tuples as
            # arrays :(
            'contact': list(self.contact),
        }

    def test_create(self):
        from letsencrypt.acme.messages import AuthorizationRequest
        self.assertEqual(self.msg, AuthorizationRequest.create(
            name='example.com', key=KEY, responses=self.responses,
            nonce='\xec\xd6\xf2oYH\xeb\x13\xd5#q\xe0\xdd\xa2\x92\xa9',
            session_id='aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
            sig_nonce='\xab?\x08o\xe6\x81$\x9f\xa1\xc9\x025\x1c\x1b\xa5+',
            contact=self.contact))

    def test_verify(self):
        self.assertTrue(self.msg.verify('example.com'))

    def test_to_json(self):
        self.assertEqual(self.msg.to_json(), self.jmsg_to)

    def test_from_json(self):
        from letsencrypt.acme.messages import AuthorizationRequest
        self.assertEqual(
            self.msg, AuthorizationRequest.from_json(self.jmsg_from))

    def test_json_without_optionals(self):
        del self.jmsg_from['contact']
        del self.jmsg_to['contact']

        from letsencrypt.acme.messages import AuthorizationRequest
        msg = AuthorizationRequest.from_json(self.jmsg_from)

        self.assertEqual(msg.contact, ())
        self.assertEqual(self.jmsg_to, msg.to_json())
class AuthorizationRequestTest(unittest.TestCase):

    def setUp(self):
        self.responses = [
            {'type': 'simpleHttps', 'path': 'Hf5GrX4Q7EBax9hc2jJnfw'},
            None,  # null
            {'type': 'recoveryToken', 'token': '23029d88d9e123e'},
        ]
        self.contact = ["mailto:[email protected]", "tel:+12025551212"]
        signature = other.Signature(
            alg='RS256', jwk=jose.JWK(key=KEY.publickey()),
            sig='-v\xd8\xc2\xa3\xba0\xd6\x92\x16\xb5.\xbe\xa1[\x04\xbe'
                '\x1b\xa1X\xd2)\x18\x94\x8f\xd7\xd0\xc0\xbbcI`W\xdf v'
                '\xe4\xed\xe8\x03J\xe8\xc8<?\xc8W\x94\x94cj(\xe7\xaa$'
                '\x92\xe9\x96\x11\xc2\xefx\x0bR',
            nonce='\xab?\x08o\xe6\x81$\x9f\xa1\xc9\x025\x1c\x1b\xa5+')

        from letsencrypt.acme.messages import AuthorizationRequest
        self.msg = AuthorizationRequest(
            session_id='aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
            nonce='\xec\xd6\xf2oYH\xeb\x13\xd5#q\xe0\xdd\xa2\x92\xa9',
            responses=self.responses,
            signature=signature,
            contact=self.contact,
        )

        self.jmsg_to = {
            'type': 'authorizationRequest',
            'sessionID': 'aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
            'nonce': '7Nbyb1lI6xPVI3Hg3aKSqQ',
            'responses': self.responses,
            'signature': signature,
            'contact': self.contact,
        }
        self.jmsg_from = {
            'type': 'authorizationRequest',
            'sessionID': 'aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
            'nonce': '7Nbyb1lI6xPVI3Hg3aKSqQ',
            'responses': self.responses,
            'signature': signature.to_json(),
            'contact': self.contact,
        }
        self.jmsg_from['signature']['jwk'] = self.jmsg_from[
            'signature']['jwk'].to_json()

    def test_create(self):
        from letsencrypt.acme.messages import AuthorizationRequest
        self.assertEqual(self.msg, AuthorizationRequest.create(
            name='example.com', key=KEY, responses=self.responses,
            nonce='\xec\xd6\xf2oYH\xeb\x13\xd5#q\xe0\xdd\xa2\x92\xa9',
            session_id='aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
            sig_nonce='\xab?\x08o\xe6\x81$\x9f\xa1\xc9\x025\x1c\x1b\xa5+',
            contact=self.contact))

    def test_verify(self):
        self.assertTrue(self.msg.verify('example.com'))

    def test_to_json(self):
        self.assertEqual(self.msg.to_json(), self.jmsg_to)

    def test_from_json(self):
        from letsencrypt.acme.messages import AuthorizationRequest
        self.assertEqual(
            self.msg, AuthorizationRequest.from_json(self.jmsg_from))

    def test_json_without_optionals(self):
        del self.jmsg_from['contact']
        del self.jmsg_to['contact']

        from letsencrypt.acme.messages import AuthorizationRequest
        msg = AuthorizationRequest.from_json(self.jmsg_from)

        self.assertEqual(msg.contact, [])
        self.assertEqual(self.jmsg_to, msg.to_json())
class AuthorizationRequestTest(unittest.TestCase):

    def setUp(self):
        self.responses = (
            challenges.SimpleHTTPSResponse(path='Hf5GrX4Q7EBax9hc2jJnfw'),
            None,  # null
            challenges.RecoveryTokenResponse(token='23029d88d9e123e'),
        )
        self.contact = ("mailto:[email protected]", "tel:+12025551212")
        signature = other.Signature(
            alg=jose.RS256, jwk=jose.JWKRSA(key=KEY.publickey()),
            sig='-v\xd8\xc2\xa3\xba0\xd6\x92\x16\xb5.\xbe\xa1[\x04\xbe'
                '\x1b\xa1X\xd2)\x18\x94\x8f\xd7\xd0\xc0\xbbcI`W\xdf v'
                '\xe4\xed\xe8\x03J\xe8\xc8<?\xc8W\x94\x94cj(\xe7\xaa$'
                '\x92\xe9\x96\x11\xc2\xefx\x0bR',
            nonce='\xab?\x08o\xe6\x81$\x9f\xa1\xc9\x025\x1c\x1b\xa5+')

        from letsencrypt.acme.messages import AuthorizationRequest
        self.msg = AuthorizationRequest(
            session_id='aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
            nonce='\xec\xd6\xf2oYH\xeb\x13\xd5#q\xe0\xdd\xa2\x92\xa9',
            responses=self.responses,
            signature=signature,
            contact=self.contact,
        )

        self.jmsg_to = {
            'type': 'authorizationRequest',
            'sessionID': 'aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
            'nonce': '7Nbyb1lI6xPVI3Hg3aKSqQ',
            'responses': self.responses,
            'signature': signature,
            'contact': self.contact,
        }
        self.jmsg_from = {
            'type': 'authorizationRequest',
            'sessionID': 'aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
            'nonce': '7Nbyb1lI6xPVI3Hg3aKSqQ',
            'responses': [None if response is None else response.to_json()
                          for response in self.responses],
            'signature': signature.to_json(),
            # TODO: schema validation doesn't recognize tuples as
            # arrays :(
            'contact': list(self.contact),
        }

    def test_create(self):
        from letsencrypt.acme.messages import AuthorizationRequest
        self.assertEqual(self.msg, AuthorizationRequest.create(
            name='example.com', key=KEY, responses=self.responses,
            nonce='\xec\xd6\xf2oYH\xeb\x13\xd5#q\xe0\xdd\xa2\x92\xa9',
            session_id='aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
            sig_nonce='\xab?\x08o\xe6\x81$\x9f\xa1\xc9\x025\x1c\x1b\xa5+',
            contact=self.contact))

    def test_verify(self):
        self.assertTrue(self.msg.verify('example.com'))

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

    def test_from_json(self):
        from letsencrypt.acme.messages import AuthorizationRequest
        self.assertEqual(
            self.msg, AuthorizationRequest.from_json(self.jmsg_from))

    def test_json_without_optionals(self):
        del self.jmsg_from['contact']
        del self.jmsg_to['contact']

        from letsencrypt.acme.messages import AuthorizationRequest
        msg = AuthorizationRequest.from_json(self.jmsg_from)

        self.assertEqual(msg.contact, ())
        self.assertEqual(self.jmsg_to, msg.to_partial_json())
示例#4
0
class AuthorizationRequestTest(unittest.TestCase):
    def setUp(self):
        self.responses = [
            {
                'type': 'simpleHttps',
                'path': 'Hf5GrX4Q7EBax9hc2jJnfw'
            },
            None,  # null
            {
                'type': 'recoveryToken',
                'token': '23029d88d9e123e'
            },
        ]
        self.contact = ["mailto:[email protected]", "tel:+12025551212"]
        signature = other.Signature(
            alg='RS256',
            jwk=jose.JWK(key=KEY.publickey()),
            sig='-v\xd8\xc2\xa3\xba0\xd6\x92\x16\xb5.\xbe\xa1[\x04\xbe'
            '\x1b\xa1X\xd2)\x18\x94\x8f\xd7\xd0\xc0\xbbcI`W\xdf v'
            '\xe4\xed\xe8\x03J\xe8\xc8<?\xc8W\x94\x94cj(\xe7\xaa$'
            '\x92\xe9\x96\x11\xc2\xefx\x0bR',
            nonce='\xab?\x08o\xe6\x81$\x9f\xa1\xc9\x025\x1c\x1b\xa5+')

        from letsencrypt.acme.messages import AuthorizationRequest
        self.msg = AuthorizationRequest(
            session_id='aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
            nonce='\xec\xd6\xf2oYH\xeb\x13\xd5#q\xe0\xdd\xa2\x92\xa9',
            responses=self.responses,
            signature=signature,
            contact=self.contact,
        )

        self.jmsg_to = {
            'type': 'authorizationRequest',
            'sessionID': 'aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
            'nonce': '7Nbyb1lI6xPVI3Hg3aKSqQ',
            'responses': self.responses,
            'signature': signature,
            'contact': self.contact,
        }
        self.jmsg_from = {
            'type': 'authorizationRequest',
            'sessionID': 'aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
            'nonce': '7Nbyb1lI6xPVI3Hg3aKSqQ',
            'responses': self.responses,
            'signature': signature.to_json(),
            'contact': self.contact,
        }
        self.jmsg_from['signature']['jwk'] = self.jmsg_from['signature'][
            'jwk'].to_json()

    def test_create(self):
        from letsencrypt.acme.messages import AuthorizationRequest
        self.assertEqual(
            self.msg,
            AuthorizationRequest.create(
                name='example.com',
                key=KEY,
                responses=self.responses,
                nonce='\xec\xd6\xf2oYH\xeb\x13\xd5#q\xe0\xdd\xa2\x92\xa9',
                session_id='aefoGaavieG9Wihuk2aufai3aeZ5EeW4',
                sig_nonce='\xab?\x08o\xe6\x81$\x9f\xa1\xc9\x025\x1c\x1b\xa5+',
                contact=self.contact))

    def test_verify(self):
        self.assertTrue(self.msg.verify('example.com'))

    def test_to_json(self):
        self.assertEqual(self.msg.to_json(), self.jmsg_to)

    def test_from_json(self):
        from letsencrypt.acme.messages import AuthorizationRequest
        self.assertEqual(self.msg,
                         AuthorizationRequest.from_json(self.jmsg_from))

    def test_json_without_optionals(self):
        del self.jmsg_from['contact']
        del self.jmsg_to['contact']

        from letsencrypt.acme.messages import AuthorizationRequest
        msg = AuthorizationRequest.from_json(self.jmsg_from)

        self.assertEqual(msg.contact, [])
        self.assertEqual(self.jmsg_to, msg.to_json())