Commit 794a5a22 authored by Łukasz Nowak's avatar Łukasz Nowak

fix "caddy-frontend/test: Prove that disabled-cookie-list does not work"

In the end curl seems the tool which gives full control over order of the
cookies, especially with upcoming migration to python3.
parent 56d5705a
...@@ -4370,32 +4370,34 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin): ...@@ -4370,32 +4370,34 @@ class TestSlave(SlaveHttpFrontendTestCase, TestDataMixin):
def test_disabled_cookie_list(self): def test_disabled_cookie_list(self):
parameter_dict = self.assertSlaveBase('disabled-cookie-list') parameter_dict = self.assertSlaveBase('disabled-cookie-list')
result = fakeHTTPSResult( replacement_dict = dict(
parameter_dict['domain'], 'test-path', domain=parameter_dict['domain'], ip=TEST_IP, port=HTTPS_PORT)
# Note: The cookies are always sorted in python2, but not in python3 so curl_command = [
# the order here is important. OrderdedDict won't work, as 'curl', '-v', '-k', '-H',
# internal implementation of requests will deny it's usage. '"Host:', '%(domain)s' % replacement_dict,
# Thus take ultra care with changing anything here or on the '--resolve', '%(domain)s:%(port)s:%(ip)s' % replacement_dict,
# disabled-cookie-list shared instance parameter ordering, as it 'https://%(domain)s:%(port)s/' % replacement_dict,
# can easily result with passing of the tests. '--cookie',
# One of the solutions would be to use curl to make this query. # Note: Cookie order is extremely important here, do not change
cookies=dict( # or test will start to pass incorrectly
Coconut='absent', '"Coconut=absent; Chocolate=absent; Coffee=present; Vanilia=absent"'
Coffee='present', ]
Chocolate='absent', prc = subprocess.Popen(
Vanilia='absent', curl_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)) )
out, err = prc.communicate()
self.assertEqual( self.assertEqual(
self.certificate_pem, prc.returncode, 0,
der2pem(result.peercert)) "Problem running %r. Output:\n%s\nError:\n%s" % (
curl_command, out, err))
self.assertEqualResultJson(result, 'Path', '/test-path') # self check - were the cookies sent in required order?
self.assertIn(
self.assertBackendHeaders( '> cookie: "Coconut=absent; Chocolate=absent; Coffee=present; '
result.json()['Incoming Headers'], parameter_dict['domain']) 'Vanilia=absent"',
err)
# real test - all configured cookies are dropped
self.assertEqual( self.assertEqual(
'Coffee=present', result.json()['Incoming Headers']['cookie']) 'Coffee=present', json.loads(out)['Incoming Headers']['cookie'])
def test_https_url(self): def test_https_url(self):
parameter_dict = self.assertSlaveBase('url_https-url') parameter_dict = self.assertSlaveBase('url_https-url')
......
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