def resource(environ, start_response, logger, kaka=None): """ """ _log_info = logger.info _session_db = environ["oic.sessiondb"] _conc = environ["oic.consumer.config"] _oac = consumer.factory(kaka, _session_db, _conc) if _oac is None: resp = http_util.Unauthorized("No valid cookie") return resp(environ, start_response) url = "http://localhost:8088/safe" response, content = _oac.fetch_protected_resource(url) if _oac.debug: _log_info("response: %s (%s)" % (response, type(response))) resp = http_util.factory(response.status, content) # if kaka: # resp.headers.append(kaka) return resp(environ, start_response)
def resource_set_registration_endpoint_(self, owner, path, method, client_id, body="", if_match="", **kwargs): """ The endpoint at which the resource server handles resource sets descriptions. :param owner: The entity that controls the resource set :param path: The path for the HTTP request :param method: HTTP method :param body: The resource set registration message :param client_id: Which client I'm talking to :param if_match: The HTTP If-Match header if any :param kwargs: possible other arguments :returns: A Response instance """ # path must be /resource_set/{rsid} or /resource_set # Path may or may not start with '/' if path.startswith("/"): assert path[1:].startswith(RSR_PATH) rsid = path[PLEN + 1:] else: assert path.startswith(RSR_PATH) rsid = path[PLEN:] if rsid.startswith("/"): rsid = rsid[1:] # user names are not globally unique, so I have to make such an # identifier logger.debug("handling resource set belonging to '%s'" % owner) adb = self.get_adb(client_id) code, msg, kwargs = adb.resource_set_registration(method, owner, body=body, rsid=rsid) return factory(code, msg, **kwargs)
def test_resource_set_registration(): adb = ADB(KEYJAR, 3600, issuer, RESSRV, RSR_PATH) rsd = ResourceSetDescription(name='foo', scopes=[READ, WRITE]) code, msg, kwargs = adb.resource_set_registration('POST', 'alice', rsd.to_json()) assert code == 201 http_response = factory(code, msg, **kwargs) assert isinstance(http_response, Created) jm = json.loads(msg) rsid = jm['_id'] # List all rsid code, msg, kwargs = adb.resource_set_registration('GET', 'alice') assert code == 200 rsid_list = json.loads(msg) assert rsid in rsid_list # get a specific resource set code, msg, kwargs = adb.resource_set_registration('GET', 'alice', rsid=rsid) assert code == 200 rs = json.loads(msg) assert rs['name'] == rsd['name'] assert rs['scopes'] == rsd['scopes'] assert rs['_id'] == rsid # upload a new version of a resource set rsd = ResourceSetDescription(name='foo', scopes=[READ, WRITE], type='document') code, msg, kwargs = adb.resource_set_registration('PUT', 'alice', body=rsd.to_json(), rsid=rsid) assert code == 200 rs = json.loads(msg) assert rs['_id'] == rsid # make sure the change came through code, msg, kwargs = adb.resource_set_registration('GET', 'alice', rsid=rsid) assert code == 200 rs = json.loads(msg) assert _eq(list(rs.keys()),['name', 'scopes', '_id', 'type']) for key in ['name', 'scopes', 'type']: assert rs[key] == rsd[key] assert rs['_id'] == rsid # delete resource set code, msg, kwargs = adb.resource_set_registration('DELETE', 'alice', rsid=rsid) assert code == 204 # List all rsid code, msg, kwargs = adb.resource_set_registration('GET', 'alice') assert code == 200 rsid_list = json.loads(msg) assert rsid_list == []
def test_resource_set_registration(): adb = ADB(KEYJAR, 3600, issuer, RESSRV, RSR_PATH) rsd = ResourceSetDescription(name='foo', scopes=[READ, WRITE]) code, msg, kwargs = adb.resource_set_registration('POST', 'alice', rsd.to_json()) assert code == 201 http_response = factory(code, msg, **kwargs) assert isinstance(http_response, Created) jm = json.loads(msg) rsid = jm['_id'] # List all rsid code, msg, kwargs = adb.resource_set_registration('GET', 'alice') assert code == 200 rsid_list = json.loads(msg) assert rsid in rsid_list # get a specific resource set code, msg, kwargs = adb.resource_set_registration('GET', 'alice', rsid=rsid) assert code == 200 rs = json.loads(msg) assert rs['name'] == rsd['name'] assert rs['scopes'] == rsd['scopes'] assert rs['_id'] == rsid # upload a new version of a resource set rsd = ResourceSetDescription(name='foo', scopes=[READ, WRITE], type='document') code, msg, kwargs = adb.resource_set_registration('PUT', 'alice', body=rsd.to_json(), rsid=rsid) assert code == 200 rs = json.loads(msg) assert rs['_id'] == rsid # make sure the change came through code, msg, kwargs = adb.resource_set_registration('GET', 'alice', rsid=rsid) assert code == 200 rs = json.loads(msg) assert _eq(list(rs.keys()), ['name', 'scopes', '_id', 'type']) for key in ['name', 'scopes', 'type']: assert rs[key] == rsd[key] assert rs['_id'] == rsid # delete resource set code, msg, kwargs = adb.resource_set_registration('DELETE', 'alice', rsid=rsid) assert code == 204 # List all rsid code, msg, kwargs = adb.resource_set_registration('GET', 'alice') assert code == 200 rsid_list = json.loads(msg) assert rsid_list == []