Add tests for auth_server_session_private
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/e709f7c0 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/e709f7c0 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/e709f7c0 Branch: refs/heads/master Commit: e709f7c08d0516fd03a9a906d11d6fa33245cb23 Parents: f54516c Author: Thomas Jackson <[email protected]> Authored: Fri Apr 24 19:29:33 2015 -0700 Committer: Thomas Jackson <[email protected]> Committed: Sun Apr 26 19:13:41 2015 -0700 ---------------------------------------------------------------------- ci/new_tsqa/tests/test_keepalive.py | 125 +++++++++++++++++++++++++++---- 1 file changed, 111 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/e709f7c0/ci/new_tsqa/tests/test_keepalive.py ---------------------------------------------------------------------- diff --git a/ci/new_tsqa/tests/test_keepalive.py b/ci/new_tsqa/tests/test_keepalive.py index c94d4d1..0e501ce 100644 --- a/ci/new_tsqa/tests/test_keepalive.py +++ b/ci/new_tsqa/tests/test_keepalive.py @@ -68,13 +68,41 @@ class KeepAliveInMixin(object): s.connect(('127.0.0.1', int(self.configs['records.config']['CONFIG']['proxy.config.http.server_ports']))) return s - def _aux_working_path(self, protocol): + def _headers_to_str(self, headers): + if headers is None: + headers = {} + request = '' + for k, v in headers.iteritems(): + request += '{0}: {1}\r\n'.format(k, v) + return request + + def _aux_KA_working_path_connid(self, protocol, headers=None): + # connect tcp + s = self._get_socket() + + request = ('GET / HTTP/1.1\r\n' + 'Host: foobar.com\r\n') + request += self._headers_to_str(headers) + request += '\r\n' + + for x in xrange(1, 10): + s.send(request) + response = s.recv(4096) + # cheat, since we know what the body should have + if '\r\n\r\n' not in response: + response += s.recv(4096) + self.assertIn('HTTP/1.1 200 OK', response) + self.assertIn('hello', response) + + def _aux_working_path(self, protocol, headers=None): # connect tcp s = self._get_socket() request = ('GET /exists/ HTTP/1.1\r\n' - 'Host: foobar.com\r\n' - '\r\n') + 'Host: foobar.com\r\n') + request += self._headers_to_str(headers) + request += '\r\n' + for x in xrange(1, 10): s.send(request) response = s.recv(4096) @@ -84,19 +112,20 @@ class KeepAliveInMixin(object): self.assertIn('HTTP/1.1 200 OK', response) self.assertIn('hello', response) - def _aux_error_path(self, protocol): + def _aux_error_path(self, protocol, headers=None): # connect tcp s = self._get_socket() request = ('GET / HTTP/1.1\r\n' - 'Host: foobar.com\r\n' - '\r\n') + 'Host: foobar.com\r\n') + request += self._headers_to_str(headers) + request += '\r\n' for x in xrange(1, 10): s.send(request) response = s.recv(4096) self.assertIn('HTTP/1.1 404 Not Found on Accelerator', response) - def _aux_error_path_post(self, protocol): + def _aux_error_path_post(self, protocol, headers=None): ''' Ensure that sending a request with a body doesn't break the keepalive session ''' @@ -105,9 +134,11 @@ class KeepAliveInMixin(object): request = ('POST / HTTP/1.1\r\n' 'Host: foobar.com\r\n' - 'Content-Length: 10\r\n' - '\r\n' - '1234567890') + 'Content-Length: 10\r\n') + request += self._headers_to_str(headers) + request += '\r\n' + request += '1234567890' + for x in xrange(1, 10): try: s.send(request) @@ -123,7 +154,7 @@ class KeepAliveInMixin(object): class BasicTestsOutMixin(object): - def _aux_KA_origin(self, protocol): + def _aux_KA_origin(self, protocol, headers=None): ''' Test that the origin does in fact support keepalive ''' @@ -131,13 +162,13 @@ class BasicTestsOutMixin(object): with requests.Session() as s: url = '{0}://127.0.0.1:{1}/'.format(protocol, self.socket_server.port) for x in xrange(1, 10): - ret = s.get(url, verify=False) + ret = s.get(url, verify=False, headers=headers) if not conn_id: conn_id = ret.text.strip() self.assertEqual(ret.status_code, 200) self.assertEqual(ret.text.strip(), conn_id, "Client reports server closed connection") - def _aux_KA_proxy(self, protocol): + def _aux_KA_proxy(self, protocol, headers=None): ''' Test that keepalive works through ATS to that origin ''' @@ -145,7 +176,7 @@ class BasicTestsOutMixin(object): self.configs['records.config']['CONFIG']['proxy.config.http.server_ports']) conn_id = None for x in xrange(1, 10): - ret = requests.get(url, verify=False) + ret = requests.get(url, verify=False, headers=headers) if not conn_id: conn_id = ret.text.strip() self.assertEqual(ret.status_code, 200) @@ -190,6 +221,7 @@ class OriginMinMaxMixin(object): ret = requests.get(url, verify=False) self.assertEqual(ret.text.strip(), conn_id, "Client reports server closed connection") + class TestKeepAliveInHTTP(tsqa.test_cases.DynamicHTTPEndpointCase, helpers.EnvironmentCase, KeepAliveInMixin): @classmethod def setUpEnv(cls, env): @@ -377,3 +409,68 @@ class TestKeepAliveOutHTTPS(helpers.EnvironmentCase, BasicTestsOutMixin, Timeout def test_KA_timeout_proxy(self): '''Tests that keepalive timeout is honored through ATS to origin via https.''' self._aux_KA_timeout_proxy("http") + + + +# TODO: refactor these tests, these are *very* similar, we should paramatarize them +## Some basic tests for auth_sever_session_private +class TestKeepAlive_Authorization_private(helpers.EnvironmentCase, BasicTestsOutMixin, KeepAliveInMixin): + @classmethod + def setUpEnv(cls, env): + + cls.socket_server = tsqa.endpoint.SocketServerDaemon(KeepaliveTCPHandler) + cls.socket_server.start() + cls.socket_server.ready.wait() + cls.configs['remap.config'].add_line('map / http://127.0.0.1:{0}/exists/'.format(cls.socket_server.port)) + + # only add server headers when there weren't any + cls.configs['records.config']['CONFIG']['proxy.config.http.response_server_enabled'] = 2 + cls.configs['records.config']['CONFIG']['proxy.config.http.keep_alive_enabled_in'] = 1 + cls.configs['records.config']['CONFIG']['share_server_session'] = 2 + + # set only one ET_NET thread (so we don't have to worry about the per-thread pools causing issues) + cls.configs['records.config']['CONFIG']['proxy.config.exec_thread.limit'] = 1 + cls.configs['records.config']['CONFIG']['proxy.config.exec_thread.autoconfig'] = 0 + + # make auth sessions private + cls.configs['records.config']['CONFIG']['proxy.config.auth_server_session_private'] = 1 + + def test_KA_server(self): + '''Tests that keepalive works through ATS to origin via https.''' + with self.assertRaises(AssertionError): + self._aux_KA_proxy("http", headers={'Authorization': 'Foo'}) + + def test_KA_client(self): + '''Tests that keepalive works through ATS to origin via https.''' + with self.assertRaises(AssertionError): + self._aux_KA_working_path_connid("http", headers={'Authorization': 'Foo'}) + + +class TestKeepAlive_Authorization_no_private(helpers.EnvironmentCase, BasicTestsOutMixin, KeepAliveInMixin): + @classmethod + def setUpEnv(cls, env): + + cls.socket_server = tsqa.endpoint.SocketServerDaemon(KeepaliveTCPHandler) + cls.socket_server.start() + cls.socket_server.ready.wait() + cls.configs['remap.config'].add_line('map / http://127.0.0.1:{0}/exists/'.format(cls.socket_server.port)) + + # only add server headers when there weren't any + cls.configs['records.config']['CONFIG']['proxy.config.http.response_server_enabled'] = 2 + cls.configs['records.config']['CONFIG']['proxy.config.http.keep_alive_enabled_in'] = 1 + cls.configs['records.config']['CONFIG']['share_server_session'] = 2 + + # set only one ET_NET thread (so we don't have to worry about the per-thread pools causing issues) + cls.configs['records.config']['CONFIG']['proxy.config.exec_thread.limit'] = 1 + cls.configs['records.config']['CONFIG']['proxy.config.exec_thread.autoconfig'] = 0 + + # make auth sessions private + cls.configs['records.config']['CONFIG']['proxy.config.http.auth_server_session_private'] = 0 + + def test_KA_server(self): + '''Tests that keepalive works through ATS to origin via https.''' + self._aux_KA_proxy("http", headers={'Authorization': 'Foo'}) + + def test_KA_client(self): + '''Tests that keepalive works through ATS to origin via https.''' + self._aux_KA_working_path_connid("http", headers={'Authorization': 'Foo'})
