1 # -*- coding: utf-8 -*-
2 # Copyright 2014 Google Inc. All Rights Reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 """Integration tests for multiple bucket configuration commands."""
18 import gslib
.tests
.testcase
as testcase
19 from gslib
.tests
.testcase
.integration_testcase
import SkipForS3
20 from gslib
.tests
.util
import ObjectToURI
as suri
23 class TestBucketConfig(testcase
.GsUtilIntegrationTestCase
):
24 """Integration tests for multiple bucket configuration commands."""
26 _set_cors_command
= ['cors', 'set']
27 _get_cors_command
= ['cors', 'get']
32 '[{"origin": ["http://origin1.example.com", '
33 '"http://origin2.example.com"], '
34 '"responseHeader": ["foo", "bar"], "method": ["GET", "PUT", "POST"], '
35 '"maxAgeSeconds": 3600},'
36 '{"origin": ["http://origin3.example.com"], '
37 '"responseHeader": ["foo2", "bar2"], "method": ["GET", "DELETE"]}]\n')
38 cors_json_obj
= json
.loads(cors_doc
)
40 _set_lifecycle_command
= ['lifecycle', 'set']
41 _get_lifecycle_command
= ['lifecycle', 'get']
43 empty_lifecycle
= '{}'
46 '{"rule": [{"action": {"type": "Delete"}, "condition": {"age": 365}}]}\n')
47 lifecycle_json_obj
= json
.loads(lifecycle_doc
)
49 _set_acl_command
= ['acl', 'set']
50 _get_acl_command
= ['acl', 'get']
51 _set_defacl_command
= ['defacl', 'set']
52 _get_defacl_command
= ['defacl', 'get']
54 @SkipForS3('A number of configs in this test are not supported by S3')
55 def test_set_multi_config(self
):
56 """Tests that bucket config patching affects only the desired config."""
57 bucket_uri
= self
.CreateBucket()
58 lifecycle_path
= self
.CreateTempFile(contents
=self
.lifecycle_doc
)
59 cors_path
= self
.CreateTempFile(contents
=self
.cors_doc
)
61 self
.RunGsUtil(self
._set
_cors
_command
+ [cors_path
, suri(bucket_uri
)])
62 cors_out
= self
.RunGsUtil(self
._get
_cors
_command
+ [suri(bucket_uri
)],
64 self
.assertEqual(json
.loads(cors_out
), self
.cors_json_obj
)
66 self
.RunGsUtil(self
._set
_lifecycle
_command
+ [lifecycle_path
,
68 cors_out
= self
.RunGsUtil(self
._get
_cors
_command
+ [suri(bucket_uri
)],
70 lifecycle_out
= self
.RunGsUtil(self
._get
_lifecycle
_command
+
71 [suri(bucket_uri
)], return_stdout
=True)
72 self
.assertEqual(json
.loads(cors_out
), self
.cors_json_obj
)
73 self
.assertEqual(json
.loads(lifecycle_out
), self
.lifecycle_json_obj
)
76 self
._set
_acl
_command
+ ['authenticated-read', suri(bucket_uri
)])
78 cors_out
= self
.RunGsUtil(self
._get
_cors
_command
+ [suri(bucket_uri
)],
80 lifecycle_out
= self
.RunGsUtil(self
._get
_lifecycle
_command
+
81 [suri(bucket_uri
)], return_stdout
=True)
82 acl_out
= self
.RunGsUtil(self
._get
_acl
_command
+ [suri(bucket_uri
)],
84 self
.assertEqual(json
.loads(cors_out
), self
.cors_json_obj
)
85 self
.assertEqual(json
.loads(lifecycle_out
), self
.lifecycle_json_obj
)
86 self
.assertIn('allAuthenticatedUsers', acl_out
)
89 self
._set
_defacl
_command
+ ['public-read', suri(bucket_uri
)])
91 cors_out
= self
.RunGsUtil(self
._get
_cors
_command
+ [suri(bucket_uri
)],
93 lifecycle_out
= self
.RunGsUtil(self
._get
_lifecycle
_command
+
94 [suri(bucket_uri
)], return_stdout
=True)
95 acl_out
= self
.RunGsUtil(self
._get
_acl
_command
+ [suri(bucket_uri
)],
97 def_acl_out
= self
.RunGsUtil(self
._get
_defacl
_command
+ [suri(bucket_uri
)],
99 self
.assertEqual(json
.loads(cors_out
), self
.cors_json_obj
)
100 self
.assertEqual(json
.loads(lifecycle_out
), self
.lifecycle_json_obj
)
101 self
.assertIn('allAuthenticatedUsers', acl_out
)
102 self
.assertIn('allUsers', def_acl_out
)