示例#1
0
 def setUp(self):
     super(TestMultipleOrigin, self).setUp()
     self.test_domain = "{0}.{1}".format(
         base.random_string('test-multi-origin-'),
         self.dns_config.test_domain)
     self.service_name = base.random_string('E2E-MultiOrigin')
     self.cname_rec = []
示例#2
0
 def setUp(self):
     super(TestCacheInvalidation, self).setUp()
     self.test_domain = "{0}.{1}".format(
         base.random_string('test-invalidate-cache'),
         self.dns_config.test_domain)
     self.service_name = base.random_string('E2E-InvalidateCache')
     self.cname_rec = []
示例#3
0
    def setUp(self):
        super(TestReferrerRestriction, self).setUp()
        self.referree_domain = "{0}.{1}".format(base.random_string("referree"),
                                                self.test_domain)
        self.service_name = base.random_string("ReferrerRestrictionService")

        self.check_preconditions()
示例#4
0
 def setUp(self):
     super(TestCacheInvalidation, self).setUp()
     self.test_domain = "{0}.{1}".format(
         base.random_string('test-invalidate-cache'),
         self.dns_config.test_domain)
     self.service_name = base.random_string('E2E-InvalidateCache')
     self.cname_rec = []
示例#5
0
 def setUp(self):
     super(TestCaching, self).setUp()
     self.test_domain = "{0}.{1}".format(
         base.random_string('test-caching'),
         self.dns_config.test_domain)
     self.service_name = base.random_string('E2E-CachingService')
     self.cname_rec = []
 def setUp(self):
     super(TestMultipleOrigin, self).setUp()
     self.test_domain = "{0}.{1}".format(
         base.random_string('test-multi-origin-'),
         self.dns_config.test_domain)
     self.service_name = base.random_string('E2E-MultiOrigin')
     self.cname_rec = []
示例#7
0
 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 setUp(self):
        super(TestReferrerRestriction, self).setUp()
        self.referree_domain = "{0}.{1}".format(
            base.random_string("referree"), self.test_domain)
        self.service_name = base.random_string("ReferrerRestrictionService")

        self.check_preconditions()
