"Fossies" - the Fresh Open Source Software Archive

Member "mod_http2-1.15.17/test/e2e/test_500_proxy.py" (5 Nov 2020, 5822 Bytes) of package /linux/www/apache_httpd_modules/mod_http2-1.15.17.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test_500_proxy.py": 1.15.16_vs_1.15.17.

    1 #
    2 # mod-h2 test suite
    3 # check HTTP/1.1 proxied backend
    4 #
    5 
    6 import os
    7 import re
    8 import pytest
    9 
   10 from TestEnv import TestEnv
   11 from TestHttpdConf import HttpdConf
   12 
   13 def setup_module(module):
   14     print("setup_module: %s" % module.__name__)
   15     TestEnv.init()
   16     TestEnv.setup_data_1k_1m()
   17     HttpdConf().add_vhost_cgi( proxy_self=True ).install()
   18     assert TestEnv.apache_restart() == 0
   19         
   20 def teardown_module(module):
   21     print("teardown_module: %s" % module.__name__)
   22     assert TestEnv.apache_stop() == 0
   23 
   24 class TestStore:
   25 
   26     def setup_method(self, method):
   27         print("setup_method: %s" % method.__name__)
   28 
   29     def teardown_method(self, method):
   30         print("teardown_method: %s" % method.__name__)
   31 
   32     def test_500_01(self):
   33         url = TestEnv.mkurl("https", "cgi", "/proxy/hello.py")
   34         r = TestEnv.curl_get(url, 5)
   35         assert 200 == r["response"]["status"]
   36         assert "HTTP/1.1" == r["response"]["json"]["protocol"]
   37         assert "" == r["response"]["json"]["https"]
   38         assert "" == r["response"]["json"]["ssl_protocol"]
   39         assert "" == r["response"]["json"]["h2"]
   40         assert "" == r["response"]["json"]["h2push"]
   41 
   42 
   43     # upload and GET again using curl, compare to original content
   44     def curl_upload_and_verify(self, fname, options=None):
   45         url = TestEnv.mkurl("https", "cgi", "/proxy/upload.py")
   46         fpath = os.path.join(TestEnv.GEN_DIR, fname)
   47         r = TestEnv.curl_upload(url, fpath, options=options)
   48         assert r["rv"] == 0
   49         assert 200 <= r["response"]["status"] < 300
   50 
   51         # why is the scheme wrong?
   52         r2 = TestEnv.curl_get(re.sub(r'http:', 'https:', r["response"]["header"]["location"]))
   53         assert r2["rv"] == 0
   54         assert r2["response"]["status"] == 200 
   55         with open(TestEnv.e2e_src( fpath ), mode='rb') as file:
   56             src = file.read()
   57         assert src == r2["response"]["body"]
   58 
   59     def test_500_10(self):
   60         self.curl_upload_and_verify( "data-1k", [ "--http2" ] )
   61         self.curl_upload_and_verify( "data-10k", [ "--http2" ] )
   62         self.curl_upload_and_verify( "data-100k", [ "--http2" ] )
   63         self.curl_upload_and_verify( "data-1m", [ "--http2" ] )
   64 
   65 
   66     # POST some data using nghttp and see it echo'ed properly back
   67     def nghttp_post_and_verify(self, fname, options=None):
   68         url = TestEnv.mkurl("https", "cgi", "/proxy/echo.py")
   69         fpath = os.path.join(TestEnv.GEN_DIR, fname)
   70         r = TestEnv.nghttp().upload(url, fpath, options=options)
   71         assert r["rv"] == 0
   72         assert 200 <= r["response"]["status"] < 300
   73         with open(TestEnv.e2e_src( fpath ), mode='rb') as file:
   74             src = file.read()
   75         #assert len(src) == len(r["response"]["body"])
   76         assert src == r["response"]["body"]
   77 
   78     @pytest.mark.skipif(not TestEnv.has_nghttp(), reason="no nghttp command available")
   79     def test_500_20(self):
   80         self.nghttp_post_and_verify( "data-1k", [ ] )
   81         self.nghttp_post_and_verify( "data-10k", [ ] )
   82         self.nghttp_post_and_verify( "data-100k", [ ] )
   83         self.nghttp_post_and_verify( "data-1m", [ ] )
   84 
   85     @pytest.mark.skipif(not TestEnv.has_nghttp(), reason="no nghttp command available")
   86     def test_500_21(self):
   87         self.nghttp_post_and_verify( "data-1k", [ "--no-content-length" ] )
   88         self.nghttp_post_and_verify( "data-10k", [ "--no-content-length" ] )
   89         self.nghttp_post_and_verify( "data-100k", [ "--no-content-length" ] )
   90         self.nghttp_post_and_verify( "data-1m", [ "--no-content-length" ] )
   91 
   92 
   93     # upload and GET again using nghttp, compare to original content
   94     def nghttp_upload_and_verify(self, fname, options=None):
   95         url = TestEnv.mkurl("https", "cgi", "/proxy/upload.py")
   96         fpath = os.path.join(TestEnv.GEN_DIR, fname)
   97 
   98         r = TestEnv.nghttp().upload_file(url, fpath, options=options)
   99         assert r["rv"] == 0
  100         assert 200 <= r["response"]["status"] < 300
  101         assert r["response"]["header"]["location"]
  102 
  103         # why is the scheme wrong?
  104         r2 = TestEnv.nghttp().get(re.sub(r'http:', 'https:', r["response"]["header"]["location"]))
  105         assert r2["rv"] == 0
  106         assert r2["response"]["status"] == 200 
  107         with open(TestEnv.e2e_src( fpath ), mode='rb') as file:
  108             src = file.read()
  109         assert src == r2["response"]["body"]
  110 
  111     @pytest.mark.skipif(not TestEnv.has_nghttp(), reason="no nghttp command available")
  112     def test_500_22(self):
  113         self.nghttp_upload_and_verify( "data-1k", [ ] )
  114         self.nghttp_upload_and_verify( "data-10k", [ ] )
  115         self.nghttp_upload_and_verify( "data-100k", [ ] )
  116         self.nghttp_upload_and_verify( "data-1m", [ ] )
  117 
  118     @pytest.mark.skipif(not TestEnv.has_nghttp() or True, reason="no nghttp command available and python3 chokes in chunks")
  119     def test_500_23(self):
  120         self.nghttp_upload_and_verify( "data-1k", [ "--no-content-length" ] )
  121         self.nghttp_upload_and_verify( "data-10k", [  "--no-content-length" ] )
  122         self.nghttp_upload_and_verify( "data-100k", [  "--no-content-length" ] )
  123         self.nghttp_upload_and_verify( "data-1m", [  "--no-content-length" ] )
  124 
  125     # upload using nghttp and check returned status
  126     def nghttp_upload_stat(self, fname, options=None):
  127         url = TestEnv.mkurl("https", "cgi", "/proxy/upload.py")
  128         fpath = os.path.join(TestEnv.GEN_DIR, fname)
  129 
  130         r = TestEnv.nghttp().upload_file(url, fpath, options=options)
  131         assert r["rv"] == 0
  132         assert 200 <= r["response"]["status"] < 300
  133         assert r["response"]["header"]["location"]
  134 
  135     @pytest.mark.skipif(not TestEnv.has_nghttp() or True, reason="no nghttp command available and python3 chokes on chunks")
  136     def test_500_24(self):
  137         for i in range(100):
  138             self.nghttp_upload_stat( "data-1k", [ "--no-content-length" ] )
  139