| OLD | NEW |
| 1 # -*- coding: utf-8 -*- |
| 1 # Copyright 2013 Google Inc. All Rights Reserved. | 2 # Copyright 2013 Google Inc. All Rights Reserved. |
| 2 # | 3 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. | 5 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
| 6 # | 7 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 9 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 11 # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 # See the License for the specific language governing permissions and | 13 # See the License for the specific language governing permissions and |
| 13 # limitations under the License. | 14 # limitations under the License. |
| 15 """Integration tests for cors command.""" |
| 14 | 16 |
| 17 from __future__ import absolute_import |
| 18 |
| 19 import json |
| 15 import posixpath | 20 import posixpath |
| 16 from xml.dom.minidom import parseString | 21 from xml.dom.minidom import parseString |
| 17 | 22 |
| 23 import gslib.tests.testcase as testcase |
| 24 from gslib.tests.testcase.integration_testcase import SkipForS3 |
| 25 from gslib.tests.util import ObjectToURI as suri |
| 26 from gslib.translation_helper import CorsTranslation |
| 18 from gslib.util import Retry | 27 from gslib.util import Retry |
| 19 import gslib.tests.testcase as testcase | |
| 20 from gslib.tests.util import ObjectToURI as suri | |
| 21 | 28 |
| 22 | 29 |
| 30 @SkipForS3('CORS command is only supported for gs:// URLs') |
| 23 class TestCors(testcase.GsUtilIntegrationTestCase): | 31 class TestCors(testcase.GsUtilIntegrationTestCase): |
| 24 """Integration tests for cors command.""" | 32 """Integration tests for cors command.""" |
| 25 | 33 |
| 26 _set_cmd_prefix = ['cors', 'set'] | 34 _set_cmd_prefix = ['cors', 'set'] |
| 27 _get_cmd_prefix = ['cors', 'get'] | 35 _get_cmd_prefix = ['cors', 'get'] |
| 28 | 36 |
| 29 empty_doc1 = parseString('<CorsConfig/>').toprettyxml(indent=' ') | 37 empty_doc1 = '[]' |
| 38 empty_doc2 = '[ {} ]' |
| 30 | 39 |
| 31 empty_doc2 = parseString( | 40 cors_bad = ( |
| 32 '<CorsConfig></CorsConfig>').toprettyxml(indent=' ') | 41 '[{"origin": ["http://origin1.example.com", ' |
| 42 '"http://origin2.example.com"], ' |
| 43 '"responseHeader": ["foo", "bar"], "badmethod": ["GET", "PUT", "POST"], ' |
| 44 '"maxAgeSeconds": 3600},' |
| 45 '{"origin": ["http://origin3.example.com"], ' |
| 46 '"responseHeader": ["foo2", "bar2"], "method": ["GET", "DELETE"]}])' |
| 47 ) |
| 33 | 48 |
| 34 empty_doc3 = parseString( | 49 no_cors = 'has no CORS configuration' |
| 35 '<CorsConfig><Cors/></CorsConfig>').toprettyxml(indent=' ') | |
| 36 | 50 |
| 37 empty_doc4 = parseString( | 51 xml_cors_doc = parseString( |
| 38 '<CorsConfig><Cors></Cors></CorsConfig>').toprettyxml(indent=' ') | |
| 39 | |
| 40 cors_bad1 = ('<?xml version="1.0" ?><CorsConfig><Cors><Methods><Method>GET' | |
| 41 '</ResponseHeader></Methods></Cors></CorsConfig>') | |
| 42 | |
| 43 cors_bad2 = ('<?xml version="1.0" ?><CorsConfig><Cors><Methods><Cors>GET' | |
| 44 '</Cors></Methods></Cors></CorsConfig>') | |
| 45 | |
| 46 cors_bad3 = ('<?xml version="1.0" ?><CorsConfig><Methods><Method>GET' | |
| 47 '</Method></Methods></Cors></CorsConfig>') | |
| 48 | |
| 49 cors_bad4 = ('<?xml version="1.0" ?><CorsConfig><Cors><Method>GET' | |
| 50 '</Method></Cors></CorsConfig>') | |
| 51 | |
| 52 cors_doc = parseString( | |
| 53 '<CorsConfig><Cors><Origins>' | 52 '<CorsConfig><Cors><Origins>' |
| 54 '<Origin>http://origin1.example.com</Origin>' | 53 '<Origin>http://origin1.example.com</Origin>' |
| 55 '<Origin>http://origin2.example.com</Origin>' | 54 '<Origin>http://origin2.example.com</Origin>' |
| 56 '</Origins><Methods><Method>GET</Method>' | 55 '</Origins><Methods><Method>GET</Method>' |
| 57 '<Method>PUT</Method><Method>POST</Method></Methods>' | 56 '<Method>PUT</Method><Method>POST</Method></Methods>' |
| 58 '<ResponseHeaders><ResponseHeader>foo</ResponseHeader>' | 57 '<ResponseHeaders><ResponseHeader>foo</ResponseHeader>' |
| 59 '<ResponseHeader>bar</ResponseHeader></ResponseHeaders>' | 58 '<ResponseHeader>bar</ResponseHeader></ResponseHeaders>' |
| 60 '<MaxAgeSec>3600</MaxAgeSec></Cors>' | 59 '<MaxAgeSec>3600</MaxAgeSec></Cors>' |
| 61 '<Cors><Origins><Origin>http://origin3.example.com</Origin></Origins>' | 60 '<Cors><Origins><Origin>http://origin3.example.com</Origin></Origins>' |
| 62 '<Methods><Method>GET</Method><Method>DELETE</Method></Methods>' | 61 '<Methods><Method>GET</Method><Method>DELETE</Method></Methods>' |
| 63 '<ResponseHeaders><ResponseHeader>foo2</ResponseHeader>' | 62 '<ResponseHeaders><ResponseHeader>foo2</ResponseHeader>' |
| 64 '<ResponseHeader>bar2</ResponseHeader></ResponseHeaders>' | 63 '<ResponseHeader>bar2</ResponseHeader></ResponseHeaders>' |
| 65 '</Cors></CorsConfig>').toprettyxml(indent=' ') | 64 '</Cors></CorsConfig>').toprettyxml(indent=' ') |
| 66 | 65 |
| 66 cors_doc = ( |
| 67 '[{"origin": ["http://origin1.example.com", ' |
| 68 '"http://origin2.example.com"], ' |
| 69 '"responseHeader": ["foo", "bar"], "method": ["GET", "PUT", "POST"], ' |
| 70 '"maxAgeSeconds": 3600},' |
| 71 '{"origin": ["http://origin3.example.com"], ' |
| 72 '"responseHeader": ["foo2", "bar2"], "method": ["GET", "DELETE"]}]\n') |
| 73 cors_json_obj = json.loads(cors_doc) |
| 74 |
| 75 cors_doc2 = ( |
| 76 '[{"origin": ["http://origin1.example.com", ' |
| 77 '"http://origin2.example.com"], ' |
| 78 '"responseHeader": ["foo", "bar"], "method": ["GET", "PUT", "POST"]}]\n') |
| 79 cors_json_obj2 = json.loads(cors_doc2) |
| 80 |
| 81 def test_cors_translation(self): |
| 82 """Tests cors translation for various formats.""" |
| 83 json_text = self.cors_doc |
| 84 entries_list = CorsTranslation.JsonCorsToMessageEntries(json_text) |
| 85 boto_cors = CorsTranslation.BotoCorsFromMessage(entries_list) |
| 86 converted_entries_list = CorsTranslation.BotoCorsToMessage(boto_cors) |
| 87 converted_json_text = CorsTranslation.MessageEntriesToJson( |
| 88 converted_entries_list) |
| 89 self.assertEqual(json.loads(json_text), json.loads(converted_json_text)) |
| 90 |
| 67 def test_default_cors(self): | 91 def test_default_cors(self): |
| 68 bucket_uri = self.CreateBucket() | 92 bucket_uri = self.CreateBucket() |
| 69 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], | 93 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], |
| 70 return_stdout=True) | 94 return_stdout=True) |
| 71 self.assertEqual(stdout, self.empty_doc1) | 95 self.assertIn(self.no_cors, stdout) |
| 72 | 96 |
| 73 def test_set_empty_cors1(self): | 97 def test_set_empty_cors1(self): |
| 74 bucket_uri = self.CreateBucket() | 98 bucket_uri = self.CreateBucket() |
| 75 fpath = self.CreateTempFile(contents=self.empty_doc1) | 99 fpath = self.CreateTempFile(contents=self.empty_doc1) |
| 76 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)]) | 100 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)]) |
| 77 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], | 101 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], |
| 78 return_stdout=True) | 102 return_stdout=True) |
| 79 self.assertEqual(stdout, self.empty_doc1) | 103 self.assertIn(self.no_cors, stdout) |
| 80 | 104 |
| 81 def test_set_empty_cors2(self): | 105 def test_set_empty_cors2(self): |
| 82 bucket_uri = self.CreateBucket() | 106 bucket_uri = self.CreateBucket() |
| 83 fpath = self.CreateTempFile(contents=self.empty_doc2) | 107 fpath = self.CreateTempFile(contents=self.empty_doc2) |
| 84 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)]) | 108 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)]) |
| 85 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], | 109 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], |
| 86 return_stdout=True) | 110 return_stdout=True) |
| 87 self.assertEqual(stdout, self.empty_doc1) | 111 self.assertIn(self.no_cors, stdout) |
| 88 | |
| 89 def test_set_empty_cors3(self): | |
| 90 bucket_uri = self.CreateBucket() | |
| 91 fpath = self.CreateTempFile(contents=self.empty_doc3) | |
| 92 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)]) | |
| 93 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], | |
| 94 return_stdout=True) | |
| 95 self.assertEqual(stdout, self.empty_doc3) | |
| 96 | |
| 97 def test_set_empty_cors4(self): | |
| 98 bucket_uri = self.CreateBucket() | |
| 99 fpath = self.CreateTempFile(contents=self.empty_doc4) | |
| 100 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)]) | |
| 101 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], | |
| 102 return_stdout=True) | |
| 103 self.assertEqual(stdout, self.empty_doc3) | |
| 104 | 112 |
| 105 def test_non_null_cors(self): | 113 def test_non_null_cors(self): |
| 106 bucket_uri = self.CreateBucket() | 114 bucket_uri = self.CreateBucket() |
| 107 fpath = self.CreateTempFile(contents=self.cors_doc) | 115 fpath = self.CreateTempFile(contents=self.cors_doc) |
| 108 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)]) | 116 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)]) |
| 109 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], | 117 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], |
| 110 return_stdout=True) | 118 return_stdout=True) |
| 111 self.assertEqual(stdout, self.cors_doc) | 119 self.assertEqual(json.loads(stdout), self.cors_json_obj) |
| 112 | 120 |
| 113 def test_bad_cors1(self): | 121 def test_bad_cors_xml(self): |
| 114 bucket_uri = self.CreateBucket() | 122 bucket_uri = self.CreateBucket() |
| 115 fpath = self.CreateTempFile(contents=self.cors_bad1) | 123 fpath = self.CreateTempFile(contents=self.xml_cors_doc) |
| 116 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)], | 124 stderr = self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)], |
| 117 expected_status=1) | 125 expected_status=1, return_stderr=True) |
| 126 self.assertIn('XML CORS data provided', stderr) |
| 118 | 127 |
| 119 def test_bad_cors2(self): | 128 def test_bad_cors(self): |
| 120 bucket_uri = self.CreateBucket() | 129 bucket_uri = self.CreateBucket() |
| 121 fpath = self.CreateTempFile(contents=self.cors_bad2) | 130 fpath = self.CreateTempFile(contents=self.cors_bad) |
| 122 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)], | 131 stderr = self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)], |
| 123 expected_status=1) | 132 expected_status=1, return_stderr=True) |
| 124 | 133 self.assertNotIn('XML CORS data provided', stderr) |
| 125 def test_bad_cors3(self): | |
| 126 bucket_uri = self.CreateBucket() | |
| 127 fpath = self.CreateTempFile(contents=self.cors_bad3) | |
| 128 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)], | |
| 129 expected_status=1) | |
| 130 | |
| 131 def test_bad_cors4(self): | |
| 132 bucket_uri = self.CreateBucket() | |
| 133 fpath = self.CreateTempFile(contents=self.cors_bad4) | |
| 134 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)], | |
| 135 expected_status=1) | |
| 136 | 134 |
| 137 def set_cors_and_reset(self): | 135 def set_cors_and_reset(self): |
| 136 """Tests setting CORS then removing it.""" |
| 138 bucket_uri = self.CreateBucket() | 137 bucket_uri = self.CreateBucket() |
| 139 tmpdir = self.CreateTempDir() | 138 tmpdir = self.CreateTempDir() |
| 140 fpath = self.CreateTempFile(tmpdir=tmpdir, contents=self.cors_doc) | 139 fpath = self.CreateTempFile(tmpdir=tmpdir, contents=self.cors_doc) |
| 141 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)]) | 140 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)]) |
| 142 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], | 141 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], |
| 143 return_stdout=True) | 142 return_stdout=True) |
| 144 self.assertEqual(stdout, self.cors_doc) | 143 self.assertEqual(json.loads(stdout), self.valid_cors_obj) |
| 145 | 144 |
| 146 fpath = self.CreateTempFile(tmpdir=tmpdir, contents=self.empty_doc1) | 145 fpath = self.CreateTempFile(tmpdir=tmpdir, contents=self.empty_doc1) |
| 147 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)]) | 146 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)]) |
| 148 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], | 147 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], |
| 149 return_stdout=True) | 148 return_stdout=True) |
| 150 self.assertEqual(stdout, self.empty_doc1) | 149 self.assertIn(self.no_cors, stdout) |
| 150 |
| 151 def set_partial_cors_and_reset(self): |
| 152 """Tests setting CORS without maxAgeSeconds, then removing it.""" |
| 153 bucket_uri = self.CreateBucket() |
| 154 tmpdir = self.CreateTempDir() |
| 155 fpath = self.CreateTempFile(tmpdir=tmpdir, contents=self.cors_doc2) |
| 156 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)]) |
| 157 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], |
| 158 return_stdout=True) |
| 159 self.assertEqual(json.loads(stdout), self.cors_json_obj2) |
| 160 |
| 161 fpath = self.CreateTempFile(tmpdir=tmpdir, contents=self.empty_doc1) |
| 162 self.RunGsUtil(self._set_cmd_prefix + [fpath, suri(bucket_uri)]) |
| 163 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket_uri)], |
| 164 return_stdout=True) |
| 165 self.assertIn(self.no_cors, stdout) |
| 151 | 166 |
| 152 def set_multi_non_null_cors(self): | 167 def set_multi_non_null_cors(self): |
| 168 """Tests setting different CORS configurations.""" |
| 153 bucket1_uri = self.CreateBucket() | 169 bucket1_uri = self.CreateBucket() |
| 154 bucket2_uri = self.CreateBucket() | 170 bucket2_uri = self.CreateBucket() |
| 155 fpath = self.CreateTempFile(contents=self.cors_doc) | 171 fpath = self.CreateTempFile(contents=self.cors_doc) |
| 156 self.RunGsUtil( | 172 self.RunGsUtil( |
| 157 self._set_cmd_prefix + [fpath, suri(bucket1_uri), suri(bucket2_uri)]) | 173 self._set_cmd_prefix + [fpath, suri(bucket1_uri), suri(bucket2_uri)]) |
| 158 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket1_uri)], | 174 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket1_uri)], |
| 159 return_stdout=True) | 175 return_stdout=True) |
| 160 self.assertEqual(stdout, self.cors_doc) | 176 self.assertEqual(json.loads(stdout), self.cors_json_obj) |
| 161 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket2_uri)], | 177 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket2_uri)], |
| 162 return_stdout=True) | 178 return_stdout=True) |
| 163 self.assertEqual(stdout, self.cors_doc) | 179 self.assertEqual(json.loads(stdout), self.cors_json_obj) |
| 164 | 180 |
| 165 def test_set_wildcard_non_null_cors(self): | 181 def test_set_wildcard_non_null_cors(self): |
| 182 """Tests setting CORS on a wildcarded bucket URI.""" |
| 166 random_prefix = self.MakeRandomTestString() | 183 random_prefix = self.MakeRandomTestString() |
| 167 bucket1_name = self.MakeTempName('bucket', prefix=random_prefix) | 184 bucket1_name = self.MakeTempName('bucket', prefix=random_prefix) |
| 168 bucket2_name = self.MakeTempName('bucket', prefix=random_prefix) | 185 bucket2_name = self.MakeTempName('bucket', prefix=random_prefix) |
| 169 bucket1_uri = self.CreateBucket(bucket_name=bucket1_name) | 186 bucket1_uri = self.CreateBucket(bucket_name=bucket1_name) |
| 170 bucket2_uri = self.CreateBucket(bucket_name=bucket2_name) | 187 bucket2_uri = self.CreateBucket(bucket_name=bucket2_name) |
| 171 # This just double checks that the common prefix of the two buckets is what | 188 # This just double checks that the common prefix of the two buckets is what |
| 172 # we think it should be (based on implementation detail of CreateBucket). | 189 # we think it should be (based on implementation detail of CreateBucket). |
| 173 # We want to be careful when setting a wildcard on buckets to make sure we | 190 # We want to be careful when setting a wildcard on buckets to make sure we |
| 174 # don't step outside the test buckets to affect other buckets. | 191 # don't step outside the test buckets to affect other buckets. |
| 175 common_prefix = posixpath.commonprefix([suri(bucket1_uri), | 192 common_prefix = posixpath.commonprefix([suri(bucket1_uri), |
| 176 suri(bucket2_uri)]) | 193 suri(bucket2_uri)]) |
| 177 self.assertTrue(common_prefix.startswith( | 194 self.assertTrue(common_prefix.startswith( |
| 178 'gs://%sgsutil-test-test_set_wildcard_non_null_cors-' % random_prefix)) | 195 'gs://%sgsutil-test-test_set_wildcard_non_null_cors-' % random_prefix)) |
| 179 wildcard = '%s*' % common_prefix | 196 wildcard = '%s*' % common_prefix |
| 180 | 197 |
| 181 fpath = self.CreateTempFile(contents=self.cors_doc) | 198 fpath = self.CreateTempFile(contents=self.cors_doc) |
| 182 | 199 |
| 183 # Use @Retry as hedge against bucket listing eventual consistency. | 200 # Use @Retry as hedge against bucket listing eventual consistency. |
| 184 expected = set(['Setting CORS on %s/...' % suri(bucket1_uri), | 201 expected = set(['Setting CORS on %s/...' % suri(bucket1_uri), |
| 185 'Setting CORS on %s/...' % suri(bucket2_uri)]) | 202 'Setting CORS on %s/...' % suri(bucket2_uri)]) |
| 186 actual = set() | 203 actual = set() |
| 187 @Retry(AssertionError, tries=3, timeout_secs=1) | 204 @Retry(AssertionError, tries=3, timeout_secs=1) |
| 188 def _Check1(): | 205 def _Check1(): |
| 206 """Ensures expect set lines are present in command output.""" |
| 189 stderr = self.RunGsUtil(self._set_cmd_prefix + [fpath, wildcard], | 207 stderr = self.RunGsUtil(self._set_cmd_prefix + [fpath, wildcard], |
| 190 return_stderr=True) | 208 return_stderr=True) |
| 191 outlines = stderr.splitlines() | 209 outlines = stderr.splitlines() |
| 192 for line in outlines: | 210 for line in outlines: |
| 193 # Ignore the deprecation warnings from running the old cors command. | 211 # Ignore the deprecation warnings from running the old cors command. |
| 194 if ('You are using a deprecated alias' in line or | 212 if ('You are using a deprecated alias' in line or |
| 195 'gsutil help cors' in line or | 213 'gsutil help cors' in line or |
| 196 'Please use "cors" with the appropriate sub-command' in line): | 214 'Please use "cors" with the appropriate sub-command' in line): |
| 197 continue | 215 continue |
| 198 actual.add(line) | 216 actual.add(line) |
| 199 for line in expected: | 217 for line in expected: |
| 200 self.assertIn(line, actual) | 218 self.assertIn(line, actual) |
| 201 self.assertEqual(stderr.count('Setting CORS'), 2) | 219 self.assertEqual(stderr.count('Setting CORS'), 2) |
| 202 _Check1() | 220 _Check1() |
| 203 | 221 |
| 204 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket1_uri)], | 222 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket1_uri)], |
| 205 return_stdout=True) | 223 return_stdout=True) |
| 206 self.assertEqual(stdout, self.cors_doc) | 224 self.assertEqual(json.loads(stdout), self.cors_json_obj) |
| 207 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket2_uri)], | 225 stdout = self.RunGsUtil(self._get_cmd_prefix + [suri(bucket2_uri)], |
| 208 return_stdout=True) | 226 return_stdout=True) |
| 209 self.assertEqual(stdout, self.cors_doc) | 227 self.assertEqual(json.loads(stdout), self.cors_json_obj) |
| 210 | 228 |
| 211 def testTooFewArgumentsFails(self): | 229 def testTooFewArgumentsFails(self): |
| 230 """Ensures CORS commands fail with too few arguments.""" |
| 212 # No arguments for get, but valid subcommand. | 231 # No arguments for get, but valid subcommand. |
| 213 stderr = self.RunGsUtil(self._get_cmd_prefix, return_stderr=True, | 232 stderr = self.RunGsUtil(self._get_cmd_prefix, return_stderr=True, |
| 214 expected_status=1) | 233 expected_status=1) |
| 215 self.assertIn('command requires at least', stderr) | 234 self.assertIn('command requires at least', stderr) |
| 216 | 235 |
| 217 # No arguments for set, but valid subcommand. | 236 # No arguments for set, but valid subcommand. |
| 218 stderr = self.RunGsUtil(self._set_cmd_prefix, return_stderr=True, | 237 stderr = self.RunGsUtil(self._set_cmd_prefix, return_stderr=True, |
| 219 expected_status=1) | 238 expected_status=1) |
| 220 self.assertIn('command requires at least', stderr) | 239 self.assertIn('command requires at least', stderr) |
| 221 | 240 |
| 222 # Neither arguments nor subcommand. | 241 # Neither arguments nor subcommand. |
| 223 stderr = self.RunGsUtil(['cors'], return_stderr=True, expected_status=1) | 242 stderr = self.RunGsUtil(['cors'], return_stderr=True, expected_status=1) |
| 224 self.assertIn('command requires at least', stderr) | 243 self.assertIn('command requires at least', stderr) |
| 225 | 244 |
| 245 |
| 226 class TestCorsOldAlias(TestCors): | 246 class TestCorsOldAlias(TestCors): |
| 227 _set_cmd_prefix = ['setcors'] | 247 _set_cmd_prefix = ['setcors'] |
| 228 _get_cmd_prefix = ['getcors'] | 248 _get_cmd_prefix = ['getcors'] |
| OLD | NEW |