def index(self, op, **kwargs): if cherrypy.request.method == "OPTIONS": cherrypy_cors.preflight(allowed_methods=["GET"], origins='*', allowed_headers='Authorization') else: try: authz = cherrypy.request.headers['Authorization'] except KeyError: authz = None try: assert authz.startswith("Bearer") except AssertionError: op.events.store(EV_FAULT, "Bad authorization token") cherrypy.HTTPError(400, "Bad authorization token") tok = authz[7:] try: _claims = op.claim_access_token[tok] except KeyError: op.events.store(EV_FAULT, "Bad authorization token") cherrypy.HTTPError(400, "Bad authorization token") else: # one time token del op.claim_access_token[tok] _info = Message(**_claims) jwt_key = op.keyjar.get_signing_key() op.events.store(EV_RESPONSE, _info.to_dict()) cherrypy.response.headers["content-type"] = 'application/jwt' return as_bytes(_info.to_jwt(key=jwt_key, algorithm="RS256"))
def test_to_dict_with_message_obj(): content = Message(a={"a": {"foo": {"bar": [{"bat": []}]}}}) _dict = content.to_dict(lev=0) content_fixture = { "a": { "a": { "foo": { "bar": [{ "bat": [] }] } } } } # type: ignore assert _dict == content_fixture
def test_to_dict_with_raw_types(): msg = Message(c_default=[]) content_fixture = {'c_default': []} _dict = msg.to_dict(lev=1) assert _dict == content_fixture
def test_to_dict_with_message_obj(): content = Message(a={'a': {'foo': {'bar': [{'bat': []}]}}}) _dict = content.to_dict(lev=0) content_fixture = {'a': {'a': {'foo': {'bar': [{'bat': []}]}}}} assert _dict == content_fixture
def test_to_dict_with_raw_types(): msg = Message(c_default=[]) content_fixture = {"c_default": []} # type: ignore _dict = msg.to_dict(lev=1) assert _dict == content_fixture