Ejemplo n.º 1
0
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 = ENDORSER
    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]
Ejemplo n.º 2
0
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
    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 key == str_auth_key:
            assert constraint == rule[CONSTRAINT]
        else:
            assert auth_map[key].as_dict == rule[CONSTRAINT]
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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]
Ejemplo n.º 9
0
def sdk_send_and_check_auth_rule_request(looper,
                                         sdk_pool_handle,
                                         sdk_wallet_trustee,
                                         auth_action=ADD_PREFIX,
                                         auth_type=NYM,
                                         field=ROLE,
                                         old_value=None,
                                         new_value=ENDORSER,
                                         constraint=None,
                                         no_wait=False):
    constraint = (generate_constraint_entity()
                  if constraint is None else constraint)
    return _sdk_send_and_check_auth_rule_request(looper,
                                                 sdk_pool_handle,
                                                 sdk_wallet_trustee,
                                                 auth_action=auth_action,
                                                 auth_type=auth_type,
                                                 field=field,
                                                 old_value=old_value,
                                                 new_value=new_value,
                                                 constraint=constraint,
                                                 no_wait=no_wait)
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
def generate_constraint_list(constraint_id=ConstraintsEnum.AND_CONSTRAINT_ID,
                             auth_constraints=None):
    auth_constraints = generate_constraint_entity() \
        if auth_constraints is None \
        else auth_constraints
    return {CONSTRAINT_ID: constraint_id, AUTH_CONSTRAINTS: auth_constraints}