End to End tests for shared cert SSL.

This patch adds the end to end test for shared SSL. The patch also
refactors some of the existing tests to DRY up the code.

Change-Id: Ie5aee2eebf791a41cf77d41899150375f8c1b8b0
This commit is contained in:
Malini Kamalambal
2015-03-06 11:42:35 -05:00
parent 61ff482d66
commit ebe706498a
7 changed files with 139 additions and 72 deletions

View File

@@ -13,9 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import random
from bs4 import BeautifulSoup
from cafe.drivers.unittest import fixtures
import random
import requests
from tests.api.utils import client
@@ -102,11 +103,12 @@ class TestBase(fixtures.BaseTestFixture):
def setup_cname(self, name, cname):
"""Create a CNAME record and wait for propagation."""
self.cname_rec = self.dns_client.add_cname_rec(name=name, data=cname)
cname_rec = self.dns_client.add_cname_rec(name=name, data=cname)
self.dns_client.wait_cname_propagation(
target=name,
retry_interval=self.dns_config.retry_interval)
return cname_rec
def setup_service(self, service_name, domain_list, origin_list,
caching_list, flavor_id):
@@ -128,6 +130,24 @@ class TestBase(fixtures.BaseTestFixture):
return resp
def run_webpagetest(self, url):
"""Runs webpagetest
:param url: URL to gather metrics on
:returns: test_result_location
"""
wpt_test_results = {}
for location in self.wpt_config.test_locations:
wpt_test_url = self.wpt_client.start_test(test_url=url,
test_location=location,
runs=2)
wpt_test_results[location] = wpt_test_url
self.wpt_client.wait_for_test_status(status='COMPLETE',
test_url=wpt_test_url)
wpt_test_results[location] = self.wpt_client.get_test_details(
test_url=wpt_test_url)
return wpt_test_results
@classmethod
def tearDownClass(cls):
"""Deletes the added resources."""

View File

