Adds end to end tests for host header validation

This patch adds the end to end tests needed to verify custom,
origin & default host headers.

Change-Id: I747e2f8426ee76222d36cf70a68089096b90ae61
This commit is contained in:
Malini Kamalambal
2015-07-20 12:46:08 -04:00
parent 054a366864
commit a83bd0e2b8
3 changed files with 183 additions and 0 deletions

View File

@@ -0,0 +1,166 @@
# Copyright (c) 2015 Rackspace, Inc.
#
# Licensed 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.
from tests.endtoend import base
from tests.endtoend.utils import config
class TestHostHeaders(base.TestBase):
@classmethod
def setUpClass(cls):
super(TestHostHeaders, cls).setUpClass()
cls.host_header_config = config.HostHeaderConfig()
cls.default_origin = cls.host_header_config.origin
cls.test_endpoint = cls.host_header_config.endpoint
cls.check_preconditions()
@classmethod
def check_preconditions(cls):
"""Ensure our environment meets our needs to ensure a valid test."""
origin = cls.http_client.get(
"http://" + cls.default_origin + cls.test_endpoint)
assert origin.status_code == 200
def setUp(self):
super(TestHostHeaders, self).setUp()
self.test_domain = "{0}.{1}".format(
base.random_string('test-hostheader'),
self.dns_config.test_domain)
self.service_name = base.random_string('HostHeaderService')
self.cname_rec = []
def test_origin_host_header(self):
domains = [{'domain': self.test_domain}]
origins = [{
"origin": self.default_origin,
"port": 80,
"ssl": False,
"rules": [{
"name": "default",
"request_url": "/*",
}],
"hostheadertype": "origin"
}]
caching = [
{"name": "default",
"ttl": 3600,
"rules": [{"name": "default", "request_url": "/*"}]}]
resp = self.setup_service(
service_name=self.service_name,
domain_list=domains,
origin_list=origins,
caching_list=caching,
flavor_id=self.poppy_config.flavor)
self.service_location = resp.headers['location']
resp = self.poppy_client.get_service(location=self.service_location)
links = resp.json()['links']
access_url = [link['href'] for link in links if
link['rel'] == 'access_url']
rec = self.setup_cname(self.test_domain, access_url[0])
if rec:
self.cname_rec.append(rec[0])
cdn_url = 'http://' + self.test_domain
resp = self.http_client.get(url=cdn_url + self.test_endpoint)
self.assertIn(self.default_origin, resp.content)
def test_custom_host_header(self):
domains = [{'domain': self.test_domain}]
host_header_value = 'llama-llama-red-pajama.com'
origins = [{
"origin": self.default_origin,
"port": 80,
"ssl": False,
"rules": [{
"name": "default",
"request_url": "/*",
}],
"hostheadertype": "custom",
"hostheadervalue": host_header_value
}]
caching = [
{"name": "default",
"ttl": 3600,
"rules": [{"name": "default", "request_url": "/*"}]}]
resp = self.setup_service(
service_name=self.service_name,
domain_list=domains,
origin_list=origins,
caching_list=caching,
flavor_id=self.poppy_config.flavor)
self.service_location = resp.headers['location']
resp = self.poppy_client.get_service(location=self.service_location)
links = resp.json()['links']
access_url = [link['href'] for link in links if
link['rel'] == 'access_url']
rec = self.setup_cname(self.test_domain, access_url[0])
if rec:
self.cname_rec.append(rec[0])
cdn_url = 'http://' + self.test_domain
url = cdn_url + self.test_endpoint
resp = self.http_client.get(url=url)
self.assertIn(host_header_value, resp.content)
def test_default_host_header(self):
domains = [{'domain': self.test_domain}]
origins = [{
"origin": self.default_origin,
"port": 80,
"ssl": False,
"rules": [{
"name": "default",
"request_url": "/*",
}]
}]
caching = [
{"name": "default",
"ttl": 3600,
"rules": [{"name": "default", "request_url": "/*"}]}]
resp = self.setup_service(
service_name=self.service_name,
domain_list=domains,
origin_list=origins,
caching_list=caching,
flavor_id=self.poppy_config.flavor)
self.service_location = resp.headers['location']
resp = self.poppy_client.get_service(location=self.service_location)
links = resp.json()['links']
access_url = [link['href'] for link in links if
link['rel'] == 'access_url']
rec = self.setup_cname(self.test_domain, access_url[0])
if rec:
self.cname_rec.append(rec[0])
cdn_url = 'http://' + self.test_domain
url = cdn_url + self.test_endpoint
resp = self.http_client.get(url=url)
self.assertIn(self.test_domain, resp.content)
def tearDown(self):
self.poppy_client.delete_service(location=self.service_location)
for record in self.cname_rec:
self.dns_client.delete_record(record)
super(TestHostHeaders, self).tearDown()

View File

@@ -234,6 +234,19 @@ class MultipleOriginConfig(data_interfaces.ConfigSectionInterface):
return self.get('image_path')
class HostHeaderConfig(data_interfaces.ConfigSectionInterface):
"""Configuration for testing multiple origins."""
SECTION_NAME = 'host_header'
@property
def origin(self):
return self.get('origin')
@property
def endpoint(self):
return self.get('endpoint')
class PurgeRulesConfig(data_interfaces.ConfigSectionInterface):
"""Configuration for purge wait time."""
SECTION_NAME = 'purgetime'

View File

@@ -15,6 +15,10 @@ webpagetest_enabled=False
referree_origin=2.3.4.5
referrer_request_url=/static/images/gorilla.jpeg
[host_header]
origin=1.3.5.7
endpoint=/test/host_header
[multiple_origin]
default_origin=127.0.0.1
images_origin=127.0.0.2