Repository: trafficserver Updated Branches: refs/heads/master d8d1b0871 -> 3210351f3
add initial remap tests Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/7cb8b29b Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/7cb8b29b Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/7cb8b29b Branch: refs/heads/master Commit: 7cb8b29b0509f06553b09bb280a7fe3373565fff Parents: d8d1b08 Author: Feifei Cai <[email protected]> Authored: Wed Mar 4 10:35:10 2015 +0000 Committer: Thomas Jackson <[email protected]> Committed: Thu Mar 26 17:59:50 2015 -0700 ---------------------------------------------------------------------- ci/new_tsqa/tests/test_remap.py | 119 +++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7cb8b29b/ci/new_tsqa/tests/test_remap.py ---------------------------------------------------------------------- diff --git a/ci/new_tsqa/tests/test_remap.py b/ci/new_tsqa/tests/test_remap.py new file mode 100644 index 0000000..c6acd59 --- /dev/null +++ b/ci/new_tsqa/tests/test_remap.py @@ -0,0 +1,119 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import requests +import time +import logging + +import helpers + +import tsqa.test_cases +import tsqa.utils +import tsqa.endpoint + +log = logging.getLogger(__name__) + +unittest = tsqa.utils.import_unittest() + +class TestRemapHTTP(helpers.EnvironmentCase): + @classmethod + def setUpEnv(cls, env): + cls.configs['records.config']['CONFIG'].update({ + 'proxy.config.diags.debug.enabled': 1, + 'proxy.config.diags.debug.tags': 'url.*', + }) + + # test with a httpbin running on localhost and port 8000 + cls.configs['remap.config'].add_line('map http://www.example.com http://127.0.0.1:8000/\n'); + cls.configs['remap.config'].add_line('map http://www.example.com:8080 http://127.0.0.1:8000/\n'); + + def test_remap_http(self): + s = requests.Session() + http_port = self.configs['records.config']['CONFIG']['proxy.config.http.server_ports'] + url = 'http://127.0.0.1:{0}/get'.format(http_port) + + ret = s.get(url) + self.assertEqual(ret.status_code, 404) + + s.headers.update({'Host': 'www.example.com'}) + ret = s.get(url) + self.assertEqual(ret.status_code, 200) + + s.headers.update({'Host': 'www.example.com:80'}) + ret = s.get(url) + self.assertEqual(ret.status_code, 200) + + s.headers.update({'Host': 'www.example.com:8080'}) + ret = s.get(url) + self.assertEqual(ret.status_code, 200) + + s.headers.update({'Host': 'www.test.com'}) + ret = s.get(url) + self.assertEqual(ret.status_code, 404) + + s.headers.update({'Host': 'www.example.com:1234'}) + ret = s.get(url) + self.assertEqual(ret.status_code, 404) + +class TestRemapHTTPS(helpers.EnvironmentCase): + @classmethod + def setUpEnv(cls, env): + # set an SSL port to ATS + cls.ssl_port = tsqa.utils.bind_unused_port()[1] + cls.configs['records.config']['CONFIG']['proxy.config.http.server_ports'] += ' {0}:ssl'.format(cls.ssl_port) + cls.configs['records.config']['CONFIG'].update({ + 'proxy.config.diags.debug.enabled': 1, + 'proxy.config.diags.debug.tags': 'url.*' + }) + + # test with a httpbin running on localhost and port 8000 + cls.configs['remap.config'].add_line('map https://www.example.com http://127.0.0.1:8000/\n'); + cls.configs['remap.config'].add_line('map https://www.example.com:4443 http://127.0.0.1:8000/\n'); + # configure SSL multicert + cls.configs['ssl_multicert.config'].add_line('dest_ip=* ssl_cert_name={0}'.format(helpers.tests_file_path('rsa_keys/www.example.com.pem'))) + + def test_remap_https(self): + s = requests.Session() + url = 'https://127.0.0.1:{0}/get'.format(self.ssl_port) + + # We lack of SNI support in requests module, so we do not verify SSL certificate here. + #ret = s.get(url, verify=(helpers.tests_file_path('certs/ca.crt'))) + ret = s.get(url, verify=False) + self.assertEqual(ret.status_code, 404) + + s.headers.update({'Host': 'www.example.com'}) + ret = s.get(url, verify=False) + self.assertEqual(ret.status_code, 200) + + s.headers.update({'Host': 'www.example.com:443'}) + ret = s.get(url) + self.assertEqual(ret.status_code, 200) + + s.headers.update({'Host': 'www.example.com:4443'}) + ret = s.get(url) + self.assertEqual(ret.status_code, 200) + + s.headers.update({'Host': 'www.test.com'}) + ret = s.get(url) + self.assertEqual(ret.status_code, 404) + + s.headers.update({'Host': 'www.example.com:1234'}) + ret = s.get(url) + self.assertEqual(ret.status_code, 404) + +if __name__ == '__main__': + unittest.main()
