示例#1
0
def wsgi_wrapper(environ, start_response, func, session_info, events, jlog):
    kwargs = extract_from_request(environ)

    kwargs['test_cnf'] = session_info['test_conf']
    try:
        oos = kwargs['test_cnf']['out_of_scope']
    except KeyError:
        pass
    else:
        if func.__name__ in oos:
            resp = error_response(
                error='incorrect_behavior',
                descr='You should not talk to this endpoint in this test')
            resp.add_header(CORS_HEADERS)
            return resp(environ, start_response)

    events.store(EV_REQUEST_ARGS, kwargs["request"])
    jlog.info({'operation': func.__name__, 'kwargs': kwargs})
    try:
        args = func(**kwargs)
    except Exception as err:
        events.store(EV_EXCEPTION, err)
        raise

    try:
        resp, state = args
        jlog.info({'response_from': func.__name__, 'response': resp2json(resp),
                   'state': state})
        events.store(EV_RESPONSE, resp.message)
        dump_log(session_info, events)
        resp.headers.extend(CORS_HEADERS)
        return resp(environ, start_response)
    except TypeError:
        resp = args
        try:
            jlog.info({'response_from': func.__name__,
                       'response': resp2json(resp)})
        except Exception:
            pass
        events.store(EV_RESPONSE, resp.message)
        dump_log(session_info, events)
        resp.headers.extend(CORS_HEADERS)
        return resp(environ, start_response)
    except Exception as err:
        jlog.error({'response_from': func.__name__, 'err': err})
        events.store(EV_EXCEPTION, err)
        dump_log(session_info, events)
        resp = ServiceError(err)
        return resp(environ, start_response)
示例#2
0
def wsgi_wrapper(environ, start_response, func, session_info, events, jlog):
    kwargs = extract_from_request(environ)

    kwargs['test_cnf'] = session_info['test_conf']
    try:
        oos = kwargs['test_cnf']['out_of_scope']
    except KeyError:
        pass
    else:
        if func.__name__ in oos:
            resp = error_response(
                error='incorrect_behavior',
                descr='You should not talk to this endpoint in this test')
            return resp(environ, start_response)

    events.store(EV_REQUEST_ARGS, kwargs["request"])
    jlog.info({'operation': func.__name__, 'kwargs': kwargs})
    args = func(**kwargs)

    try:
        resp, state = args
        jlog.info({
            'response_from': func.__name__,
            'response': resp2json(resp),
            'state': state
        })
        events.store(EV_RESPONSE, resp.message)
        dump_log(session_info, events)
        return resp(environ, start_response)
    except TypeError:
        resp = args
        jlog.info({
            'response_from': func.__name__,
            'response': resp2json(resp)
        })
        events.store(EV_RESPONSE, resp.message)
        dump_log(session_info, events)
        return resp(environ, start_response)
    except Exception as err:
        jlog.error({'response_from': func.__name__, 'err': err})
        events.store(EV_EXCEPTION, err)
        dump_log(session_info, events)
        raise
示例#3
0
def webfinger(environ, start_response, session_info, events, jlog, **kwargs):
    _query = session_info['parameters']
    events.store(EV_REQUEST, Operation("WebFinger", _query))

    try:
        assert _query["rel"] == [OIC_ISSUER]
        resource = _query["resource"][0]
    except AssertionError:
        errmsg = "Wrong 'rel' value: %s" % _query["rel"][0]
        events.store(EV_FAULT, errmsg)
        resp = BadRequest(errmsg)
    except KeyError:
        errmsg = "Missing 'rel' parameter in request"
        events.store(EV_FAULT, errmsg)
        resp = BadRequest(errmsg)
    else:
        wf = WebFinger()

        _url = os.path.join(kwargs["op_arg"]["baseurl"],
                            session_info['oper_id'],
                            session_info["test_id"])

        _mesg = wf.response(subject=resource, base=_url)
        if session_info['test_id'] == 'rp-discovery-webfinger-http-href':
            _msg = json.loads(_mesg)
            _msg['links'][0]['href'] = _msg['links'][0]['href'].replace(
                'https', 'http')
            _mesg = json.dumps(_msg)
        elif session_info['test_id'] == 'rp-discovery-webfinger-unknown-member':
            _msg = json.loads(_mesg)
            _msg['dummy'] = 'foobar'
            _mesg = json.dumps(_msg)

        resp = Response(_mesg,
                        content="application/jrd+json")

        events.store(EV_RESPONSE, resp.message)

    jlog.info(resp2json(resp))

    dump_log(session_info, events)
    return resp(environ, start_response)
示例#4
0
def webfinger(environ, start_response, session_info, events, jlog, **kwargs):
    _query = session_info['parameters']
    events.store(EV_REQUEST, Operation("WebFinger", _query))

    try:
        assert _query["rel"] == [OIC_ISSUER]
        resource = _query["resource"][0]
    except AssertionError:
        errmsg = "Wrong 'rel' value: %s" % _query["rel"][0]
        events.store(EV_FAULT, errmsg)
        resp = BadRequest(errmsg)
    except KeyError:
        errmsg = "Missing 'rel' parameter in request"
        events.store(EV_FAULT, errmsg)
        resp = BadRequest(errmsg)
    else:
        wf = WebFinger()

        _url = os.path.join(kwargs["op_arg"]["baseurl"],
                            session_info['oper_id'], session_info["test_id"])

        _mesg = wf.response(subject=resource, base=_url)
        if session_info['test_id'] == 'rp-discovery-webfinger-http-href':
            _msg = json.loads(_mesg)
            _msg['links'][0]['href'] = _msg['links'][0]['href'].replace(
                'https', 'http')
            _mesg = json.dumps(_msg)
        elif session_info[
                'test_id'] == 'rp-discovery-webfinger-unknown-member':
            _msg = json.loads(_mesg)
            _msg['dummy'] = 'foobar'
            _mesg = json.dumps(_msg)

        resp = Response(_mesg, content="application/jrd+json")

        events.store(EV_RESPONSE, resp.message)

    jlog.info(resp2json(resp))

    dump_log(session_info, events)
    return resp(environ, start_response)