def setUp(self): self.h = fake_authz_headers(FAKE_FILE.data) self.hglobal = fake_authz_headers( FAKE_FILE.data, roles={"Global Admin": { 'group': ['global'] }}) webtest.WebCase.PORT = PORT self.engine = cherrypy.engine self.proc = load_server(self.engine)
def test_upload_tgz(self, fmt='application/json', page="/test/file", inbody=None): h = fake_authz_headers(RT.test_authz_key.data) + [("Accept", fmt)] # empty of input submit failing with 400 self.getPage(page, headers=h, method="PUT", body=None) self.assertStatus("400 Bad Request") self.assertHeader("X-Error-Http", "400") self.assertHeader("X-Error-Detail", "Invalid input parameter") # empty inputfile body1 = 'hashkey=' + self.checksum h1 = h + [('Content-Length', len(body1))] self.getPage(page, headers=h1, method="PUT", body=body1) self.assertStatus("400 Bad Request") self.assertHeader("X-Error-Http", "400") self.assertHeader("X-Error-Detail", "Invalid input parameter") # real upload request # TODO this is not working because it gets 'File is not a .tgz file.' b2 = """--x Content-Disposition: form-data; name="inputfile"; filename="%s" Content-Type: application/x-tar %s --x Content-Disposition: form-data; name="hashkey" %s --x-- """ % (self.tgz.name, open(self.tgz.name, 'rb').read(), self.checksum) h2 = [("Content-type", "multipart/form-data; boundary=x"), ("Content-Length", len(b2))] self.getPage(page, headers=h + h2, method="PUT", body=b2)
def test_workflow_non_null_submit(self, fmt='application/json', page="/test/workflow", inbody=SUBMIT_BODY): """Try submitting job with all the parameters """ h = fake_authz_headers(RT.test_authz_key.data) + [("Accept", fmt)] self.getPage(page, headers=h, method="PUT", body=inbody)
def test(self): h = fake_authz_headers(T.test_authz_key.data) h.append(("Accept", "application/json")) for _ in xrange(0, 10): self.getPage("/test/status", headers=h) print self.body time.sleep(.3)
def test_upload_tgz(self, fmt='application/json', page="/test/file", inbody = None): h = fake_authz_headers(RT.test_authz_key.data) + [("Accept", fmt)] # empty of input submit failing with 400 self.getPage(page, headers=h, method="PUT", body=None) self.assertStatus("400 Bad Request") self.assertHeader("X-Error-Http", "400") self.assertHeader("X-Error-Detail", "Invalid input parameter") # empty inputfile body1 = 'hashkey='+self.checksum h1 = h + [('Content-Length', len(body1))] self.getPage(page, headers=h1, method="PUT", body=body1) self.assertStatus("400 Bad Request") self.assertHeader("X-Error-Http", "400") self.assertHeader("X-Error-Detail", "Invalid input parameter") # real upload request # TODO this is not working because it gets 'File is not a .tgz file.' b2 = """--x Content-Disposition: form-data; name="inputfile"; filename="%s" Content-Type: application/x-tar %s --x Content-Disposition: form-data; name="hashkey" %s --x-- """ % (self.tgz.name, open(self.tgz.name,'rb').read(), self.checksum) h2 = [("Content-type", "multipart/form-data; boundary=x"), ("Content-Length", len(b2))] self.getPage(page, headers=h+h2, method="PUT", body=b2)
def __init__(self, app, baseurl, mount, cacertdir = "/etc/grid-security/certificates", minreq = 1000, interval = 300, instance = "test"): Thread.__init__(self, name = "LdapSync") self.sectoken = "".join(random.sample(string.letters, 30)) self._inturl = "http://localhost:%d%s/%s/ldapsync" % \ (app.srvconfig.port, mount, instance) self._headers = \ fake_authz_headers(open(app.srvconfig.tools.cms_auth.key_file).read(), method = "Internal", login = self.sectoken, name = self.__class__.__name__, dn = None, roles = {"Global Admin": {"group": ["global"]}}) \ + [("Accept", "application/json")] self._cv = Condition() if isinstance(baseurl, str): self._baseurl = baseurl self._cacertdir = cacertdir self._minreq = minreq self._interval = interval self._stopme = False self._full = (0, [], []) self._warnings = {} self._intreq = RequestManager(num_connections = 2, user_agent = self._ident, handle_init = self._handle_init, request_respond = self._respond, request_init = self._int_init) cherrypy.engine.subscribe("stop", self.stop) cherrypy.engine.subscribe("start", self.start)
def test_exists_json(self, fmt='application/json', page="/test/file", inbody=None): h = fake_authz_headers(RT.test_authz_key.data) + [("Accept", fmt)] username = [head[1] for head in h if head[0] == 'cms-authn-login'][-1] # empty request failing self.getPage(page, headers=h, method="GET", body=None) self.assertStatus("400 Bad Request") self.assertHeader("X-Error-Http", "400") self.assertHeader("X-Error-Detail", "Invalid input parameter") # checking a not existing file body1 = '?hashkey=' + str(64 * 'a') + '&nodownload=1' self.getPage(page + body1, headers=h, method="GET", body=inbody) self.assertStatus("404 Not Found") self.assertHeader("X-Error-Http", "404") self.assertHeader("X-Error-Detail", "No such instance") self.assertHeader("X-Error-Info", "Not found") # checking a real file tgz, checksum = self._fake_upload_json(username) body1 = '?inputfilename=' + os.path.basename( tgz.name) + '&nodownload=1' self.getPage(page + body1, headers=h, method="GET", body=inbody) self.assertStatus("200 OK") self.assertHeader("Content-Type", fmt) self.assertInBody(checksum)
def test_auth_success(self): h = fake_authz_headers(T.test_authz_key.data, roles={"Global Admin": { 'group': ['global'] }}) self.getPage("/test/global_admin", headers=h) self.assertStatus("200 OK") self.assertBody("ok")
def test_worklow_invalid_param(self, fmt = 'application/json', page = "/test/workflow", inbody=None): """Try getting workflow with some extra invalid parameter provided""" h = fake_authz_headers(RT.test_authz_key.data) + [("Accept", fmt)] self.getPage(page + '?workflow=pippo&invalid_param=xxx', headers=h, method="GET", body=inbody) self.assertStatus("400 Bad Request") self.assertHeader("X-Error-Http", "400") self.assertHeader("X-Error-Detail", "Invalid input parameter")
def test_workflow_get_wo_workflow(self, fmt = 'application/json', page = "/test/workflow", inbody=None): """Try getting workflow without workflow parameter provided""" h = fake_authz_headers(RT.test_authz_key.data) + [("Accept", fmt)] self.getPage(page + '?subresource=data', headers=h, method="GET", body=inbody) self.assertStatus("400 Bad Request") self.assertHeader("X-Error-Http", "400") self.assertHeader("X-Error-Detail", "Invalid input parameter")
def test_workflow_invalid_param_only(self,fmt = 'application/json', page = "/test/workflow", inbody=SUBMIT_BODY): """Try submitting job with invalid parameter ONLY """ h = fake_authz_headers(RT.test_authz_key.data) + [("Accept", fmt)] self.getPage(page + '?invalid=x',headers=h, method="GET", body=inbody) self.assertStatus("400 Bad Request") self.assertHeader("X-Error-Http", "400") self.assertHeader("X-Error-Detail", "Invalid input parameter")
def test_workflow_empty_submit(self, fmt = 'application/json', page = "/test/workflow",inbody = None): """Try to submit workflow without any parameters""" h = fake_authz_headers(RT.test_authz_key.data) + [("Accept", fmt)] self.getPage(page, headers=h, method="PUT", body=inbody) self.assertStatus("400 Bad Request") self.assertHeader("X-Error-Http", "400") self.assertHeader("X-Error-Detail", "Invalid input parameter")
def test_workflow_too_long_param(self, fmt = 'application/json', page = "/test/workflow", inbody=None): """Try getting workflow with random and too long parameter provided """ h = fake_authz_headers(RT.test_authz_key.data) + [("Accept", fmt)] randomlongname=''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(200)) self.getPage(page + '?workflow='+randomlongname, headers=h, method="GET", body=inbody) self.assertStatus("400 Bad Request") self.assertHeader("X-Error-Http", "400") self.assertHeader("X-Error-Detail", "Invalid input parameter")
def getAuthHeader(hmacData, reqAuth): roles = {} for role in reqAuth['role']: roles[role] = {'group': reqAuth['group']} return fake_authz_headers(hmacData, dn="/TEST/DN/CN", roles=roles, format="dict")
def test_multi_throw5b(self): h = fake_authz_headers(T.test_authz_key.data) h.append(("Accept", "application/json")) self.getPage("/test/multi?lim=5", headers = h) self.assertStatus(400) self.assertHeader("X-REST-Status", "200") self.assertHeader("X-Error-HTTP", "400") self.assertHeader("X-Error-Info", "cut at 5") self.assertHeader("X-Error-Detail", "Invalid object") self.assertHeader("X-Error-ID")
def test_multi_throw5b(self): h = fake_authz_headers(T.test_authz_key.data) h.append(("Accept", "application/json")) self.getPage("/test/multi?lim=5", headers=h) self.assertStatus(400) self.assertHeader("X-REST-Status", "200") self.assertHeader("X-Error-HTTP", "400") self.assertHeader("X-Error-Info", "cut at 5") self.assertHeader("X-Error-Detail", "Invalid object") self.assertHeader("X-Error-ID")
def _test_accept_fail(self, fmt, page="/test/simple", avail="application/json, application/xml"): h = fake_authz_headers(T.test_authz_key.data) + [("Accept", fmt)] self.getPage(page, headers = h) self.assertStatus("406 Not Acceptable") self.assertHeader("X-REST-Status", "201") self.assertHeader("X-REST-Time") self.assertHeader("X-Error-ID") self.assertHeader("X-Error-HTTP", "406") self.assertHeader("X-Error-Info", "Available types: %s" % avail) self.assertHeader("X-Error-Detail", "Not acceptable") self.assertInBody("Not acceptable")
def test_simple_json(self): h = fake_authz_headers(T.test_authz_key.data) h.append(("Accept", "application/json")) self.getPage("/test/simple", headers=h) self.assertStatus("200 OK") b = cjson.decode(self.body) assert isinstance(b, dict) assert "desc" not in b assert "result" in b assert isinstance(b["result"], list) assert len(b["result"]) == 1 assert b["result"][0] == "foo"
def test_simple_json(self): h = fake_authz_headers(T.test_authz_key.data) h.append(("Accept", "application/json")) self.getPage("/test/simple", headers = h) self.assertStatus("200 OK") b = cjson.decode(self.body) assert isinstance(b, dict) assert "desc" not in b assert "result" in b assert isinstance(b["result"], list) assert len(b["result"]) == 1 assert b["result"][0] == "foo"
def _test_accept_fail(self, fmt, page="/test/simple", avail="application/json, application/xml"): h = fake_authz_headers(T.test_authz_key.data) + [("Accept", fmt)] self.getPage(page, headers=h) self.assertStatus("406 Not Acceptable") self.assertHeader("X-REST-Status", "201") self.assertHeader("X-REST-Time") self.assertHeader("X-Error-ID") self.assertHeader("X-Error-HTTP", "406") self.assertHeader("X-Error-Info", "Available types: %s" % avail) self.assertHeader("X-Error-Detail", "Not acceptable") self.assertInBody("Not acceptable")
def test_download_tgz(self, fmt='application/octet-stream', page="/test/file", inbody = None): h = fake_authz_headers(RT.test_authz_key.data) + [("Accept", fmt)] # empty request failing self.getPage(page, headers=h, method="GET", body=None) self.assertStatus("400 Bad Request") self.assertHeader("X-Error-Http", "400") self.assertHeader("X-Error-Detail", "Invalid input parameter") # real file upload tgz, checksum = self._fake_upload_isb() body1 = '?hashkey='+checksum self.getPage(page + body1, headers=h, method="GET", body=inbody) self.assertStatus("200 OK") self.assertHeader("Content-Disposition", 'attachment; filename="%s"' % checksum) self.assertHeader("Content-Type", fmt)
def test_simple_json_deflate(self): h = fake_authz_headers(T.test_authz_key.data) h.append(("Accept", "application/json")) h.append(("Accept-Encoding", "deflate")) self.getPage("/test/simple", headers = h) self.assertStatus("200 OK") self.assertHeader("Content-Length") self.assertHeader("Content-Encoding", "deflate") b = cjson.decode(zlib.decompress(self.body, -zlib.MAX_WBITS)) assert isinstance(b, dict) assert "desc" not in b assert "result" in b assert isinstance(b["result"], list) assert len(b["result"]) == 1 assert b["result"][0] == "foo"
def test_simple_json_deflate(self): h = fake_authz_headers(T.test_authz_key.data) h.append(("Accept", "application/json")) h.append(("Accept-Encoding", "deflate")) self.getPage("/test/simple", headers=h) self.assertStatus("200 OK") self.assertHeader("Content-Length") self.assertHeader("Content-Encoding", "deflate") b = cjson.decode(zlib.decompress(self.body, -zlib.MAX_WBITS)) assert isinstance(b, dict) assert "desc" not in b assert "result" in b assert isinstance(b["result"], list) assert len(b["result"]) == 1 assert b["result"][0] == "foo"
def test_download_json(self, fmt='application/octet-stream', page="/test/file", inbody = None): h = fake_authz_headers(RT.test_authz_key.data) + [("Accept", fmt)] username = [head[1] for head in h if head[0] == 'cms-authn-login'][-1] # empty request failing self.getPage(page, headers=h, method="GET", body=None) self.assertStatus("400 Bad Request") self.assertHeader("X-Error-Http", "400") self.assertHeader("X-Error-Detail", "Invalid input parameter") # real file download tgz, checksum = self._fake_upload_json(username) body1 = '?inputfilename='+os.path.basename(tgz.name) self.getPage(page + body1, headers=h, method="GET", body=inbody) self.assertStatus("200 OK") self.assertHeader("Content-Disposition", 'attachment; filename="%s"' % os.path.basename(tgz.name)) self.assertHeader("Content-Type", fmt)
def _test_accept_ok(self, fmt, page = "/test/simple", inbody = None): h = fake_authz_headers(T.test_authz_key.data) + [("Accept", fmt)] self.getPage(page, headers = h) self.assertStatus("200 OK") if fmt.find("*") >= 0: self.assertHeader("Content-Type") else: self.assertHeader("Content-Type", fmt) self.assertHeader("X-REST-Status", "100") self.assertHeader("X-REST-Time") self.assertNoHeader("X-Error-ID") self.assertNoHeader("X-Error-HTTP") self.assertNoHeader("X-Error-Info") self.assertNoHeader("X-Error-Detail") if inbody: self.assertInBody(inbody)
def test_multi_throw10(self): h = fake_authz_headers(T.test_authz_key.data) h.append(("Accept", "application/json")) self.getPage("/test/multi?lim=10&etag=x", headers = h) self.assertStatus("200 OK") self.assertHeader("X-REST-Status", "100") b = cjson.decode(self.body) assert isinstance(b, dict) assert "desc" not in b assert "result" in b assert isinstance(b["result"], list) assert len(b["result"]) == 10 for i in xrange(0, 10): assert isinstance(b["result"][i], list) assert b["result"][i][0] == "row" assert b["result"][i][1] == i
def test_multi_throw10(self): h = fake_authz_headers(T.test_authz_key.data) h.append(("Accept", "application/json")) self.getPage("/test/multi?lim=10&etag=x", headers=h) self.assertStatus("200 OK") self.assertHeader("X-REST-Status", "100") b = cjson.decode(self.body) assert isinstance(b, dict) assert "desc" not in b assert "result" in b assert isinstance(b["result"], list) assert len(b["result"]) == 10 for i in xrange(0, 10): assert isinstance(b["result"][i], list) assert b["result"][i][0] == "row" assert b["result"][i][1] == i
def _test_accept_ok(self, fmt, page="/test/simple", inbody=None): h = fake_authz_headers(T.test_authz_key.data) + [("Accept", fmt)] self.getPage(page, headers=h) self.assertStatus("200 OK") if fmt.find("*") >= 0: self.assertHeader("Content-Type") else: self.assertHeader("Content-Type", fmt) self.assertHeader("X-REST-Status", "100") self.assertHeader("X-REST-Time") self.assertNoHeader("X-Error-ID") self.assertNoHeader("X-Error-HTTP") self.assertNoHeader("X-Error-Info") self.assertNoHeader("X-Error-Detail") if inbody: self.assertInBody(inbody)
def test_download_tgz(self, fmt='application/octet-stream', page="/test/file", inbody=None): h = fake_authz_headers(RT.test_authz_key.data) + [("Accept", fmt)] # empty request failing self.getPage(page, headers=h, method="GET", body=None) self.assertStatus("400 Bad Request") self.assertHeader("X-Error-Http", "400") self.assertHeader("X-Error-Detail", "Invalid input parameter") # real file upload tgz, checksum = self._fake_upload_isb() body1 = '?hashkey=' + checksum self.getPage(page + body1, headers=h, method="GET", body=inbody) self.assertStatus("200 OK") self.assertHeader("Content-Disposition", 'attachment; filename="%s"' % checksum) self.assertHeader("Content-Type", fmt)
def test_download_json(self, fmt='application/octet-stream', page="/test/file", inbody=None): h = fake_authz_headers(RT.test_authz_key.data) + [("Accept", fmt)] username = [head[1] for head in h if head[0] == 'cms-authn-login'][-1] # empty request failing self.getPage(page, headers=h, method="GET", body=None) self.assertStatus("400 Bad Request") self.assertHeader("X-Error-Http", "400") self.assertHeader("X-Error-Detail", "Invalid input parameter") # real file download tgz, checksum = self._fake_upload_json(username) body1 = '?inputfilename=' + os.path.basename(tgz.name) self.getPage(page + body1, headers=h, method="GET", body=inbody) self.assertStatus("200 OK") self.assertHeader( "Content-Disposition", 'attachment; filename="%s"' % os.path.basename(tgz.name)) self.assertHeader("Content-Type", fmt)
def test_exists_tgz(self, fmt='application/json', page="/test/file", inbody = None): h = fake_authz_headers(RT.test_authz_key.data) + [("Accept", fmt)] # empty request failing self.getPage(page, headers=h, method="GET", body=None) self.assertStatus("400 Bad Request") self.assertHeader("X-Error-Http", "400") self.assertHeader("X-Error-Detail", "Invalid input parameter") # checking a not existing file body1 = '?hashkey='+str(64*'a')+'&nodownload=1' self.getPage(page + body1, headers=h, method="GET", body=inbody) self.assertStatus("404 Not Found") self.assertHeader("X-Error-Http", "404") self.assertHeader("X-Error-Detail", "No such instance") self.assertHeader("X-Error-Info", "Not found") # checking a real file tgz, checksum = self._fake_upload_isb() body1 = '?hashkey='+checksum+'&nodownload=1' self.getPage(page + body1, headers=h, method="GET", body=inbody) self.assertStatus("200 OK") self.assertHeader("Content-Type", fmt) self.assertInBody(checksum)
def test_auth_success(self): h = fake_authz_headers(T.test_authz_key.data, roles = {"Global Admin": {'group': ['global']}}) self.getPage("/test/global_admin", headers = h) self.assertStatus("200 OK") self.assertBody("ok")
def getAuthHeader(hmacData, reqAuth): roles = {} for role in reqAuth['role']: roles[role] = {'group': reqAuth['group']} return fake_authz_headers(hmacData, roles = roles, format = "dict")
def test_workflow_non_null_submit(self, fmt = 'application/json', page = "/test/workflow",inbody = SUBMIT_BODY): """Try submitting job with all the parameters """ h = fake_authz_headers(RT.test_authz_key.data) + [("Accept", fmt)] self.getPage(page, headers=h, method="PUT", body=inbody)
def test_basic_success(self): h = fake_authz_headers(T.test_authz_key.data) self.getPage("/test", headers = h) self.assertStatus("200 OK") self.assertBody("foo")
def getAuthHeader(hmacData, reqAuth): roles = {} for role in reqAuth["role"]: roles[role] = {"group": reqAuth["group"]} return fake_authz_headers(hmacData, dn="/TEST/DN/CN", roles=roles, format="dict")
def test_auth_fail(self): h = fake_authz_headers(T.test_authz_key.data) self.getPage("/test/global_admin", headers = h) self.assertStatus("403 Forbidden")
def test_basic_success(self): h = fake_authz_headers(T.test_authz_key.data) self.getPage("/test", headers=h) self.assertStatus("200 OK") self.assertBody("foo")
def setUp(self): self.h = fake_authz_headers(FAKE_FILE.data) self.hglobal = fake_authz_headers(FAKE_FILE.data, roles = {"Global Admin": {'group': ['global']}}) webtest.WebCase.PORT = PORT self.engine = cherrypy.engine self.proc = load_server(self.engine)
def test_auth_fail(self): h = fake_authz_headers(T.test_authz_key.data) self.getPage("/test/global_admin", headers=h) self.assertStatus("403 Forbidden")
def setUp(self): self.h = fake_authz_headers(FAKE_FILE.data) webtest.WebCase.PORT = PORT self.engine = cherrypy.engine self.proc = load_server(self.engine)