@@ -1,6 +1,6 @@
# coding= utf-8
# Copyright (c) 2014 Rackspace, Inc.
# 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.
@@ -15,9 +15,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import random
import string
from tests.endtoend import base
@@ -25,19 +22,16 @@ class TestWebsiteCDN(base.TestBase):
"""Tests for CDN enabling a website."""
def _random_string(self, length=12):
return ''.join([random.choice(string.ascii_letters)
for _ in range(length)])
def setUp(self):
super(TestWebsiteCDN, self).setUp()
sub_domain = 'TestCDN-' + self._random_string()
sub_domain = base.random_string(prefix='TestCDN-')
self.test_domain = sub_domain + '.' + self.dns_config.test_domain
print('Domain Name', self.test_domain)
self.origin = self.test_config.wordpress_origin
self.cname_rec = []
def test_enable_cdn(self):
@@ -47,47 +41,38 @@ class TestWebsiteCDN(base.TestBase):
"port": 80,
"ssl": False}]
caching_list = []
self.service_name = 'testService-' + self._random_string()
self.service_name = base.random_string(prefix='testService-')
resp = self.poppy_client.create_service(
resp = self.setup_service(
service_name=self.service_name,
domain_list=domain_list,
origin_list=origin_list,
caching_list=caching_list,
flavor_id=self.poppy_config.flavor)
self.assertEqual(resp.status_code, 202)
self.service_location = resp.headers['location']
self.poppy_client.wait_for_service_status(
location=self.service_location,
status='DEPLOYED',
abort_on_status='FAILED',
retry_interval=self.poppy_config.status_check_retry_interval,
retry_timeout=self.poppy_config.status_check_retry_timeout)
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']
self.cname_rec = self.dns_client.add_cname_rec(
name=self.test_domain, data=access_url[0])
rec = self.setup_cname(name=self.test_domain, cname=access_url[0])
self.cname_rec.append(rec)
origin_url = 'http://' + self.origin
cdn_enabled_url = 'http://' + self.test_domain
self.dns_client.wait_cname_propagation(
target=self.test_domain,
retry_interval=self.dns_config.retry_interval)
self.assertSameContent(origin_url=origin_url,
cdn_url=cdn_enabled_url)
self._test_webpage(cdn_url=cdn_enabled_url)
if self.test_config.webpagetest_enabled:
self.run_webpagetest(url=cdn_enabled_url)
def test_multiple_domains(self):
# Create another domain in addition to the one created in setUp
sub_domain2 = 'TestCDN-' + self._random_string()
sub_domain2 = base.random_string(prefix='TestCDN-')
self.test_domain2 = sub_domain2 + '.' + self.dns_config.test_domain
print('Additional Domain Name', self.test_domain2)
@@ -99,76 +84,50 @@ class TestWebsiteCDN(base.TestBase):
"port": 80,
"ssl": False}]
caching_list = []
self.service_name = 'testService-' + self._random_string()
self.service_name = base.random_string(prefix='testService-')
resp = self.poppy_client.create_service(
resp = self.setup_service(
service_name=self.service_name,
domain_list=domain_list,
origin_list=origin_list,
caching_list=caching_list,
flavor_id=self.poppy_config.flavor)
self.assertEqual(resp.status_code, 202)
self.service_location = resp.headers['location']
self.poppy_client.wait_for_service_status(
location=self.service_location,
status='DEPLOYED',
abort_on_status='FAILED',
retry_interval=self.poppy_config.status_check_retry_interval,
retry_timeout=self.poppy_config.status_check_retry_timeout)
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']
# Add a cname to the first domain
self.cname_rec = self.dns_client.add_cname_rec(
name=self.test_domain, data=access_url[0])
# Adds cname records corresponding to the test domains
rec = self.setup_cname(name=self.test_domain, cname=access_url[0])
self.cname_rec.append(rec)
# Add a cname to the second domain
self.cname_rec = self.dns_client.add_cname_rec(
name=self.test_domain2, data=access_url[0])
rec = self.setup_cname(name=self.test_domain2, cname=access_url[0])
self.cname_rec.append(rec)
origin_url = 'http://' + self.origin
cdn_enabled_url1 = 'http://' + self.test_domain
cdn_enabled_url2 = 'http://' + self.test_domain2
self.dns_client.wait_cname_propagation(
target=self.test_domain,
retry_interval=self.dns_config.retry_interval)
self.dns_client.wait_cname_propagation(
target=self.test_domain2,
retry_interval=self.dns_config.retry_interval)
self.assertSameContent(origin_url=origin_url,
cdn_url=cdn_enabled_url1)
self.assertSameContent(origin_url=origin_url,
cdn_url=cdn_enabled_url2)
self._test_webpage(cdn_url=cdn_enabled_url1)
self._test_webpage(cdn_url=cdn_enabled_url2)
def _test_webpage(self, cdn_url):
# Benchmark page load metrics for the CDN enabled website
if self.test_config.webpagetest_enabled:
wpt_test_results = {}
for location in self.wpt_config.test_locations:
wpt_test_url = self.wpt_client.start_test(
test_url=cdn_url, test_location=location, runs=2)
wpt_test_results[location] = wpt_test_url
self.wpt_client.wait_for_test_status(
status='COMPLETE', test_url=wpt_test_url)
wpt_test_results[location] = self.wpt_client.get_test_details(
test_url=wpt_test_url)
print('Webpage Tests Results', wpt_test_url)
wpt_result_1 = self.run_webpagetest(url=cdn_enabled_url1)
wpt_result_2 = self.run_webpagetest(url=cdn_enabled_url2)
print(wpt_result_1)
print(wpt_result_2)
def tearDown(self):
self.poppy_client.delete_service(location=self.service_location)
# self.dns_client.delete_record(self.cname_rec)
"""
@todo(malini): Fix Bug in Delete below
for record in self.cname_rec:
self.dns_client.delete_record(record)
"""
super(TestWebsiteCDN, self).tearDown()

View File

@@ -54,6 +54,7 @@ class TestMultipleOrigin(base.TestBase):
self.test_domain = "{0}.{1}".format(
base.random_string('TestMultiOrigin'), self.dns_config.test_domain)
self.service_name = base.random_string('MultiOriginService')
self.cname_rec = []
def test_multiple_origin_default_first(self):
domains = [{'domain': self.test_domain}]
@@ -87,7 +88,8 @@ class TestMultipleOrigin(base.TestBase):
access_url = [link['href'] for link in links if
link['rel'] == 'access_url']
self.setup_cname(self.test_domain, access_url[0])
rec = self.setup_cname(self.test_domain, access_url[0])
self.cname_rec.append(rec)
# Check that the CDN provider is grabbing other content from the
# default origin, not the images origin
@@ -137,7 +139,8 @@ class TestMultipleOrigin(base.TestBase):
access_url = [link['href'] for link in links if
link['rel'] == 'access_url']
self.setup_cname(self.test_domain, access_url[0])
rec = self.setup_cname(self.test_domain, access_url[0])
self.cname_rec.append(rec)
# Everything should match the /* rule under the default origin,
# since it's the last rule in the list
@@ -154,6 +157,9 @@ class TestMultipleOrigin(base.TestBase):
def tearDown(self):
self.poppy_client.delete_service(location=self.service_location)
"""
@todo(malini): Fix Bug in Delete below
for record in self.cname_rec:
self.dns_client.delete_record(record)
"""
super(TestMultipleOrigin, self).tearDown()

View File

@@ -0,0 +1,69 @@
# coding= utf-8
# 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
class TestSSLCDN(base.TestBase):
"""Tests for CDN enabling with SSL on."""
def setUp(self):
super(TestSSLCDN, self).setUp()
if self.test_config.run_ssl_tests is False:
self.skipTest('SSL tests are currently disabled in configuration')
self.test_domain = base.random_string(prefix='TestCDN-SSL')
self.origin = self.test_config.ssl_origin
def test_shared_ssl_enable_cdn(self):
# Create a Poppy Service for the test website
domain_list = [{"domain": self.test_domain, "protocol": "https",
"certificate": "shared"}]
origin_list = [{"origin": self.origin, "port": 443, "ssl": True}]
caching_list = []
self.service_name = base.random_string(prefix='testService-')
resp = self.setup_service(
service_name=self.service_name,
domain_list=domain_list,
origin_list=origin_list,
caching_list=caching_list,
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']
origin_url = 'http://' + self.origin
access_url = [link['href'] for link in links if
link['rel'] == 'access_url']
cdn_url = 'https://' + access_url[0]
self.assertSameContent(origin_url=origin_url,
cdn_url=cdn_url)
# Benchmark page load metrics for the CDN enabled website
if self.test_config.webpagetest_enabled:
wpt_test_results = self.run_webpagetest(url=cdn_url)
print(wpt_test_results)
def tearDown(self):
self.poppy_client.delete_service(location=self.service_location)
super(TestSSLCDN, self).tearDown()

View File

@@ -55,6 +55,16 @@ class TestConfig(data_interfaces.ConfigSectionInterface):
"""IP address for wordpress origin."""
return self.get('wordpress_origin')
@property
def ssl_origin(self):
"""IP address for ssl origin."""
return self.get('ssl_origin')
@property
def run_ssl_tests(self):
"""Flag to indicate if ssl tests should be run."""
return self.get_boolean('run_ssl_tests')
@property
def webpagetest_enabled(self):
"""Flag to indicate if webpagetest tests should be run."""

View File

@@ -9,6 +9,8 @@ base_url=https://identity.api.rackspacecloud.com/v2.0
[test_configuration]
wordpress_origin=1.2.3.4
ssl_origin=1.2.3.4
run_ssl_tests=False
webpagetest_enabled=False
[multiple_origin]

View File

@@ -1,5 +1,6 @@
coverage
ddt
dnspython
fixtures
hacking
mock