Exemplo n.º 1
0
 def _static_validation_for_rule(self, operation, identifier, req_id):
     try:
         ConstraintCreator.create_constraint(operation.get(CONSTRAINT))
     except (ValueError, KeyError) as exp:
         raise InvalidClientRequest(identifier, req_id, exp)
     StaticAuthRuleHelper.check_auth_key(operation, identifier, req_id,
                                         self.write_req_validator.auth_map)
Exemplo n.º 2
0
    def _doStaticValidationAuthRule(self, identifier, reqId, operation):
        constraint = operation.get(CONSTRAINT)
        ConstraintCreator.create_constraint(constraint)
        action = operation.get(AUTH_ACTION, None)

        if OLD_VALUE not in operation and action == EDIT_PREFIX:
            raise InvalidClientRequest(
                identifier, reqId, "Transaction for change authentication "
                "rule for {}={} must contain field {}".format(
                    AUTH_ACTION, EDIT_PREFIX, OLD_VALUE))

        if OLD_VALUE in operation and action == ADD_PREFIX:
            raise InvalidClientRequest(
                identifier, reqId, "Transaction for change authentication "
                "rule for {}={} must not contain field {}".format(
                    AUTH_ACTION, ADD_PREFIX, OLD_VALUE))

        auth_key = self.get_auth_key(operation)

        if auth_key not in self.write_req_validator.auth_map and \
                auth_key not in self.write_req_validator.anyone_can_write_map:
            raise InvalidClientRequest(
                identifier, reqId,
                "Unknown authorization rule: key '{}' is not "
                "found in authorization map".format(auth_key))
Exemplo n.º 3
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
    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]
Exemplo n.º 4
0
    def _doStaticValidationAuthRule(self, identifier, reqId, operation):
        try:
            ConstraintCreator.create_constraint(operation.get(CONSTRAINT))
        except ValueError as exp:
            raise InvalidClientRequest(identifier, reqId, exp)

        action = operation.get(AUTH_ACTION, None)

        if OLD_VALUE not in operation and action == EDIT_PREFIX:
            raise InvalidClientRequest(
                identifier, reqId, "Transaction for change authentication "
                "rule for {}={} must contain field {}".format(
                    AUTH_ACTION, EDIT_PREFIX, OLD_VALUE))

        if OLD_VALUE in operation and action == ADD_PREFIX:
            raise InvalidClientRequest(
                identifier, reqId, "Transaction for change authentication "
                "rule for {}={} must not contain field {}".format(
                    AUTH_ACTION, ADD_PREFIX, OLD_VALUE))
        self._check_auth_key(operation, identifier, reqId)
Exemplo n.º 5
0
def test_constraint_creator(constraints_as_dict, constraints):
    from_creator = [
        ConstraintCreator.create_constraint(c) for c in constraints_as_dict
    ]
    assert all(map(lambda a, b: a == b, constraints, from_creator))
Exemplo n.º 6
0
 def get_auth_constraint(operation):
     return ConstraintCreator.create_constraint(operation.get(CONSTRAINT))