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

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

Issue 10199002: Upgrade gsutil to 3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 8 years, 7 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 | Annotate | Revision Log
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 S3 MfaDelete with versioning
26 """
27
28 import unittest
29 import time
30 from boto.s3.connection import S3Connection
31 from boto.exception import S3ResponseError
32 from boto.s3.deletemarker import DeleteMarker
33
34 class S3MFATest (unittest.TestCase):
35
36 def setUp(self):
37 self.conn = S3Connection()
38 self.bucket_name = 'mfa-%d' % int(time.time())
39 self.bucket = self.conn.create_bucket(self.bucket_name)
40
41 def tearDown(self):
42 for k in self.bucket.list_versions():
43 self.bucket.delete_key(k.name, version_id=k.version_id)
44 self.bucket.delete()
45
46 def test_mfadel(self):
47 # Enable Versioning with MfaDelete
48 mfa_sn = raw_input('MFA S/N: ')
49 mfa_code = raw_input('MFA Code: ')
50 self.bucket.configure_versioning(True, mfa_delete=True, mfa_token=(mfa_s n, mfa_code))
51
52 # Check enabling mfa worked.
53 i = 0
54 for i in range(1,8):
55 time.sleep(2**i)
56 d = self.bucket.get_versioning_status()
57 if d['Versioning'] == 'Enabled' and d['MfaDelete'] == 'Enabled':
58 break
59 self.assertEqual('Enabled', d['Versioning'])
60 self.assertEqual('Enabled', d['MfaDelete'])
61
62 # Add a key to the bucket
63 k = self.bucket.new_key('foobar')
64 s1 = 'This is v1'
65 k.set_contents_from_string(s1)
66 v1 = k.version_id
67
68 # Now try to delete v1 without the MFA token
69 try:
70 self.bucket.delete_key('foobar', version_id=v1)
71 self.fail("Must fail if not using MFA token")
72 except S3ResponseError:
73 pass
74
75 # Now try delete again with the MFA token
76 mfa_code = raw_input('MFA Code: ')
77 self.bucket.delete_key('foobar', version_id=v1, mfa_token=(mfa_sn, mfa_c ode))
78
79 # Next suspend versioning and disable MfaDelete on the bucket
80 mfa_code = raw_input('MFA Code: ')
81 self.bucket.configure_versioning(False, mfa_delete=False, mfa_token=(mfa _sn, mfa_code))
82
83 # Lastly, check disabling mfa worked.
84 i = 0
85 for i in range(1,8):
86 time.sleep(2**i)
87 d = self.bucket.get_versioning_status()
88 if d['Versioning'] == 'Suspended' and d['MfaDelete'] != 'Enabled':
89 break
90 self.assertEqual('Suspended', d['Versioning'])
91 self.assertNotEqual('Enabled', d['MfaDelete'])
OLDNEW
« no previous file with comments | « third_party/gsutil/boto/tests/s3/test_key.py ('k') | third_party/gsutil/boto/tests/s3/test_multidelete.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698