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]', ))
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.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))
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 register_account( cls, email: str, directory_url: str = "https://acme-v02.api.letsencrypt.org/directory", ): """ create a new acme account :param email: the email address that should be used for the account :param directory_url: the url of the acme directory that should be used :return: a new ACME client instance """ keypair = cls._generate_keypair() client_network = ClientNetwork(keypair) directory = cls._get_directory(directory_url) registration = Registration.from_data(email=email, terms_of_service_agreed=True) client = ClientV2(directory, client_network) result = client.new_account(registration) return ACMEService(client)
def test_from_json_hashable(self): from acme.messages import Registration hash(Registration.from_json(self.jobj_from))
def test_from_json(self): from acme.messages import Registration self.assertEqual(self.reg, 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))