Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/gsutil/boto/tests/integration/s3/test_encryption.py

Issue 12317103: Added gsutil to depot tools (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: added readme Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright (c) 2010 Mitch Garnaat http://garnaat.org/
2 # Copyright (c) 2010, Eucalyptus Systems, Inc.
3 # All rights reserved.
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish, dis-
9 # tribute, sublicense, and/or sell copies of the Software, and to permit
10 # persons to whom the Software is furnished to do so, subject to the fol-
11 # lowing conditions:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
18 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
19 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 # IN THE SOFTWARE.
23
24 """
25 Some unit tests for the S3 Encryption
26 """
27
28 import unittest
29 import time
30 from boto.s3.connection import S3Connection
31 from boto.exception import S3ResponseError
32
33 json_policy = """{
34 "Version":"2008-10-17",
35 "Id":"PutObjPolicy",
36 "Statement":[{
37 "Sid":"DenyUnEncryptedObjectUploads",
38 "Effect":"Deny",
39 "Principal":{
40 "AWS":"*"
41 },
42 "Action":"s3:PutObject",
43 "Resource":"arn:aws:s3:::%s/*",
44 "Condition":{
45 "StringNotEquals":{
46 "s3:x-amz-server-side-encryption":"AES256"
47 }
48 }
49 }
50 ]
51 }"""
52
53 class S3EncryptionTest (unittest.TestCase):
54 s3 = True
55
56 def test_1_versions(self):
57 print '--- running S3Encryption tests ---'
58 c = S3Connection()
59 # create a new, empty bucket
60 bucket_name = 'encryption-%d' % int(time.time())
61 bucket = c.create_bucket(bucket_name)
62
63 # now try a get_bucket call and see if it's really there
64 bucket = c.get_bucket(bucket_name)
65
66 # create an unencrypted key
67 k = bucket.new_key('foobar')
68 s1 = 'This is unencrypted data'
69 s2 = 'This is encrypted data'
70 k.set_contents_from_string(s1)
71 time.sleep(5)
72
73 # now get the contents from s3
74 o = k.get_contents_as_string()
75
76 # check to make sure content read from s3 is identical to original
77 assert o == s1
78
79 # now overwrite that same key with encrypted data
80 k.set_contents_from_string(s2, encrypt_key=True)
81 time.sleep(5)
82
83 # now retrieve the contents as a string and compare
84 o = k.get_contents_as_string()
85 assert o == s2
86
87 # now set bucket policy to require encrypted objects
88 bucket.set_policy(json_policy % bucket.name)
89 time.sleep(5)
90
91 # now try to write unencrypted key
92 write_failed = False
93 try:
94 k.set_contents_from_string(s1)
95 except S3ResponseError:
96 write_failed = True
97
98 assert write_failed
99
100 # now try to write unencrypted key
101 write_failed = False
102 try:
103 k.set_contents_from_string(s1, encrypt_key=True)
104 except S3ResponseError:
105 write_failed = True
106
107 assert not write_failed
108
109 # Now do regular delete
110 k.delete()
111 time.sleep(5)
112
113 # now delete bucket
114 bucket.delete()
115 print '--- tests completed ---'
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698