示例#9
0
    def test_multiple_domains(self):

        # Create another domain in addition to the one created in setUp
        sub_domain2 = base.random_string(prefix='test-cdn-')
        self.test_domain2 = sub_domain2 + '.' + self.dns_config.test_domain

        print('Additional Domain Name', self.test_domain2)

        # Create a Poppy Service for the test website with two domains
        domain_list = [{"domain": self.test_domain},
                       {"domain": self.test_domain2}]
        origin_list = [{"origin": self.origin,
                        "port": 80,
                        "ssl": False}]
        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']
        access_url = [link['href'] for link in links if
                      link['rel'] == 'access_url']

        # Adds cname records corresponding to the test domains
        rec = self.setup_cname(name=self.test_domain, cname=access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        rec = self.setup_cname(name=self.test_domain2, cname=access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        origin_url = 'http://' + self.origin
        cdn_enabled_url1 = 'http://' + self.test_domain
        cdn_enabled_url2 = 'http://' + self.test_domain2

        self.assertSameContent(origin_url=origin_url,
                               cdn_url=cdn_enabled_url1)

        self.assertSameContent(origin_url=origin_url,
                               cdn_url=cdn_enabled_url2)

        if self.test_config.webpagetest_enabled:
            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)
示例#10
0
    def test_multiple_domains(self):

        # Create another domain in addition to the one created in setUp
        sub_domain2 = base.random_string(prefix='test-cdn-')
        self.test_domain2 = sub_domain2 + '.' + self.dns_config.test_domain

        # Create a Poppy Service for the test website with two domains
        domain_list = [{
            "domain": self.test_domain
        }, {
            "domain": self.test_domain2
        }]
        origin_list = [{"origin": self.origin, "port": 80, "ssl": False}]
        caching_list = []
        self.service_name = base.random_string(prefix='e2e-cdn-')

        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']
        access_url = [
            link['href'] for link in links if link['rel'] == 'access_url'
        ]

        # Adds cname records corresponding to the test domains
        rec = self.setup_cname(name=self.test_domain, cname=access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        rec = self.setup_cname(name=self.test_domain2, cname=access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        origin_url = 'http://' + self.origin
        cdn_enabled_url1 = 'http://' + self.test_domain
        cdn_enabled_url2 = 'http://' + self.test_domain2

        self.assertSameContent(origin_url=origin_url, cdn_url=cdn_enabled_url1)

        self.assertSameContent(origin_url=origin_url, cdn_url=cdn_enabled_url2)

        if self.test_config.webpagetest_enabled:
            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)
示例#11
0
    def test_ip_blacklist(self):
        test_domain = "{0}.{1}".format(
            base.random_string('test-blacklist-ip'),
            self.dns_config.test_domain)
        domains = [{'domain': 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": "/*"}]}]

        test_system_ip = self.get_ip_address()
        restrictions = [
            {"name": "test_ip_blacklist",
             "access": "blacklist",
             "rules": [{"name": "blacklist",
                        "client_ip": test_system_ip,
                        "request_url": "/*"}]}]

        resp = self.setup_service(
            service_name=self.service_name,
            domain_list=domains,
            origin_list=origins,
            caching_list=caching,
            restrictions_list=restrictions,
            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(test_domain, access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        # Verify blacklisted IP cannot fetch cdn content
        cdn_url = 'http://' + test_domain
        resp = self.http_client.get(url=cdn_url)
        self.assertEqual(resp.status_code, 403)
        self.assertIn('Access Denied', resp.content)

        # Verify wpt can fetch cdn content
        wpt_result = self.run_webpagetest(url=cdn_url)
        test_region = wpt_result.keys()[0]
        wpt_response_text = \
            wpt_result[
                test_region]['data']['runs']['1']['firstView']['requests'][
                0]['headers']['response'][0]
        self.assertIn(
            'HTTP/1.1 200', wpt_response_text)
示例#12
0
    def test_enable_cdn(self):

        # Create a Poppy Service for the test website
        domain_list = [{"domain": self.test_domain}]
        origin_list = [{"origin": self.origin, "port": 80, "ssl": False}]
        caching_list = []
        self.service_name = base.random_string(prefix='e2e-cdn-')

        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']
        access_url = [
            link['href'] for link in links if link['rel'] == 'access_url'
        ]

        rec = self.setup_cname(name=self.test_domain, cname=access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        origin_url = 'http://' + self.origin
        cdn_enabled_url = 'http://' + self.test_domain

        self.assertSameContent(origin_url=origin_url, cdn_url=cdn_enabled_url)

        if self.test_config.webpagetest_enabled:
            self.run_webpagetest(url=cdn_enabled_url)
示例#13
0
    def test_enable_cdn(self):

        # Create a Poppy Service for the test website
        domain_list = [{"domain": self.test_domain}]
        origin_list = [{"origin": self.origin,
                        "port": 80,
                        "ssl": False}]
        caching_list = []
        self.service_name = base.random_string(prefix='e2e-cdn-')

        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']
        access_url = [link['href'] for link in links if
                      link['rel'] == 'access_url']

        rec = self.setup_cname(name=self.test_domain, cname=access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        origin_url = 'http://' + self.origin
        cdn_enabled_url = 'http://' + self.test_domain

        self.assertSameContent(origin_url=origin_url, cdn_url=cdn_enabled_url)

        if self.test_config.webpagetest_enabled:
            self.run_webpagetest(url=cdn_enabled_url)
示例#14
0
    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='e2e-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.service_location = resp.headers['location']

        resp = self.poppy_client.get_service(location=self.service_location)
        links = resp.json()['links']
        origin_url = 'https://' + self.origin
        access_url = [link['href'] for link in links if
                      link['rel'] == 'access_url']
        cdn_url = 'https://' + access_url[0]

        time.sleep(self.dns_config.cdn_provider_dns_sleep)

        self.assertSameContent(origin_url=origin_url,
                               cdn_url=cdn_url)
示例#15
0
    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='e2e-ssl-')
        self.origin = self.test_config.ssl_origin
示例#16
0
    def setUp(self):
        super(TestWebsiteCDN, self).setUp()

        sub_domain = base.random_string(prefix='test-cdn-')
        self.test_domain = sub_domain + '.' + self.dns_config.test_domain

        self.origin = self.test_config.alternate_origin
        self.cname_rec = []
示例#17
0
    def setUp(self):
        super(TestWebsiteCDN, self).setUp()

        sub_domain = base.random_string(prefix='test-cdn-')
        self.test_domain = sub_domain + '.' + self.dns_config.test_domain

        self.origin = self.test_config.alternate_origin
        self.cname_rec = []
示例#18
0
    def setUp(self):
        super(TestWebsiteCDN, self).setUp()

        sub_domain = base.random_string(prefix='test-cdn-')
        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 = []
示例#19
0
    def test_purge(self):

        # Create a Poppy Service for the test website
        domain_list = [{"domain": self.test_domain}]
        origin_list = [{"origin": self.origin,
                        "port": 80,
                        "ssl": False}]

        rule1 = self.cacherules_config.cache_rule1
        ttlrule1 = self.cacherules_config.ttl_rule1

        caching_list = [{"name": "images", "ttl": ttlrule1, "rules":
                        [{"name": "image_rule", "request_url": rule1}]}]
        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']
        access_url = [link['href'] for link in links if
                      link['rel'] == 'access_url']

        # Adds cname records corresponding to the test domains
        rec = self.setup_cname(name=self.test_domain, cname=access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        origin_url = 'http://' + self.origin
        cdn_enabled_url = 'http://' + self.test_domain

        self.assertSameContent(origin_url=origin_url,
                               cdn_url=cdn_enabled_url)

        # Purge object in rule 1 and ensure it gets a TCP_MISS
        self.get_from_cdn_enabled_url(cdn_url=cdn_enabled_url + rule1, count=2)
        self.assertCacheStatus(cdn_url=cdn_enabled_url + rule1,
                               status_list=['TCP_HIT', 'TCP_MEM_HIT'])
        self.poppy_client.purge_asset(location=self.service_location,
                                      asset_url=rule1)

        # Wait for purge to complete & verify that content is fetched from
        # origin for subsequent call.
        # @todo: Change the sleep to check the real status of purge. As is
        # there is no way a poppy user can get the purge status.
        time.sleep(self.purge_config.purge_wait_time)
        self.assertCacheStatus(
            cdn_url=cdn_enabled_url + rule1,
            status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
    def setUp(self):
        super(TestGeoRestrictions, self).setUp()
        self.service_name = base.random_string('E2E-Geo-Restriction')
        self.cname_rec = []

        self.service_location = ''
示例#21
0
    def test_cache_rules(self):

        # Create a Poppy Service for the test website with cache rules
        domain_list = [{"domain": self.test_domain}]
        origin_list = [{"origin": self.origin,
                        "port": 80,
                        "ssl": False}]

        rule1 = self.cacherules_config.cache_rule1
        ttlrule1 = self.cacherules_config.ttl_rule1

        rule2 = self.cacherules_config.cache_rule2
        ttlrule2 = self.cacherules_config.ttl_rule2

        rule3 = self.cacherules_config.cache_rule3
        ttlrule3 = self.cacherules_config.ttl_rule3

        # Setup cache list using cache
        caching_list = [{"name": "images", "ttl": ttlrule1, "rules":
                        [{"name": "image_rule",
                          "request_url": rule1}]},
                        {"name": "images", "ttl": ttlrule2, "rules":
                        [{"name": "css_rule",
                          "request_url": rule2}]},
                        {"name": "images", "ttl": ttlrule3, "rules":
                        [{"name": "js_rule",
                          "request_url": rule3}]}]

        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']
        access_url = [link['href'] for link in links if
                      link['rel'] == 'access_url']

        # Adds cname records corresponding to the test domains
        rec = self.setup_cname(name=self.test_domain, cname=access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        origin_url = 'http://' + self.origin
        cdn_enabled_url = 'http://' + self.test_domain

        self.assertSameContent(origin_url=origin_url,
                               cdn_url=cdn_enabled_url)

        # Verify cdn hit on rule urls
        self.get_from_cdn_enabled_url(cdn_url=cdn_enabled_url + rule1, count=2)
        self.assertCacheStatus(cdn_url=cdn_enabled_url + rule1,
                               status_list=['TCP_HIT', 'TCP_MEM_HIT'])

        self.get_from_cdn_enabled_url(cdn_url=cdn_enabled_url + rule2, count=2)
        self.assertCacheStatus(cdn_url=cdn_enabled_url + rule2,
                               status_list=['TCP_HIT', 'TCP_MEM_HIT'])

        self.get_from_cdn_enabled_url(cdn_url=cdn_enabled_url + rule3, count=2)
        self.assertCacheStatus(cdn_url=cdn_enabled_url + rule3,
                               status_list=['TCP_HIT', 'TCP_MEM_HIT'])

        time.sleep(max(ttlrule1, ttlrule2, ttlrule3))
        # Verify that content in cache is stale/removed after the ttl expires
        self.assertCacheStatus(
            cdn_url=cdn_enabled_url + rule1,
            status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
        self.assertCacheStatus(
            cdn_url=cdn_enabled_url + rule2,
            status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
        self.assertCacheStatus(
            cdn_url=cdn_enabled_url + rule3,
            status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
示例#22
0
    def test_update_cache_rules(self):

        # Create a Poppy Service for the test website
        domain_list = [{"domain": self.test_domain}]
        origin_list = [{
            "origin": self.default_origin,
            "port": 80,
            "ssl": False
        }]

        jpg_ttl = self.caching_config.jpg_ttl

        caching_list = [{
            "name":
            "images",
            "ttl":
            jpg_ttl,
            "rules": [{
                "name": "image_rule",
                "request_url": self.jpg_path
            }]
        }]
        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']
        access_url = [
            link['href'] for link in links if link['rel'] == 'access_url'
        ]

        # Adds cname records corresponding to the test domains
        rec = self.setup_cname(name=self.test_domain, cname=access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        origin_jpg = 'http://' + self.default_origin + self.jpg_path

        cdn_url = 'http://' + self.test_domain
        cdn_jpg_url = cdn_url + self.jpg_path

        self.assertSameContent(origin_url=origin_jpg, cdn_url=cdn_jpg_url)

        # Verify that content is cached after two requests
        edge_server = self.get_from_cdn_enabled_url(cdn_url=cdn_jpg_url,
                                                    count=1)
        self.assertCacheStatus(cdn_url=cdn_jpg_url,
                               edge_server=edge_server,
                               status_list=['TCP_HIT', 'TCP_MEM_HIT'])

        # Verify that content in cache is stale/removed after the ttl expires
        time.sleep(jpg_ttl + 10)
        self.assertCacheStatus(
            cdn_url=cdn_jpg_url,
            edge_server=edge_server,
            status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])

        # Update cache rules
        new_ttl = 50
        test_data = [{
            "op": "replace",
            "path": "/caching/0",
            "value": {
                "name": "cache_name",
                "ttl": new_ttl,
                "rules": [{
                    "name": "image_rule",
                    "request_url": self.jpg_path
                }]
            }
        }]
        resp = self.poppy_client.patch_service(location=self.service_location,
                                               request_body=test_data)

        # Verify that content is cached after two requests
        edge_server = self.get_from_cdn_enabled_url(cdn_url=cdn_jpg_url,
                                                    count=1)
        self.assertCacheStatus(cdn_url=cdn_jpg_url,
                               edge_server=edge_server,
                               status_list=['TCP_HIT', 'TCP_MEM_HIT'])

        time.sleep(new_ttl)
        # Verify that content in cache is stale/removed after the ttl expires
        self.assertCacheStatus(
            cdn_url=cdn_jpg_url,
            edge_server=edge_server,
            status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
示例#23
0
    def test_update_cache_rules(self):

        # Create a Poppy Service for the test website
        domain_list = [{"domain": self.test_domain}]
        origin_list = [{
            "origin": self.default_origin, "port": 80, "ssl": False}]

        jpg_ttl = self.caching_config.jpg_ttl

        caching_list = [{
            "name": "images", "ttl": jpg_ttl,
            "rules":
                [{"name": "image_rule", "request_url": self.jpg_path}]}]
        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']
        access_url = [link['href'] for link in links if
                      link['rel'] == 'access_url']

        # Adds cname records corresponding to the test domains
        rec = self.setup_cname(name=self.test_domain, cname=access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        origin_jpg = 'http://' + self.default_origin + self.jpg_path

        cdn_url = 'http://' + self.test_domain
        cdn_jpg_url = cdn_url + self.jpg_path

        self.assertSameContent(
            origin_url=origin_jpg, cdn_url=cdn_jpg_url)

        # Verify that content is cached after two requests
        self.get_from_cdn_enabled_url(cdn_url=cdn_jpg_url, count=2)
        self.assertCacheStatus(cdn_url=cdn_jpg_url,
                               status_list=['TCP_HIT', 'TCP_MEM_HIT'])

        # Verify that content in cache is stale/removed after the ttl expires
        time.sleep(jpg_ttl + 10)
        self.assertCacheStatus(
            cdn_url=cdn_jpg_url,
            status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])

        # Update cache rules
        new_ttl = 50
        test_data = [{
            "op": "replace",
            "path": "/caching/0",
            "value": {
                "name": "cache_name",
                "ttl": new_ttl,
                "rules": [{"name": "image_rule",
                           "request_url": self.jpg_path}]}
        }]
        resp = self.poppy_client.patch_service(location=self.service_location,
                                               request_body=test_data)

        # Verify that content is cached after two requests
        self.get_from_cdn_enabled_url(cdn_url=cdn_jpg_url, count=2)
        self.assertCacheStatus(cdn_url=cdn_jpg_url,
                               status_list=['TCP_HIT', 'TCP_MEM_HIT'])

        time.sleep(new_ttl)
        # Verify that content in cache is stale/removed after the ttl expires
        self.assertCacheStatus(
            cdn_url=cdn_jpg_url,
            status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
示例#24
0
    def test_cache_rules(self):

        # Create a Poppy Service for the test website with cache rules
        domain_list = [{"domain": self.test_domain}]
        origin_list = [{"origin": self.default_origin,
                        "port": 80,
                        "ssl": False}]

        jpg_ttl = self.caching_config.jpg_ttl
        txt_ttl = self.caching_config.txt_ttl
        zip_ttl = self.caching_config.zip_ttl

        # Setup cache list using cache
        caching_list = [
            {"name": "jpg", "ttl": jpg_ttl,
             "rules": [{"name": "jpg_rule", "request_url": self.jpg_path}]},
            {"name": "txt", "ttl": txt_ttl,
             "rules": [{"name": "txt_rule", "request_url": self.txt_path}]},
            {"name": "zip", "ttl": zip_ttl,
             "rules": [{"name": "zip_rule", "request_url": self.zip_path}]}]

        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']
        access_url = [link['href'] for link in links if
                      link['rel'] == 'access_url']

        # Adds cname records corresponding to the test domains
        rec = self.setup_cname(name=self.test_domain, cname=access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        origin_url = 'http://' + self.default_origin
        cdn_url = 'http://' + self.test_domain

        self.assertSameContent(origin_url=origin_url, cdn_url=cdn_url)

        # Verify cdn hit on rule urls
        cdn_jpg_url = cdn_url + self.jpg_path
        self.get_from_cdn_enabled_url(cdn_url=cdn_jpg_url, count=2)
        self.assertCacheStatus(cdn_url=cdn_jpg_url,
                               status_list=['TCP_HIT', 'TCP_MEM_HIT'])

        cdn_txt_url = cdn_url + self.txt_path
        self.get_from_cdn_enabled_url(cdn_url=cdn_txt_url, count=2)
        self.assertCacheStatus(cdn_url=cdn_txt_url,
                               status_list=['TCP_HIT', 'TCP_MEM_HIT'])

        cdn_zip_url = cdn_url + self.zip_path
        self.get_from_cdn_enabled_url(cdn_url=cdn_zip_url, count=2)
        self.assertCacheStatus(cdn_url=cdn_zip_url,
                               status_list=['TCP_HIT', 'TCP_MEM_HIT'])

        time.sleep(max(jpg_ttl, zip_ttl, txt_ttl))
        # Verify that content in cache is stale/removed after the ttl expires
        self.assertCacheStatus(
            cdn_url=cdn_jpg_url,
            status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
        self.assertCacheStatus(
            cdn_url=cdn_txt_url,
            status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
        self.assertCacheStatus(
            cdn_url=cdn_zip_url,
            status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
示例#25
0
    def test_ip_blacklist(self):
        test_domain = "{0}.{1}".format(
            base.random_string('test-blacklist-ip'),
            self.dns_config.test_domain)
        domains = [{'domain': 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": "/*"}]}]

        test_system_ipv4 = self.get_ipv4_address()
        test_system_ipv6 = self.get_ipv6_address()
        restrictions = [
            {"name": "test_ip_blacklist",
             "access": "blacklist",
             "rules": [
                 {"name": "blacklist",
                  "client_ip": test_system_ipv4,
                  "request_url": "/*"},
                 {"name": "blacklist",
                  "client_ip": test_system_ipv6,
                  "request_url": "/*"}]}]

        resp = self.setup_service(
            service_name=self.service_name,
            domain_list=domains,
            origin_list=origins,
            caching_list=caching,
            restrictions_list=restrictions,
            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(test_domain, access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        # Verify blacklisted IP cannot fetch cdn content
        cdn_url = 'http://' + test_domain
        resp = self.http_client.get(url=cdn_url)
        self.assertEqual(resp.status_code, 403)
        self.assertIn('Access Denied', resp.content)

        # Verify wpt can fetch cdn content
        wpt_result = self.run_webpagetest(url=cdn_url)
        test_region = wpt_result.keys()[0]
        wpt_response_text = \
            wpt_result[
                test_region]['data']['runs']['1']['firstView']['requests'][
                0]['headers']['response'][0]
        self.assertIn(
            'HTTP/1.1 200', wpt_response_text)
示例#26
0
 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 = []
示例#27
0
 def setUp(self):
     super(TestPurge, self).setUp()
     self.test_domain = "{0}.{1}".format(base.random_string('test-purge'),
                                         self.dns_config.test_domain)
     self.service_name = base.random_string('E2E-PurgeService')
     self.cname_rec = []
示例#28
0
    def test_ip_cidr_whitelist(self):
        test_domain = "{0}.{1}".format(
            base.random_string('test-whitelist-ip'),
            self.dns_config.test_domain)
        domains = [{'domain': 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": "/*"}]}]

        test_system_ipv4_cidr = self.get_ipv4_address() + '/15'
        test_system_ipv6_cidr = self.get_ipv6_address() + '/42'

        restrictions = [
            {"name": "test_ip_whitelist",
             "access": "whitelist",
             "rules": [
                 {"name": "whitelist",
                  "client_ip": test_system_ipv4_cidr,
                  "request_url": "/*"},
                 {"name": "whitelist",
                  "client_ip": test_system_ipv6_cidr,
                  "request_url": "/*"}]}]
        resp = self.setup_service(
            service_name=self.service_name,
            domain_list=domains,
            origin_list=origins,
            caching_list=caching,
            restrictions_list=restrictions,
            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(test_domain, access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        # Verify whitelisted IP range can fetch cdn content
        cdn_url = 'http://' + test_domain
        resp = self.http_client.get(url=cdn_url)
        self.assertEqual(resp.status_code, 200)
        self.assertIn('Test Flask Site', resp.content)

        # Verify wpt cannot fetch cdn content.
        # wpt accesses from a different country, which will not fall within
        # the whitelisted IP CIDR.
        wpt_result = self.run_webpagetest(url=cdn_url)
        test_region = wpt_result.keys()[0]
        wpt_response_text = \
            wpt_result[
                test_region]['data']['runs']['1']['firstView']['requests'][
                0]['headers']['response'][0]
        self.assertIn(
            'HTTP/1.1 403 Forbidden', wpt_response_text)
示例#29
0
    def test_cache_rules(self):

        # Create a Poppy Service for the test website with cache rules
        domain_list = [{"domain": self.test_domain}]
        origin_list = [{
            "origin": self.default_origin,
            "port": 80,
            "ssl": False
        }]

        jpg_ttl = self.caching_config.jpg_ttl
        txt_ttl = self.caching_config.txt_ttl
        zip_ttl = self.caching_config.zip_ttl

        # Setup cache list using cache
        caching_list = [{
            "name":
            "jpg",
            "ttl":
            jpg_ttl,
            "rules": [{
                "name": "jpg_rule",
                "request_url": self.jpg_path
            }]
        }, {
            "name":
            "txt",
            "ttl":
            txt_ttl,
            "rules": [{
                "name": "txt_rule",
                "request_url": self.txt_path
            }]
        }, {
            "name":
            "zip",
            "ttl":
            zip_ttl,
            "rules": [{
                "name": "zip_rule",
                "request_url": self.zip_path
            }]
        }]

        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']
        access_url = [
            link['href'] for link in links if link['rel'] == 'access_url'
        ]

        # Adds cname records corresponding to the test domains
        rec = self.setup_cname(name=self.test_domain, cname=access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        origin_url = 'http://' + self.default_origin
        cdn_url = 'http://' + self.test_domain

        self.assertSameContent(origin_url=origin_url, cdn_url=cdn_url)

        # Verify cdn hit on rule urls
        cdn_jpg_url = cdn_url + self.jpg_path
        edge_server = self.get_from_cdn_enabled_url(cdn_url=cdn_jpg_url,
                                                    count=1)
        self.assertCacheStatus(cdn_url=cdn_jpg_url,
                               edge_server=edge_server,
                               status_list=['TCP_HIT', 'TCP_MEM_HIT'])

        cdn_txt_url = cdn_url + self.txt_path
        edge_server = self.get_from_cdn_enabled_url(cdn_url=cdn_txt_url,
                                                    count=1)
        self.assertCacheStatus(cdn_url=cdn_txt_url,
                               edge_server=edge_server,
                               status_list=['TCP_HIT', 'TCP_MEM_HIT'])

        cdn_zip_url = cdn_url + self.zip_path
        edge_server = self.get_from_cdn_enabled_url(cdn_url=cdn_zip_url,
                                                    count=1)
        self.assertCacheStatus(cdn_url=cdn_zip_url,
                               edge_server=edge_server,
                               status_list=['TCP_HIT', 'TCP_MEM_HIT'])

        time.sleep(max(jpg_ttl, zip_ttl, txt_ttl))
        # Verify that content in cache is stale/removed after the ttl expires
        self.assertCacheStatus(
            cdn_url=cdn_jpg_url,
            edge_server=edge_server,
            status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
        self.assertCacheStatus(
            cdn_url=cdn_txt_url,
            edge_server=edge_server,
            status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
        self.assertCacheStatus(
            cdn_url=cdn_zip_url,
            edge_server=edge_server,
            status_list=['TCP_REFRESH_HIT', 'TCP_REFRESH_MISS', 'TCP_MISS'])
示例#30
0
    def setUp(self):
        super(TestIpRestrictions, self).setUp()
        self.service_name = base.random_string('E2E-IP-Restriction')
        self.cname_rec = []

        self.service_location = ''
示例#31
0
    def test_update_cache_rules(self):

        # Create a Poppy Service for the test website
        domain_list = [{"domain": self.test_domain}]
        origin_list = [{"origin": self.origin, "port": 80, "ssl": False}]

        rule1 = self.cacherules_config.cache_rule1
        ttlrule1 = self.cacherules_config.ttl_rule1

        caching_list = [{"name": "images", "ttl": ttlrule1, "rules": [{"name": "image_rule", "request_url": rule1}]}]
        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"]
        access_url = [link["href"] for link in links if link["rel"] == "access_url"]

        # Adds cname records corresponding to the test domains
        rec = self.setup_cname(name=self.test_domain, cname=access_url[0])
        if rec:
            self.cname_rec.append(rec[0])

        origin_url = "http://" + self.origin
        cdn_enabled_url = "http://" + self.test_domain

        self.assertSameContent(origin_url=origin_url, cdn_url=cdn_enabled_url)

        # Verify that content is cached after two requests
        self.get_from_cdn_enabled_url(cdn_url=cdn_enabled_url + rule1, count=2)
        self.assertCacheStatus(cdn_url=cdn_enabled_url + rule1, status_list=["TCP_HIT", "TCP_MEM_HIT"])

        # Verify that content in cache is stale/removed after the ttl expires
        time.sleep(ttlrule1 + 10)
        self.assertCacheStatus(
            cdn_url=cdn_enabled_url + rule1, status_list=["TCP_REFRESH_HIT", "TCP_REFRESH_MISS", "TCP_MISS"]
        )

        # Update cache rules
        new_ttl = 50
        test_data = [
            {
                "op": "replace",
                "path": "/caching/0",
                "value": {
                    "name": "cache_name",
                    "ttl": new_ttl,
                    "rules": [{"name": "image_rule", "request_url": rule1}],
                },
            }
        ]
        resp = self.poppy_client.patch_service(location=self.service_location, request_body=test_data)

        # Verify that content is cached after two requests
        self.get_from_cdn_enabled_url(cdn_url=cdn_enabled_url + rule1, count=2)
        self.assertCacheStatus(cdn_url=cdn_enabled_url + rule1, status_list=["TCP_HIT", "TCP_MEM_HIT"])

        time.sleep(new_ttl)
        # Verify that content in cache is stale/removed after the ttl expires
        self.assertCacheStatus(
            cdn_url=cdn_enabled_url + rule1, status_list=["TCP_REFRESH_HIT", "TCP_REFRESH_MISS", "TCP_MISS"]
        )