Exemple #1
0
 def test_delete_address(self):
     member = self.client.create_member()
     name = generate_nonce()
     payload = utils.generate_address()
     address = member.add_address(name, payload)
     assert len(member.get_addresses()) == 1
     member.delete_address(address.id)
     assert len(member.get_addresses()) == 0
Exemple #2
0
 def test_add_and_get_address(self):
     member = self.client.create_member(utils.generate_alias())
     name = generate_nonce()
     payload = utils.generate_address()
     address = member.add_address(name, payload)
     result = member.get_address(address.id)
     assert name == address.name
     assert payload == address.address
     assert address == result
Exemple #3
0
 def test_get_access_token(self):
     member1 = self.client.create_member(
         utils.generate_alias(type=Alias.DOMAIN))
     address = member1.add_address(generate_nonce(),
                                   utils.generate_address())
     payload = AccessTokenBuilder.create_with_alias(
         member1.get_first_alias()).for_address(address.id).build()
     access_token = member1.create_access_token(payload)
     result = member1.get_token(access_token.id)
     assert access_token == result
Exemple #4
0
 def test_create_and_get_addresses(self):
     member = self.client.create_member(utils.generate_alias())
     addresses = {
         utils.generate_nonce(): utils.generate_address()
         for _ in range(3)
     }
     for name, address in addresses.items():
         member.add_address(name, address)
     actual = {
         address_record.name: address_record.address
         for address_record in member.get_addresses()
     }
     assert addresses == actual
Exemple #5
0
 def test_create_access_token_idempotent(self):
     member1 = self.client.create_member(
         utils.generate_alias(type=Alias.DOMAIN))
     address = member1.add_address(generate_nonce(),
                                   utils.generate_address())
     payload = AccessTokenBuilder.create_with_alias(
         member1.get_first_alias()).for_address(address.id).build()
     member1.endorse_token(member1.create_access_token(payload),
                           Key.STANDARD)
     member1.endorse_token(member1.create_access_token(payload),
                           Key.STANDARD)
     time.sleep(self.TOKEN_LOOKUP_POLL_FREQUENCY * 2)
     result = member1.get_access_tokens(2, None)
     assert len(result.tokens) == 1
Exemple #6
0
 def test_only_one_access_token_allowed(self):
     member = self.client.create_member(
         utils.generate_alias(type=Alias.DOMAIN))
     address = member.add_address(generate_nonce(),
                                  utils.generate_address())
     payload = AccessTokenBuilder.create_with_alias(
         member.get_first_alias()).for_address(address.id).build()
     member.create_access_token(payload)
     payload = AccessTokenBuilder.create_with_alias(
         member.get_first_alias()).for_address(address.id).build()
     with pytest.raises(RequestError) as exec_info:
         member.create_access_token(payload)
     assert exec_info.value.details == "Token from {} to {} already exists".format(
         member.member_id, member.member_id)
     assert exec_info.value.code == StatusCode.ALREADY_EXISTS
Exemple #7
0
 def test_get_access_tokens(self):
     # TODO: cleanup
     member1 = self.client.create_member(
         utils.generate_alias(type=Alias.DOMAIN))
     member2 = self.client.create_member(
         utils.generate_alias(type=Alias.DOMAIN))
     address = member1.add_address(generate_nonce(),
                                   utils.generate_address())
     payload = AccessTokenBuilder.create_with_alias(
         member1.get_first_alias()).for_address(address.id).build()
     member1.create_access_token(payload)
     payload = AccessTokenBuilder.create_with_alias(
         member2.get_first_alias()).for_address(address.id).build()
     access_token = member1.create_access_token(payload)
     member1.endorse_token(access_token, Key.STANDARD)
     time.sleep(self.TOKEN_LOOKUP_POLL_FREQUENCY * 2)
     result = member1.get_access_tokens(limit=2, offset=None)
     token_ids = [item.id for item in result.tokens]
     assert access_token.id in token_ids
Exemple #8
0
 def test_get_access_token_id(self):
     member1 = self.client.create_member(
         utils.generate_alias(type=Alias.DOMAIN))
     member2 = self.client.create_member(
         utils.generate_alias(type=Alias.DOMAIN))
     address = member1.add_address(generate_nonce(),
                                   utils.generate_address())
     payload = AccessTokenBuilder.create_with_alias(
         member2.get_first_alias()).for_address(address.id).build()
     request = TokenRequest.builder(payload).build()
     token_request_id = member2.store_token_request(request)
     access_token = member1.create_access_token(payload)
     member1.endorse_token(access_token, Key.STANDARD)
     signature = member1.sign_token_request_state(token_request_id,
                                                  access_token.id,
                                                  generate_nonce())
     assert signature.ByteSize != 0
     result = self.client.get_token_request_result(token_request_id)
     assert result.token_id == access_token.id
     assert result.signature.signature == signature.signature