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 @@
import glob
import os
import requests
from recurls import Recurls
import http.client
from requests_toolbelt.adapters import source
import json
......@@ -261,18 +261,7 @@ def subprocess_output(*args, **kwargs):
return subprocess_status_output(*args, **kwargs)[1]
def isHTTP2(domain):
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
mimikra = Recurls()
class AtsMixin(object):
......@@ -982,6 +971,33 @@ class HttpFrontendTestCase(SlapOSInstanceTestCase):
except Exception as 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(
self, result, cached=False, via=True, backend_reached=True):
headers = result.headers.copy()
......@@ -2353,8 +2369,10 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'_Url_access_log',
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'"GET \/test-path\/deep\/..\/.\/deeper HTTP\/1.1" \d{3} '
r'\d+ "-" "TEST USER AGENT" \d+'
r'"GET https:\/\/%(domain)s:%(port)s\/test-path\/deep\/..\/.\/deeper '
r'HTTP\/2.0" \d{3} '
r'\d+ "-" "TEST USER AGENT" \d+' % dict(
domain=parameter_dict['domain'], port=HTTPS_PORT)
)
self.assertLastLogLineRegexp(
......@@ -2622,7 +2640,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>"""),
</note>""").decode(),
'X-Drop-Header': 'Content-Type'
}
)
......@@ -3290,8 +3308,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
j['Incoming Headers']['connection']
)
self.assertTrue('x-real-ip' in j['Incoming Headers'])
self.assertFalse(
isHTTP2(parameter_dict['domain']))
self.assertHttp11(parameter_dict['domain'])
def test_type_websocket(self):
parameter_dict = self.assertSlaveBase(
......@@ -3320,8 +3337,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
j['Incoming Headers']['connection']
)
self.assertTrue('x-real-ip' in j['Incoming Headers'])
self.assertFalse(
isHTTP2(parameter_dict['domain']))
self.assertHttp11(parameter_dict['domain'])
def test_type_websocket_websocket_transparent_false(self):
parameter_dict = self.assertSlaveBase(
......@@ -3351,8 +3367,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
j['Incoming Headers']['connection']
)
self.assertFalse('x-real-ip' in j['Incoming Headers'])
self.assertFalse(
isHTTP2(parameter_dict['domain']))
self.assertHttp11(parameter_dict['domain'])
def test_type_websocket_websocket_path_list(self):
parameter_dict = self.assertSlaveBase(
......@@ -3371,8 +3386,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'Path',
'/test-path'
)
self.assertFalse(
isHTTP2(parameter_dict['domain']))
self.assertHttp1(parameter_dict['domain'])
try:
j = result.json()
except Exception:
......@@ -3389,8 +3403,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'Path',
'/ws/test-path'
)
self.assertFalse(
isHTTP2(parameter_dict['domain']))
self.assertHttp1(parameter_dict['domain'])
try:
j = result.json()
except Exception:
......@@ -3411,8 +3424,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'Path',
'/with%20space/test-path'
)
self.assertFalse(
isHTTP2(parameter_dict['domain']))
self.assertHttp1(parameter_dict['domain'])
try:
j = result.json()
except Exception:
......@@ -3442,8 +3454,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'Path',
'/test-path'
)
self.assertFalse(
isHTTP2(parameter_dict['domain']))
self.assertHttp1(parameter_dict['domain'])
try:
j = result.json()
except Exception:
......@@ -3460,8 +3471,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'Path',
'/ws/test-path'
)
self.assertFalse(
isHTTP2(parameter_dict['domain']))
self.assertHttp1(parameter_dict['domain'])
try:
j = result.json()
except Exception:
......@@ -3483,8 +3493,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
'Path',
'/with%20space/test-path'
)
self.assertFalse(
isHTTP2(parameter_dict['domain']))
self.assertHttp1(parameter_dict['domain'])
try:
j = result.json()
except Exception:
......@@ -4213,8 +4222,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
headers
)
self.assertFalse(
isHTTP2(parameter_dict['domain']))
self.assertHttp11(parameter_dict['domain'])
def test_enable_http2_default(self):
parameter_dict = self.assertSlaveBase('enable-http2-default')
......@@ -4238,8 +4246,7 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin, AtsMixin):
headers
)
self.assertTrue(
isHTTP2(parameter_dict['domain']))
self.assertHttp2(parameter_dict['domain'])
def test_prefer_gzip_encoding_to_backend_https_only(self):
parameter_dict = self.assertSlaveBase(
......@@ -4774,20 +4781,17 @@ class TestEnableHttp2ByDefaultFalseSlave(SlaveHttpFrontendTestCase,
def test_enable_http2_default(self):
parameter_dict = self.assertSlaveBase('enable-http2-default')
self.assertFalse(
isHTTP2(parameter_dict['domain']))
self.assertHttp11(parameter_dict['domain'])
def test_enable_http2_false(self):
parameter_dict = self.assertSlaveBase('enable-http2-false')
self.assertFalse(
isHTTP2(parameter_dict['domain']))
self.assertHttp11(parameter_dict['domain'])
def test_enable_http2_true(self):
parameter_dict = self.assertSlaveBase('enable-http2-true')
self.assertTrue(
isHTTP2(parameter_dict['domain']))
self.assertHttp2(parameter_dict['domain'])
class TestEnableHttp2ByDefaultDefaultSlave(SlaveHttpFrontendTestCase,
......@@ -4822,20 +4826,17 @@ class TestEnableHttp2ByDefaultDefaultSlave(SlaveHttpFrontendTestCase,
def test_enable_http2_default(self):
parameter_dict = self.assertSlaveBase('enable-http2-default')
self.assertTrue(
isHTTP2(parameter_dict['domain']))
self.assertHttp2(parameter_dict['domain'])
def test_enable_http2_false(self):
parameter_dict = self.assertSlaveBase('enable-http2-false')
self.assertFalse(
isHTTP2(parameter_dict['domain']))
self.assertHttp11(parameter_dict['domain'])
def test_enable_http2_true(self):
parameter_dict = self.assertSlaveBase('enable-http2-true')
self.assertTrue(
isHTTP2(parameter_dict['domain']))
self.assertHttp2(parameter_dict['domain'])
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