def check_nghttp_body(self, ref_input, nghttp_output): with open(TestEnv.e2e_src( os.path.join(TestEnv.GEN_DIR, ref_input) ), mode='rb') as f: refbody = f.read() with open(TestEnv.e2e_src( nghttp_output), mode='rb') as f: text = f.read() o = TestEnv.nghttp().parse_output(text) assert "response" in o assert "body" in o["response"] if refbody != o["response"]["body"]: with open(TestEnv.e2e_src( os.path.join(TestEnv.GEN_DIR, '%s.parsed' % ref_input) ), mode='wb') as f: f.write( o["response"]["body"] ) assert len(refbody) == len(o["response"]["body"]) assert refbody == o["response"]["body"]
def nghttp_post_and_verify(self, fname, options=None): url = TestEnv.mkurl("https", "cgi", "/proxy/echo.py") fpath = os.path.join(TestEnv.GEN_DIR, fname) r = TestEnv.nghttp().upload(url, fpath, options=options) assert r["rv"] == 0 assert 200 <= r["response"]["status"] < 300 with open(TestEnv.e2e_src(fpath), mode='rb') as file: src = file.read() #assert len(src) == len(r["response"]["body"]) assert src == r["response"]["body"]
def nghttp_post_and_verify(self, fname, options=None): url = TestEnv.mkurl("https", "cgi", "/echo.py") fpath = os.path.join(TestEnv.GEN_DIR, fname) r = TestEnv.nghttp().upload(url, fpath, options=options) assert r["rv"] == 0 assert r["response"]["status"] >= 200 and r["response"]["status"] < 300 with open(TestEnv.e2e_src( fpath ), mode='rb') as file: src = file.read() assert src == r["response"]["body"]
def curl_upload_and_verify(self, fname, options=None): url = TestEnv.mkurl("https", "cgi", "/upload.py") fpath = os.path.join(TestEnv.GEN_DIR, fname) r = TestEnv.curl_upload(url, fpath, options=options) assert r["rv"] == 0 assert r["response"]["status"] >= 200 and r["response"]["status"] < 300 r2 = TestEnv.curl_get(r["response"]["header"]["location"]) assert r2["rv"] == 0 assert r2["response"]["status"] == 200 with open(TestEnv.e2e_src(fpath), mode='rb') as file: src = file.read() assert src == r2["response"]["body"]
def curl_upload_and_verify(self, fname, options=None): url = TestEnv.mkurl("https", "cgi", "/upload.py") fpath = os.path.join(TestEnv.GEN_DIR, fname) r = TestEnv.curl_upload(url, fpath, options=options) assert r["rv"] == 0 assert r["response"]["status"] >= 200 and r["response"]["status"] < 300 r2 = TestEnv.curl_get( r["response"]["header"]["location"]) assert r2["rv"] == 0 assert r2["response"]["status"] == 200 with open(TestEnv.e2e_src( fpath ), mode='rb') as file: src = file.read() assert src == r2["response"]["body"]
def curl_upload_and_verify(self, fname, options=None): url = TestEnv.mkurl("https", "cgi", "/proxy/upload.py") fpath = os.path.join(TestEnv.GEN_DIR, fname) r = TestEnv.curl_upload(url, fpath, options=options) assert r["rv"] == 0 assert 200 <= r["response"]["status"] < 300 # why is the scheme wrong? r2 = TestEnv.curl_get( re.sub(r'http:', 'https:', r["response"]["header"]["location"])) assert r2["rv"] == 0 assert r2["response"]["status"] == 200 with open(TestEnv.e2e_src(fpath), mode='rb') as file: src = file.read() assert src == r2["response"]["body"]
def test_003_02(self): with open(TestEnv.e2e_src( "htdocs/test1/index.html"), mode='rb') as file: src = file.read() url = TestEnv.mkurl("https", "test1", "/index.html") r = TestEnv.curl_get(url, 5) assert 200 == r["response"]["status"] assert "HTTP/2" == r["response"]["protocol"] assert src == r["response"]["body"] url = TestEnv.mkurl("https", "test1", "/index.html") r = TestEnv.curl_get(url, 5, [ "--http1.1" ]) assert 200 == r["response"]["status"] assert "HTTP/1.1" == r["response"]["protocol"] assert src == r["response"]["body"]
def test_003_02(self): with open(TestEnv.e2e_src( "htdocs/test1/index.html"), mode='rb') as file: src = file.read() url = TestEnv.mkurl("https", "test1", "/index.html") r = TestEnv.curl_get(url, 5) assert 200 == r["response"]["status"] assert "HTTP/2" == r["response"]["protocol"] assert src == r["response"]["body"] url = TestEnv.mkurl("https", "test1", "/index.html") r = TestEnv.curl_get(url, 5, [ "--http1.1" ]) assert 200 == r["response"]["status"] assert "HTTP/1.1" == r["response"]["protocol"] assert src == r["response"]["body"]
def nghttp_upload_and_verify(self, fname, options=None): url = TestEnv.mkurl("https", "cgi", "/proxy/upload.py") fpath = os.path.join(TestEnv.GEN_DIR, fname) r = TestEnv.nghttp().upload_file(url, fpath, options=options) assert r["rv"] == 0 assert r["response"]["status"] >= 200 and r["response"]["status"] < 300 assert r["response"]["header"]["location"] # why is the scheme wrong? r2 = TestEnv.nghttp().get(re.sub(r'http:', 'https:', r["response"]["header"]["location"])) assert r2["rv"] == 0 assert r2["response"]["status"] == 200 with open(TestEnv.e2e_src( fpath ), mode='rb') as file: src = file.read() assert src == r2["response"]["body"]
def post_and_verify(fname, options=None): url = TestEnv.mkurl("https", "cgi", "/h2test/echo") fpath = os.path.join(TestEnv.GEN_DIR, fname) r = TestEnv.curl_upload(url, fpath, options=options) assert r["rv"] == 0 assert r["response"]["status"] >= 200 and r["response"][ "status"] < 300 ct = r["response"]["header"]["content-type"] mail_hd = "Content-Type: " + ct + "\r\nMIME-Version: 1.0\r\n\r\n" mime_msg = mail_hd.encode() + r["response"]["body"] # this MIME API is from hell body = email.parser.BytesParser().parsebytes(mime_msg) assert body assert body.is_multipart() filepart = None for part in body.walk(): if fname == part.get_filename(): filepart = part assert filepart with open(TestEnv.e2e_src(fpath), mode='rb') as file: src = file.read() assert src == filepart.get_payload(decode=True)