Commit 312acd55 authored by Łukasz Nowak's avatar Łukasz Nowak

software/rapid-cdn: Switch to recurls

This class mimics requests, but as an engine to access sites it uses curl
command, which is expected to be provided with a lot of features, including
full HTTP3 support.
parent d383c10c
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
import glob import glob
import os import os
import requests from recurls import Recurls
import http.client import http.client
from requests_toolbelt.adapters import source from requests_toolbelt.adapters import source
import json import json
...@@ -261,18 +261,7 @@ def subprocess_output(*args, **kwargs): ...@@ -261,18 +261,7 @@ def subprocess_output(*args, **kwargs):
return subprocess_status_output(*args, **kwargs)[1] return subprocess_status_output(*args, **kwargs)[1]
def isHTTP2(domain): mimikra = Recurls()
curl_command = 'curl --http2 -v -k -H "Host: %(domain)s" ' \
'https://%(domain)s:%(https_port)s/ '\
'--resolve %(domain)s:%(https_port)s:%(ip)s' % dict(
ip=TEST_IP, domain=domain, https_port=HTTPS_PORT)
prc = subprocess.Popen(
curl_command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
out, err = prc.communicate()
assert prc.returncode == 0, "Problem running %r. Output:\n%s\nError:\n%s" % (
curl_command, out, err)
return 'Using HTTP2, server supports'.encode() in err
class AtsMixin(object): class AtsMixin(object):
...@@ -982,6 +971,33 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase): ...@@ -982,6 +971,33 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
except Exception as e: except Exception as e:
self.fail(e) self.fail(e)
def assertHttp2(self, domain):
result = mimikra.get(
'https://%(domain)s:%(https_port)s/' % dict(
domain=domain, https_port=HTTPS_PORT),
resolve_all={HTTPS_PORT: TEST_IP},
verify=False
)
self.assertEqual('2', result.protocol)
def assertHttp11(self, domain):
result = mimikra.get(
'https://%(domain)s:%(https_port)s/' % dict(
domain=domain, https_port=HTTPS_PORT),
resolve_all={HTTPS_PORT: TEST_IP},
verify=False
)
self.assertEqual('1.1', result.protocol)
def assertHttp1(self, domain):
result = mimikra.get(
'https://%(domain)s:%(https_port)s/' % dict(
domain=domain, https_port=HTTPS_PORT),
resolve_all={HTTPS_PORT: TEST_IP},
verify=False
)
self.assertEqual('1', result.protocol)
def assertResponseHeaders( def assertResponseHeaders(
self, result, cached=False, via=True, backend_reached=True): self, result, cached=False, via=True, backend_reached=True):
headers = result.headers.copy() headers = result.headers.copy()
...@@ -2353,8 +2369,10 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -2353,8 +2369,10 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'_Url_access_log', '_Url_access_log',
r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} - - ' r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} - - '
r'\[\d{2}\/.{3}\/\d{4}\:\d{2}\:\d{2}\:\d{2} \+\d{4}\] ' r'\[\d{2}\/.{3}\/\d{4}\:\d{2}\:\d{2}\:\d{2} \+\d{4}\] '
r'"GET \/test-path\/deep\/..\/.\/deeper HTTP\/1.1" \d{3} ' r'"GET https:\/\/%(domain)s:%(port)s\/test-path\/deep\/..\/.\/deeper '
r'\d+ "-" "TEST USER AGENT" \d+' r'HTTP\/2.0" \d{3} '
r'\d+ "-" "TEST USER AGENT" \d+' % dict(
domain=parameter_dict['domain'], port=HTTPS_PORT)
) )
self.assertLastLogLineRegexp( self.assertLastLogLineRegexp(
...@@ -2622,7 +2640,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -2622,7 +2640,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
<from>Jani</from> <from>Jani</from>
<heading>Reminder</heading> <heading>Reminder</heading>
<body>Don't forget me this weekend!</body> <body>Don't forget me this weekend!</body>
</note>"""), </note>""").decode(),
'X-Drop-Header': 'Content-Type' 'X-Drop-Header': 'Content-Type'
} }
) )
...@@ -3290,8 +3308,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -3290,8 +3308,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
j['Incoming Headers']['connection'] j['Incoming Headers']['connection']
) )
self.assertTrue('x-real-ip' in j['Incoming Headers']) self.assertTrue('x-real-ip' in j['Incoming Headers'])
self.assertFalse( self.assertHttp11(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
def test_type_websocket(self): def test_type_websocket(self):
parameter_dict = self.assertSlaveBase( parameter_dict = self.assertSlaveBase(
...@@ -3320,8 +3337,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -3320,8 +3337,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
j['Incoming Headers']['connection'] j['Incoming Headers']['connection']
) )
self.assertTrue('x-real-ip' in j['Incoming Headers']) self.assertTrue('x-real-ip' in j['Incoming Headers'])
self.assertFalse( self.assertHttp11(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
def test_type_websocket_websocket_transparent_false(self): def test_type_websocket_websocket_transparent_false(self):
parameter_dict = self.assertSlaveBase( parameter_dict = self.assertSlaveBase(
...@@ -3351,8 +3367,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -3351,8 +3367,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
j['Incoming Headers']['connection'] j['Incoming Headers']['connection']
) )
self.assertFalse('x-real-ip' in j['Incoming Headers']) self.assertFalse('x-real-ip' in j['Incoming Headers'])
self.assertFalse( self.assertHttp11(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
def test_type_websocket_websocket_path_list(self): def test_type_websocket_websocket_path_list(self):
parameter_dict = self.assertSlaveBase( parameter_dict = self.assertSlaveBase(
...@@ -3371,8 +3386,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -3371,8 +3386,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'Path', 'Path',
'/test-path' '/test-path'
) )
self.assertFalse( self.assertHttp1(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
try: try:
j = result.json() j = result.json()
except Exception: except Exception:
...@@ -3389,8 +3403,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -3389,8 +3403,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'Path', 'Path',
'/ws/test-path' '/ws/test-path'
) )
self.assertFalse( self.assertHttp1(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
try: try:
j = result.json() j = result.json()
except Exception: except Exception:
...@@ -3411,8 +3424,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -3411,8 +3424,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'Path', 'Path',
'/with%20space/test-path' '/with%20space/test-path'
) )
self.assertFalse( self.assertHttp1(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
try: try:
j = result.json() j = result.json()
except Exception: except Exception:
...@@ -3442,8 +3454,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -3442,8 +3454,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'Path', 'Path',
'/test-path' '/test-path'
) )
self.assertFalse( self.assertHttp1(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
try: try:
j = result.json() j = result.json()
except Exception: except Exception:
...@@ -3460,8 +3471,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -3460,8 +3471,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'Path', 'Path',
'/ws/test-path' '/ws/test-path'
) )
self.assertFalse( self.assertHttp1(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
try: try:
j = result.json() j = result.json()
except Exception: except Exception:
...@@ -3483,8 +3493,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -3483,8 +3493,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'Path', 'Path',
'/with%20space/test-path' '/with%20space/test-path'
) )
self.assertFalse( self.assertHttp1(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
try: try:
j = result.json() j = result.json()
except Exception: except Exception:
...@@ -4213,8 +4222,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -4213,8 +4222,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
headers headers
) )
self.assertFalse( self.assertHttp11(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
def test_enable_http2_default(self): def test_enable_http2_default(self):
parameter_dict = self.assertSlaveBase('enable-http2-default') parameter_dict = self.assertSlaveBase('enable-http2-default')
...@@ -4238,8 +4246,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin): ...@@ -4238,8 +4246,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
headers headers
) )
self.assertTrue( self.assertHttp2(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
def test_prefer_gzip_encoding_to_backend_https_only(self): def test_prefer_gzip_encoding_to_backend_https_only(self):
parameter_dict = self.assertSlaveBase( parameter_dict = self.assertSlaveBase(
...@@ -4774,20 +4781,17 @@ class TestEnableHttp2ByDefaultFalseSlave(SlaveHttpFrontendTestCase, ...@@ -4774,20 +4781,17 @@ class TestEnableHttp2ByDefaultFalseSlave(SlaveHttpFrontendTestCase,
def test_enable_http2_default(self): def test_enable_http2_default(self):
parameter_dict = self.assertSlaveBase('enable-http2-default') parameter_dict = self.assertSlaveBase('enable-http2-default')
self.assertFalse( self.assertHttp11(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
def test_enable_http2_false(self): def test_enable_http2_false(self):
parameter_dict = self.assertSlaveBase('enable-http2-false') parameter_dict = self.assertSlaveBase('enable-http2-false')
self.assertFalse( self.assertHttp11(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
def test_enable_http2_true(self): def test_enable_http2_true(self):
parameter_dict = self.assertSlaveBase('enable-http2-true') parameter_dict = self.assertSlaveBase('enable-http2-true')
self.assertTrue( self.assertHttp2(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
class TestEnableHttp2ByDefaultDefaultSlave(SlaveHttpFrontendTestCase, class TestEnableHttp2ByDefaultDefaultSlave(SlaveHttpFrontendTestCase,
...@@ -4822,20 +4826,17 @@ class TestEnableHttp2ByDefaultDefaultSlave(SlaveHttpFrontendTestCase, ...@@ -4822,20 +4826,17 @@ class TestEnableHttp2ByDefaultDefaultSlave(SlaveHttpFrontendTestCase,
def test_enable_http2_default(self): def test_enable_http2_default(self):
parameter_dict = self.assertSlaveBase('enable-http2-default') parameter_dict = self.assertSlaveBase('enable-http2-default')
self.assertTrue( self.assertHttp2(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
def test_enable_http2_false(self): def test_enable_http2_false(self):
parameter_dict = self.assertSlaveBase('enable-http2-false') parameter_dict = self.assertSlaveBase('enable-http2-false')
self.assertFalse( self.assertHttp11(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
def test_enable_http2_true(self): def test_enable_http2_true(self):
parameter_dict = self.assertSlaveBase('enable-http2-true') parameter_dict = self.assertSlaveBase('enable-http2-true')
self.assertTrue( self.assertHttp2(parameter_dict['domain'])
isHTTP2(parameter_dict['domain']))
class TestRe6stVerificationUrlDefaultSlave(SlaveHttpFrontendTestCase, class TestRe6stVerificationUrlDefaultSlave(SlaveHttpFrontendTestCase,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment