blob: 41430c89f0c4b3de61e26c869d117c2ecd5b384e [file] [log] [blame]
Joe H. Rahme836da3f2013-10-09 15:47:16 +02001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
4#
5# Author: Joe H. Rahme <joe.hakim.rahme@enovance.com>
6#
7# Licensed under the Apache License, Version 2.0 (the "License"); you may
8# not use this file except in compliance with the License. You may obtain
9# a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16# License for the specific language governing permissions and limitations
17# under the License.
18
19from tempest.api.object_storage import base
20from tempest import clients
Daisuke Moritad206d3b2013-12-06 15:18:04 +090021from tempest.common import custom_matchers
Joe H. Rahme836da3f2013-10-09 15:47:16 +020022from tempest import config
23from tempest.test import attr
24from tempest.test import HTTP_SUCCESS
25
Sean Dague86bd8422013-12-20 09:56:44 -050026CONF = config.CONF
27
Joe H. Rahme836da3f2013-10-09 15:47:16 +020028
29class CrossdomainTest(base.BaseObjectTest):
30 crossdomain_available = \
Sean Dague86bd8422013-12-20 09:56:44 -050031 CONF.object_storage_feature_enabled.crossdomain
Joe H. Rahme836da3f2013-10-09 15:47:16 +020032
33 @classmethod
34 def setUpClass(cls):
35 super(CrossdomainTest, cls).setUpClass()
36
37 # skip this test if CORS isn't enabled in the conf file.
38 if not cls.crossdomain_available:
39 skip_msg = ("%s skipped as Crossdomain middleware not available"
40 % cls.__name__)
41 raise cls.skipException(skip_msg)
42
43 # creates a test user. The test user will set its base_url to the Swift
44 # endpoint and test the healthcheck feature.
45 cls.data.setup_test_user()
46
47 cls.os_test_user = clients.Manager(
48 cls.data.test_user,
49 cls.data.test_password,
50 cls.data.test_tenant)
51
52 cls.xml_start = '<?xml version="1.0"?>\n' \
53 '<!DOCTYPE cross-domain-policy SYSTEM ' \
54 '"http://www.adobe.com/xml/dtds/cross-domain-policy.' \
55 'dtd" >\n<cross-domain-policy>\n'
56
57 cls.xml_end = "</cross-domain-policy>"
58
59 @classmethod
60 def tearDownClass(cls):
61 cls.data.teardown_all()
62 super(CrossdomainTest, cls).tearDownClass()
63
64 def setUp(self):
65 super(CrossdomainTest, self).setUp()
66
67 client = self.os_test_user.account_client
68 client._set_auth()
69 # Turning http://.../v1/foobar into http://.../
70 client.base_url = "/".join(client.base_url.split("/")[:-2])
71
72 def tearDown(self):
73 # clear the base_url for subsequent requests
74 self.os_test_user.account_client.base_url = None
75
76 super(CrossdomainTest, self).tearDown()
77
78 @attr('gate')
79 def test_get_crossdomain_policy(self):
80 resp, body = self.os_test_user.account_client.get("crossdomain.xml",
81 {})
82
83 self.assertIn(int(resp['status']), HTTP_SUCCESS)
84 self.assertTrue(body.startswith(self.xml_start) and
85 body.endswith(self.xml_end))
Daisuke Moritad206d3b2013-12-06 15:18:04 +090086
87 # The target of the request is not any Swift resource. Therefore, the
88 # existence of response header is checked without a custom matcher.
89 self.assertIn('content-length', resp)
90 self.assertIn('content-type', resp)
91 self.assertIn('x-trans-id', resp)
92 self.assertIn('date', resp)
93 # Check only the format of common headers with custom matcher
94 self.assertThat(resp, custom_matchers.AreAllWellFormatted())