Esempio n. 1
0
class RegistrationTest(unittest.TestCase):
    """Tests for acme.messages.Registration."""
    def setUp(self):
        key = jose.jwk.JWKRSA(key=KEY.publickey())
        contact = (
            'mailto:[email protected]',
            'tel:1234',
        )
        recovery_token = 'XYZ'
        agreement = 'https://letsencrypt.org/terms'

        from acme.messages import Registration
        self.reg = Registration(key=key,
                                contact=contact,
                                recovery_token=recovery_token,
                                agreement=agreement)

        self.jobj_to = {
            'contact': contact,
            'recoveryToken': recovery_token,
            'agreement': agreement,
            'key': key,
        }
        self.jobj_from = self.jobj_to.copy()
        self.jobj_from['key'] = key.to_json()

    def test_from_data(self):
        from acme.messages import Registration
        reg = Registration.from_data(phone='1234', email='*****@*****.**')
        self.assertEqual(reg.contact, (
            'tel:1234',
            'mailto:[email protected]',
        ))

    def test_phones(self):
        self.assertEqual(('1234', ), self.reg.phones)

    def test_emails(self):
        self.assertEqual(('*****@*****.**', ), self.reg.emails)

    def test_phone(self):
        self.assertEqual('1234', self.reg.phone)

    def test_email(self):
        self.assertEqual('*****@*****.**', self.reg.email)

    def test_to_partial_json(self):
        self.assertEqual(self.jobj_to, self.reg.to_partial_json())

    def test_from_json(self):
        from acme.messages import Registration
        self.assertEqual(self.reg, Registration.from_json(self.jobj_from))

    def test_from_json_hashable(self):
        from acme.messages import Registration
        hash(Registration.from_json(self.jobj_from))
Esempio n. 2
0
class RegistrationTest(unittest.TestCase):
    """Tests for acme.messages.Registration."""

    def setUp(self):
        key = jose.jwk.JWKRSA(key=KEY.publickey())
        contact = (
            'mailto:[email protected]',
            'tel:1234',
        )
        recovery_token = 'XYZ'
        agreement = 'https://letsencrypt.org/terms'

        from acme.messages import Registration
        self.reg = Registration(
            key=key, contact=contact, recovery_token=recovery_token,
            agreement=agreement)

        self.jobj_to = {
            'contact': contact,
            'recoveryToken': recovery_token,
            'agreement': agreement,
            'key': key,
        }
        self.jobj_from = self.jobj_to.copy()
        self.jobj_from['key'] = key.to_json()

    def test_from_data(self):
        from acme.messages import Registration
        reg = Registration.from_data(phone='1234', email='*****@*****.**')
        self.assertEqual(reg.contact, (
            'tel:1234',
            'mailto:[email protected]',
        ))

    def test_phones(self):
        self.assertEqual(('1234',), self.reg.phones)

    def test_emails(self):
        self.assertEqual(('*****@*****.**',), self.reg.emails)

    def test_phone(self):
        self.assertEqual('1234', self.reg.phone)

    def test_email(self):
        self.assertEqual('*****@*****.**', self.reg.email)

    def test_to_partial_json(self):
        self.assertEqual(self.jobj_to, self.reg.to_partial_json())

    def test_from_json(self):
        from acme.messages import Registration
        self.assertEqual(self.reg, Registration.from_json(self.jobj_from))

    def test_from_json_hashable(self):
        from acme.messages import Registration
        hash(Registration.from_json(self.jobj_from))
