def test_invalid_operation_with_empty_auth_constraints(): # ConstraintListField without empty list in auth_constraints invalid_auth_rule_operation = generate_auth_rule_operation(constraint=generate_constraint_list( auth_constraints=[generate_constraint_entity(), generate_constraint_list( auth_constraints=[])])) with pytest.raises(TypeError, match="Fields {} should not be an empty " "list.".format(AUTH_CONSTRAINTS)): validator.validate(invalid_auth_rule_operation)
def test_invalid_operation_constraint_id_with_large_constraint(): # ConstraintListField without required field CONSTRAINT_ID on the 2nd level invalid_auth_rule_operation = generate_auth_rule_operation(constraint=generate_constraint_list( auth_constraints=[generate_constraint_entity(), generate_constraint_list( auth_constraints=[generate_constraint_entity(), generate_constraint_entity()])])) del invalid_auth_rule_operation[CONSTRAINT][AUTH_CONSTRAINTS][1][CONSTRAINT_ID] with pytest.raises(TypeError, match=CONSTRAINT_ID): validator.validate(invalid_auth_rule_operation)
def test_invalid_entity_role_in_extra_large_constraint(): # ConstraintEntityField without required field 'role' invalid_auth_rule_operation = generate_auth_rule_operation(constraint=generate_constraint_list( auth_constraints=[generate_constraint_entity(), generate_constraint_list( auth_constraints=[generate_constraint_entity(), generate_constraint_entity()])])) del invalid_auth_rule_operation[CONSTRAINT][AUTH_CONSTRAINTS][1][AUTH_CONSTRAINTS][0][ROLE] with pytest.raises(TypeError, match=ROLE): validator.validate(invalid_auth_rule_operation)
def test_get_all_auth_rule_transactions_after_write(looper, sdk_wallet_trustee, sdk_pool_handle): auth_action = ADD_PREFIX auth_type = NYM field = ROLE new_value = TRUST_ANCHOR constraint = generate_constraint_list(auth_constraints=[generate_constraint_entity(role=TRUSTEE), generate_constraint_entity(role=STEWARD)]) resp = sdk_send_and_check_auth_rule_request(looper, sdk_pool_handle, sdk_wallet_trustee, auth_action=auth_action, auth_type=auth_type, field=field, new_value=new_value, constraint=constraint) str_auth_key = ConfigReqHandler.get_auth_key(resp[0][0][OPERATION]) resp = sdk_send_and_check_get_auth_rule_request( looper, sdk_pool_handle, sdk_wallet_trustee ) result = resp[0][1]["result"][DATA] for rule in result: key = ConfigReqHandler.get_auth_key(rule) if auth_map[key] is None: assert {} == rule[CONSTRAINT] elif key == str_auth_key: assert constraint == rule[CONSTRAINT] else: assert auth_map[key].as_dict == rule[CONSTRAINT]
def test_get_one_auth_rule_transaction_after_write(looper, sdk_wallet_trustee, sdk_pool_handle): auth_action = ADD_PREFIX auth_type = NYM field = ROLE new_value = TRUST_ANCHOR constraint = generate_constraint_list(auth_constraints=[generate_constraint_entity(role=TRUSTEE), generate_constraint_entity(role=STEWARD)]) resp = sdk_send_and_check_auth_rule_request(looper, sdk_pool_handle, sdk_wallet_trustee, auth_action=auth_action, auth_type=auth_type, field=field, new_value=new_value, constraint=constraint) dict_auth_key = generate_key(auth_action=auth_action, auth_type=auth_type, field=field, new_value=new_value) resp = sdk_send_and_check_get_auth_rule_request( looper, sdk_pool_handle, sdk_wallet_trustee, **dict_auth_key ) result = resp[0][1]["result"][DATA] assert len(result) == 1 _check_key(dict_auth_key, result[0]) assert constraint == result[0][CONSTRAINT] assert resp[0][1]["result"][STATE_PROOF]
def test_get_one_auth_rule_transaction_after_write(looper, sdk_wallet_trustee, sdk_pool_handle): auth_action = ADD_PREFIX auth_type = NYM field = ROLE new_value = TRUST_ANCHOR constraint = generate_constraint_list(auth_constraints=[generate_constraint_entity(role=TRUSTEE), generate_constraint_entity(role=STEWARD)]) resp = sdk_send_and_check_auth_rule_request(looper, sdk_wallet_trustee, sdk_pool_handle, auth_action=auth_action, auth_type=auth_type, field=field, new_value=new_value, constraint=constraint) dict_auth_key = generate_key(auth_action=auth_action, auth_type=auth_type, field=field, new_value=new_value) str_key = ConfigReqHandler.get_auth_key(dict_auth_key) resp = sdk_get_auth_rule_request(looper, sdk_wallet_trustee, sdk_pool_handle, dict_auth_key) print(config.make_state_path_for_auth_rule(str_key)) result = resp[0][1]["result"][DATA][config.make_state_path_for_auth_rule(str_key).decode()] assert result == constraint assert resp[0][1]["result"][STATE_PROOF]
def test_get_all_auth_rule_transactions_after_write(looper, sdk_wallet_trustee, sdk_pool_handle): auth_action = ADD_PREFIX auth_type = NYM field = ROLE new_value = ENDORSER auth_constraint = generate_constraint_list(auth_constraints=[generate_constraint_entity(role=TRUSTEE), generate_constraint_entity(role=STEWARD)]) resp = sdk_send_and_check_auth_rule_request(looper, sdk_pool_handle, sdk_wallet_trustee, auth_action=auth_action, auth_type=auth_type, field=field, new_value=new_value, constraint=auth_constraint) auth_key = StaticAuthRuleHelper.get_auth_key(resp[0][0][OPERATION]) resp = sdk_send_and_check_get_auth_rule_request(looper, sdk_pool_handle, sdk_wallet_trustee) result = resp[0][1]["result"][DATA] full_auth_map = OrderedDict(auth_map) full_auth_map.update(sovtoken_auth_map) full_auth_map.update(sovtokenfees_auth_map) full_auth_map[auth_key] = ConstraintCreator.create_constraint(auth_constraint) for i, (auth_key, constraint) in enumerate(full_auth_map.items()): rule = result[i] assert auth_key == StaticAuthRuleHelper.get_auth_key(rule) if constraint is None: assert {} == rule[CONSTRAINT] else: assert constraint.as_dict == rule[CONSTRAINT]
def test_get_all_auth_rule_transactions_after_write(looper, sdk_wallet_trustee, sdk_pool_handle): auth_action = ADD_PREFIX auth_type = NYM field = ROLE new_value = TRUST_ANCHOR constraint = generate_constraint_list(auth_constraints=[ generate_constraint_entity(role=TRUSTEE), generate_constraint_entity(role=STEWARD) ]) resp = sdk_send_and_check_auth_rule_request(looper, sdk_wallet_trustee, sdk_pool_handle, auth_action=auth_action, auth_type=auth_type, field=field, new_value=new_value, constraint=constraint) auth_key = ConfigReqHandler.get_auth_key(resp[0][0][OPERATION]) resp = sdk_get_auth_rule_request(looper, sdk_wallet_trustee, sdk_pool_handle) expect = {key: constraint.as_dict for key, constraint in auth_map.items()} expect[auth_key] = constraint result = resp[0][1]["result"][DATA] assert result == expect
def test_invalid_operation_auth_constraints(): # ConstraintListField without required field 'auth_constraints' invalid_auth_rule_operation = generate_auth_rule_operation(constraint=generate_constraint_list( auth_constraints=[generate_constraint_entity(), generate_constraint_entity()])) del invalid_auth_rule_operation[CONSTRAINT][AUTH_CONSTRAINTS] with pytest.raises(TypeError, match=AUTH_CONSTRAINTS): validator.validate(invalid_auth_rule_operation)
def test_auth_rule_transaction_with_large_constraint(looper, sdk_wallet_trustee, sdk_pool_handle): constraint = generate_constraint_list(auth_constraints=[generate_constraint_entity(role=TRUSTEE), generate_constraint_entity(role=STEWARD)]) sdk_send_and_check_auth_rule_request(looper, sdk_wallet_trustee, sdk_pool_handle, constraint=constraint)
def send_and_check_auth_rule(looper, sdk_pool_handle, sdk_wallet_trustee): auth_constraint = generate_constraint_list(auth_constraints=[generate_constraint_entity(role=TRUSTEE), generate_constraint_entity(role=STEWARD)]) sdk_send_and_check_auth_rule_request(looper, sdk_pool_handle, sdk_wallet_trustee, auth_action=ADD_PREFIX, auth_type=NYM, field=ROLE, new_value=ENDORSER, constraint=auth_constraint)
def test_auth_rule_after_get_auth_rule_as_is_except_constraint( looper, sdk_wallet_trustee, sdk_pool_handle ): constraint = generate_constraint_list(auth_constraints=[generate_constraint_entity(role=TRUSTEE), generate_constraint_entity(role=STEWARD)]) # get all auth rules auth_rules_resp = sdk_send_and_check_get_auth_rule_request( looper, sdk_pool_handle, sdk_wallet_trustee ) auth_rules = auth_rules_resp[0][1][RESULT][DATA] rule = auth_rules[0] # prepare action key dict_key = dict(rule) dict_key.pop(CONSTRAINT) # prepare "operation" to send AUTH_RULE txn op = dict(rule) op[TXN_TYPE] = AUTH_RULE op[CONSTRAINT] = constraint # send AUTH_RULE txn req_obj = sdk_gen_request(op, identifier=sdk_wallet_trustee[1]) req = sdk_sign_and_submit_req_obj(looper, sdk_pool_handle, sdk_wallet_trustee, req_obj) sdk_get_and_check_replies(looper, [req]) # send GET_AUTH_RULE get_response = sdk_send_and_check_get_auth_rule_request( looper, sdk_pool_handle, sdk_wallet_trustee, **dict_key ) # check response result = get_response[0][1]["result"][DATA] assert len(result) == 1 _check_key(dict_key, result[0]) assert constraint == result[0][CONSTRAINT] assert get_response[0][1]["result"][STATE_PROOF]
import pytest from indy_common.constants import CONSTRAINT, AUTH_ACTION from indy_common.types import ClientAuthRuleOperation from indy_node.test.helper import generate_constraint_entity from indy_node.test.auth_rule.helper import generate_constraint_list, \ generate_auth_rule_operation from indy_common.authorize.auth_constraints import ROLE, AUTH_CONSTRAINTS, CONSTRAINT_ID validator = ClientAuthRuleOperation() valid_auth_rule_operation_small = generate_auth_rule_operation() valid_auth_rule_operation_large = generate_auth_rule_operation( constraint=generate_constraint_list(auth_constraints=[ generate_constraint_entity(), generate_constraint_entity() ])) valid_auth_rule_operation_extra_large = generate_auth_rule_operation( constraint=generate_constraint_list(auth_constraints=[ generate_constraint_entity(), generate_constraint_list(auth_constraints=[ generate_constraint_entity(), generate_constraint_entity() ]) ])) def test_valid(): validator.validate(valid_auth_rule_operation_small) validator.validate(valid_auth_rule_operation_large) validator.validate(valid_auth_rule_operation_extra_large)
import pytest from indy_common.constants import CONSTRAINT, AUTH_ACTION from indy_common.types import ClientAuthRuleOperation from indy_node.test.auth_rule.helper import generate_constraint_entity, generate_constraint_list, \ generate_auth_rule_operation from indy_common.authorize.auth_constraints import ROLE, AUTH_CONSTRAINTS, CONSTRAINT_ID validator = ClientAuthRuleOperation() valid_auth_rule_operation_small = generate_auth_rule_operation() valid_auth_rule_operation_large = generate_auth_rule_operation(constraint=generate_constraint_list( auth_constraints=[generate_constraint_entity(), generate_constraint_entity()])) valid_auth_rule_operation_extra_large = generate_auth_rule_operation(constraint=generate_constraint_list( auth_constraints=[generate_constraint_entity(), generate_constraint_list( auth_constraints=[generate_constraint_entity(), generate_constraint_entity()])])) def test_valid(): validator.validate(valid_auth_rule_operation_small) validator.validate(valid_auth_rule_operation_large) validator.validate(valid_auth_rule_operation_extra_large) def test_invalid_operation_action(): # must be ADD_PREFIX or EDIT_PREFIX invalid_auth_rule_operation = generate_auth_rule_operation(auth_action="auth_action") with pytest.raises(TypeError, match=AUTH_ACTION):