def test_dynamic_validation_for_existing(handler_and_request):
    handler, request = handler_and_request
    make_rich_schema_object_exist(handler, request)
    add_to_idr(handler.database_manager.idr_cache, request.identifier, TRUSTEE)
    add_to_idr(handler.database_manager.idr_cache, request.endorser, ENDORSER)

    with pytest.raises(UnauthorizedClientRequest,
                       match=str(AuthConstraintForbidden())):
        handler.dynamic_validation(request, 0)
Exemplo n.º 2
0
def test_dynamic_validation_for_existing(handler_and_request):
    handler, request = handler_and_request
    make_rich_schema_object_exist(handler, request)
    add_to_idr(handler.database_manager.idr_cache, request.identifier, TRUSTEE)
    add_to_idr(handler.database_manager.idr_cache, request.endorser, ENDORSER)

    # default auth rules allow editing of CredDef and PresDef by the owner
    if isinstance(handler, RichSchemaCredDefHandler) or isinstance(
            handler, RichSchemaPresDefHandler):
        handler.dynamic_validation(request, 0)
    else:
        with pytest.raises(UnauthorizedClientRequest,
                           match=str(AuthConstraintForbidden())):
            handler.dynamic_validation(request, 0)
def cred_def_req(rich_schema_handler, mapping_handler, rich_schema_req, mapping_req):
    make_rich_schema_object_exist(rich_schema_handler, rich_schema_req)
    make_rich_schema_object_exist(mapping_handler, mapping_req)

    req = rich_schema_cred_def_request()

    content = copy.deepcopy(json.loads(req.operation[RS_CONTENT]))
    content[RS_CRED_DEF_SCHEMA] = rich_schema_req.operation[RS_ID]
    content[RS_CRED_DEF_MAPPING] = mapping_req.operation[RS_ID]
    req.operation[RS_CONTENT] = json.dumps(content)

    add_to_idr(rich_schema_handler.database_manager.idr_cache, req.identifier, TRUSTEE)
    add_to_idr(rich_schema_handler.database_manager.idr_cache, req.endorser, ENDORSER)

    return req
Exemplo n.º 4
0
def test_dynamic_validation_for_existing_metadata(handler_and_request):
    handler, request = handler_and_request
    make_rich_schema_object_exist(handler, request)
    add_to_idr(handler.database_manager.idr_cache, request.identifier, TRUSTEE)
    add_to_idr(handler.database_manager.idr_cache, request.endorser, ENDORSER)

    request.operation[RS_ID] = randomString()
    request.operation[RS_CONTENT] = randomString()
    request.reqId = random.randint(10, 1000000000)

    with pytest.raises(
            InvalidClientRequest,
            match=
            'An object with rsName="{}", rsVersion="{}" and rsType="{}" already exists. '
            'Please choose different rsName, rsVersion or rsType'.format(
                request.operation[RS_NAME], request.operation[RS_VERSION],
                request.operation[RS_TYPE])):
        handler.dynamic_validation(request, 0)
def mapping_req(rich_schema_handler, encoding_handler, rich_schema_req):
    make_rich_schema_object_exist(rich_schema_handler, rich_schema_req)
    make_rich_schema_object_exist(encoding_handler, TEST_ENCODING_1)
    make_rich_schema_object_exist(encoding_handler, TEST_ENCODING_2)
    make_rich_schema_object_exist(encoding_handler, TEST_ENCODING_3)

    id = randomString()
    content = copy.deepcopy(TEST_MAPPING)
    content['@id'] = id
    req = rs_req(RICH_SCHEMA_MAPPING, RS_MAPPING_TYPE_VALUE,
                 content=content, id=id)

    add_to_idr(rich_schema_handler.database_manager.idr_cache, req.identifier, TRUSTEE)
    add_to_idr(rich_schema_handler.database_manager.idr_cache, req.endorser, ENDORSER)

    return req