blob: 51ecd16b79709e55d546452b6f1c579aebd959d3 [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
26
27class CrossdomainTest(base.BaseObjectTest):
28 crossdomain_available = \
29 config.TempestConfig().object_storage_feature_enabled.crossdomain
30
31 @classmethod
32 def setUpClass(cls):
33 super(CrossdomainTest, cls).setUpClass()
34
35 # skip this test if CORS isn't enabled in the conf file.
36 if not cls.crossdomain_available:
37 skip_msg = ("%s skipped as Crossdomain middleware not available"
38 % cls.__name__)
39 raise cls.skipException(skip_msg)
40
41 # creates a test user. The test user will set its base_url to the Swift
42 # endpoint and test the healthcheck feature.
43 cls.data.setup_test_user()
44
45 cls.os_test_user = clients.Manager(
46 cls.data.test_user,
47 cls.data.test_password,
48 cls.data.test_tenant)
49
50 cls.xml_start = '<?xml version="1.0"?>\n' \
51 '<!DOCTYPE cross-domain-policy SYSTEM ' \
52 '"http://www.adobe.com/xml/dtds/cross-domain-policy.' \
53 'dtd" >\n<cross-domain-policy>\n'
54
55 cls.xml_end = "</cross-domain-policy>"
56
57 @classmethod
58 def tearDownClass(cls):
59 cls.data.teardown_all()
60 super(CrossdomainTest, cls).tearDownClass()
61
62 def setUp(self):
63 super(CrossdomainTest, self).setUp()
64
65 client = self.os_test_user.account_client
66 client._set_auth()
67 # Turning http://.../v1/foobar into http://.../
68 client.base_url = "/".join(client.base_url.split("/")[:-2])
69
70 def tearDown(self):
71 # clear the base_url for subsequent requests
72 self.os_test_user.account_client.base_url = None
73
74 super(CrossdomainTest, self).tearDown()
75
76 @attr('gate')
77 def test_get_crossdomain_policy(self):
78 resp, body = self.os_test_user.account_client.get("crossdomain.xml",
79 {})
80
81 self.assertIn(int(resp['status']), HTTP_SUCCESS)
82 self.assertTrue(body.startswith(self.xml_start) and
83 body.endswith(self.xml_end))
Daisuke Moritad206d3b2013-12-06 15:18:04 +090084
85 # The target of the request is not any Swift resource. Therefore, the
86 # existence of response header is checked without a custom matcher.
87 self.assertIn('content-length', resp)
88 self.assertIn('content-type', resp)
89 self.assertIn('x-trans-id', resp)
90 self.assertIn('date', resp)
91 # Check only the format of common headers with custom matcher
92 self.assertThat(resp, custom_matchers.AreAllWellFormatted())