c.putheader('Content-Type', 'text/plain') # See http://www.cherrypy.org/ticket/941 c._output('Re, 1.2.3.4#015#012') c.endheaders() response = c.getresponse() self.status = str(response.status) self.assertStatus(400) self.body = response.fp.read() self.assertBody("Illegal header line.") def test_http_over_https(self): if self.scheme != 'https': return self.skip("skipped (not running HTTPS)... ") # Try connecting without SSL. conn = HTTPConnection('%s:%s' % (self.interface(), self.PORT)) conn.putrequest("GET", "/", skip_host=True) conn.putheader("Host", self.HOST) conn.endheaders() response = conn.response_class(conn.sock, method="GET") response.begin() self.assertEqual(response.status, 400) self.body = response.read() self.assertBody("The client sent a plain HTTP request, but this " "server only speaks HTTPS on this port.") if __name__ == '__main__': helper.testmain()
c = HTTPConnection(host) try: c.putrequest('GET', '/') c.endheaders() response = c.getresponse() body = response.read() self.assertEqual(response.status, 200) self.assertEqual(body, "Hello world!") finally: c.close() success.append(True) ITERATIONS = 25 ts = [] for _ in range(ITERATIONS): t = threading.Thread(target=getpage) ts.append(t) t.start() for t in ts: t.join() self.assertEqual(len(success), ITERATIONS) self.getPage("/gc_stats") self.assertBody("Statistics:") if __name__ == '__main__': helper.testmain({'server.socket_queue_size': 10})
self.getPage("/page3") self.assertStatus('200 OK') self.assertBody(pov) # Apache, for example, may emit a Connection header even for HTTP/1.0 ## self.assertNoHeader("Connection") def test_598(self): remote_data_conn = urllib.urlopen('%s://%s:%s/one_megabyte_of_a/' % (self.scheme, self.HOST, self.PORT,)) buf = remote_data_conn.read(512) time.sleep(timeout * 0.6) remaining = (1024 * 1024) - 512 while remaining: data = remote_data_conn.read(remaining) if not data: break else: buf += data remaining -= len(data) self.assertEqual(len(buf), 1024 * 1024) self.assertEqual(buf, "a" * 1024 * 1024) self.assertEqual(remaining, 0) remote_data_conn.close() if __name__ == "__main__": setup_server() helper.testmain({'server.socket_timeout': timeout, 'server.socket_host': '127.0.0.1'})
self.assertInBody("""<a href="/error?code=500">""") self.assertInBody("""<a href="/messageArg">""") self.getPage("/traceback_setting") setting = self.body self.getPage("/toggleTracebacks") self.assertStatus((302, 303)) self.getPage("/traceback_setting") self.assertBody(str(not eval(setting))) self.getPage("/error?code=500") self.assertStatus(500) self.assertInBody("The server encountered an unexpected condition " "which prevented it from fulfilling the request.") self.getPage("/error?code=403") self.assertStatus(403) self.assertInBody("<h2>You can't do that!</h2>") self.getPage("/messageArg") self.assertStatus(500) self.assertInBody("If you construct an HTTPError with a 'message'") if __name__ == "__main__": helper.testmain({ 'server.socket_host': '127.0.0.1', 'server.socket_port': 8080, 'server.thread_pool': 10, })
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 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_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 setup_server(): srcfile = __file__.split("/")[-1].split(".py")[0] setup_test_server(srcfile, "Root") if __name__ == '__main__': setup_server() helper.testmain()
try: c.putrequest('GET', '/') c.endheaders() response = c.getresponse() body = response.read() self.assertEqual(response.status, 200) self.assertEqual(body, "Hello world!") finally: c.close() success.append(True) ITERATIONS = 25 ts = [] for _ in range(ITERATIONS): t = threading.Thread(target=getpage) ts.append(t) t.start() for t in ts: t.join() self.assertEqual(len(success), ITERATIONS) self.getPage("/gc_stats") self.assertBody("Statistics:") if __name__ == '__main__': setup_server() helper.testmain({'server.socket_queue_size': 10})