class RegistrationTest(unittest.TestCase):
    """Tests for acme.messages.Registration."""

    def setUp(self):
        key = jose.jwk.JWKRSA(key=KEY.public_key())
        contact = (
            'mailto:[email protected]',
            'tel:1234',
        )
        agreement = 'https://letsencrypt.org/terms'

        from acme.messages import Registration
        self.reg = Registration(key=key, contact=contact, agreement=agreement)
        self.reg_none = Registration()

        self.jobj_to = {
            'contact': contact,
            'agreement': agreement,
            'key': key,
        }
        self.jobj_from = self.jobj_to.copy()
        self.jobj_from['key'] = key.to_json()

    def test_from_data(self):
        from acme.messages import Registration
        reg = Registration.from_data(phone='1234', email='*****@*****.**')
        self.assertEqual(reg.contact, (
            'tel:1234',
            'mailto:[email protected]',
        ))

    def test_new_registration_from_data_with_eab(self):
        from acme.messages import NewRegistration, ExternalAccountBinding, Directory
        key = jose.jwk.JWKRSA(key=KEY.public_key())
        kid = "kid-for-testing"
        hmac_key = "hmac-key-for-testing"
        directory = Directory({
            'newAccount': 'http://url/acme/new-account',
        })
        eab = ExternalAccountBinding.from_data(key, kid, hmac_key, directory)
        reg = NewRegistration.from_data(email='*****@*****.**', external_account_binding=eab)
        self.assertEqual(reg.contact, (
            'mailto:[email protected]',
        ))
        self.assertEqual(sorted(reg.external_account_binding.keys()),
                         sorted(['protected', 'payload', 'signature']))

    def test_phones(self):
        self.assertEqual(('1234',), self.reg.phones)

    def test_emails(self):
        self.assertEqual(('*****@*****.**',), self.reg.emails)

    def test_to_partial_json(self):
        self.assertEqual(self.jobj_to, self.reg.to_partial_json())

    def test_from_json(self):
        from acme.messages import Registration
        self.assertEqual(self.reg, Registration.from_json(self.jobj_from))

    def test_from_json_hashable(self):
        from acme.messages import Registration
        hash(Registration.from_json(self.jobj_from))
Esempio n. 4
0
class RegistrationTest(unittest.TestCase):
    """Tests for acme.messages.Registration."""

    def setUp(self):
        key = jose.jwk.JWKRSA(key=KEY.public_key())
        contact = (
            'mailto:[email protected]',
            'tel:1234',
        )
        agreement = 'https://letsencrypt.org/terms'

        from acme.messages import Registration
        self.reg = Registration(key=key, contact=contact, agreement=agreement)
        self.reg_none = Registration()

        self.jobj_to = {
            'contact': contact,
            'agreement': agreement,
            'key': key,
        }
        self.jobj_from = self.jobj_to.copy()
        self.jobj_from['key'] = key.to_json()

    def test_from_data(self):
        from acme.messages import Registration
        reg = Registration.from_data(phone='1234', email='*****@*****.**')
        self.assertEqual(reg.contact, (
            'tel:1234',
            'mailto:[email protected]',
        ))

    def test_new_registration_from_data_with_eab(self):
        from acme.messages import NewRegistration, ExternalAccountBinding, Directory
        key = jose.jwk.JWKRSA(key=KEY.public_key())
        kid = "kid-for-testing"
        hmac_key = "hmac-key-for-testing"
        directory = Directory({
            'newAccount': 'http://url/acme/new-account',
        })
        eab = ExternalAccountBinding.from_data(key, kid, hmac_key, directory)
        reg = NewRegistration.from_data(email='*****@*****.**', external_account_binding=eab)
        self.assertEqual(reg.contact, (
            'mailto:[email protected]',
        ))
        self.assertEqual(sorted(reg.external_account_binding.keys()),
                         sorted(['protected', 'payload', 'signature']))

    def test_phones(self):
        self.assertEqual(('1234',), self.reg.phones)

    def test_emails(self):
        self.assertEqual(('*****@*****.**',), self.reg.emails)

    def test_to_partial_json(self):
        self.assertEqual(self.jobj_to, self.reg.to_partial_json())

    def test_from_json(self):
        from acme.messages import Registration
        self.assertEqual(self.reg, Registration.from_json(self.jobj_from))

    def test_from_json_hashable(self):
        from acme.messages import Registration
        hash(Registration.from_json(self.jobj_from))