Browse code

* S3/ACL.py: Move attributes from class to instance. * run-tests.py: Tests for ACL. * s3cmd: Minor messages changes.

git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@334 830e0280-6d2a-0410-9c65-932aecc39d9d

Michal Ludvig authored on 2009/01/07 21:40:31
Showing 4 changed files
... ...
@@ -2,6 +2,9 @@
2 2
 
3 3
 	* S3/S3.py: Some errors during file upload were incorrectly 
4 4
 	  interpreted as MD5 mismatch. (bug #2384990)
5
+	* S3/ACL.py: Move attributes from class to instance.
6
+	* run-tests.py: Tests for ACL.
7
+	* s3cmd: Minor messages changes.
5 8
 
6 9
 2009-01-07  Michal Ludvig  <michal@logix.cz>
7 10
 
... ...
@@ -13,11 +13,12 @@ except ImportError:
13 13
 class Grantee(object):
14 14
 	ALL_USERS_URI = "http://acs.amazonaws.com/groups/global/AllUsers"
15 15
 
16
-	xsi_type = None
17
-	tag = None
18
-	name = None
19
-	display_name = None
20
-	permission = None
16
+	def __init__(self):
17
+		self.xsi_type = None
18
+		self.tag = None
19
+		self.name = None
20
+		self.display_name = None
21
+		self.permission = None
21 22
 
22 23
 	def __repr__(self):
23 24
 		return 'Grantee("%(tag)s", "%(name)s", "%(permission)s")' % { 
... ...
@@ -45,21 +46,24 @@ class Grantee(object):
45 45
 		return el
46 46
 
47 47
 class GranteeAnonRead(Grantee):
48
-	xsi_type = "Group"
49
-	tag = "URI"
50
-	name = Grantee.ALL_USERS_URI
51
-	permission = "READ"
48
+	def __init__(self):
49
+		Grantee.__init__(self)
50
+		self.xsi_type = "Group"
51
+		self.tag = "URI"
52
+		self.name = Grantee.ALL_USERS_URI
53
+		self.permission = "READ"
52 54
 
53 55
 class ACL(object):
54 56
 	EMPTY_ACL = "<AccessControlPolicy><Owner><ID></ID></Owner><AccessControlList></AccessControlList></AccessControlPolicy>"
55 57
 
56
-	grantees = []
57
-	owner_id = ""
58
-	owner_nick = ""
59
-
60 58
 	def __init__(self, xml = None):
61 59
 		if not xml:
62 60
 			xml = ACL.EMPTY_ACL
61
+
62
+		self.grantees = []
63
+		self.owner_id = ""
64
+		self.owner_nick = ""
65
+
63 66
 		tree = getTreeFromXml(xml)
64 67
 		self.parseOwner(tree)
65 68
 		self.parseGrants(tree)
... ...
@@ -238,26 +238,49 @@ test_s3cmd("List bucket recursive", ['ls', '--recursive', 's3://s3cmd-autotest-1
238 238
 # test_s3cmd("Recursive put", ['put', '--recursive', 'testsuite/etc', 's3://s3cmd-autotest-1/xyz/'])
239 239
 
240 240
 
241
-## ====== Put public, guess MIME
242
-test_s3cmd("Put public, guess MIME", ['put', '--guess-mime-type', '--acl-public', 'testsuite/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc/logo.png'],
243
-	must_find = [ "stored as s3://s3cmd-autotest-1/xyz/etc/logo.png" ])
244
-
245
-
246 241
 ## ====== rmdir local
247 242
 test_rmdir("Removing local target", 'testsuite-out')
248 243
 
249 244
 
250 245
 ## ====== Sync from S3
251
-must_find = [ "stored as testsuite-out/etc/logo.png " ]
246
+must_find = [ "stored as testsuite-out/binary/random-crap.md5 " ]
252 247
 if have_encoding:
253 248
 	must_find.append("stored as testsuite-out/" + encoding + "/" + enc_pattern)
254 249
 test_s3cmd("Sync from S3", ['sync', 's3://s3cmd-autotest-1/xyz', 'testsuite-out'],
255 250
 	must_find = must_find)
256 251
 
257 252
 
253
+## ====== Put public, guess MIME
254
+test_s3cmd("Put public, guess MIME", ['put', '--guess-mime-type', '--acl-public', 'testsuite/etc/logo.png', 's3://s3cmd-autotest-1/xyz/etc/logo.png'],
255
+	must_find = [ "stored as s3://s3cmd-autotest-1/xyz/etc/logo.png" ])
256
+
257
+
258 258
 ## ====== Retrieve from URL
259 259
 if have_wget:
260
-	test("Retrieve from URL", ['wget', 'http://s3cmd-autotest-1.s3.amazonaws.com/xyz/etc/logo.png'],
260
+	test("Retrieve from URL", ['wget', '-O', 'testsuite-out/logo.png', 'http://s3cmd-autotest-1.s3.amazonaws.com/xyz/etc/logo.png'],
261
+		must_find_re = [ 'logo.png.*saved \[22059/22059\]' ])
262
+
263
+
264
+## ====== Change ACL to Private
265
+test_s3cmd("Change ACL to Private", ['setacl', '--acl-private', 's3://s3cmd-autotest-1/xyz/etc/l*.png'],
266
+	must_find = [ "logo.png: ACL set to Private" ])
267
+
268
+
269
+## ====== Verify Private ACL
270
+if have_wget:
271
+	test("Verify Private ACL", ['wget', '-O', 'testsuite-out/logo.png', 'http://s3cmd-autotest-1.s3.amazonaws.com/xyz/etc/logo.png'],
272
+		retcode = 1,
273
+		must_find_re = [ 'ERROR 403: Forbidden' ])
274
+
275
+
276
+## ====== Change ACL to Public
277
+test_s3cmd("Change ACL to Public", ['setacl', '--acl-public', '--recursive', 's3://s3cmd-autotest-1/xyz/etc/', '-v'],
278
+	must_find = [ "logo.png: ACL set to Public" ])
279
+
280
+
281
+## ====== Verify Public ACL
282
+if have_wget:
283
+	test("Verify Public ACL", ['wget', '-O', 'testsuite-out/logo.png', 'http://s3cmd-autotest-1.s3.amazonaws.com/xyz/etc/logo.png'],
261 284
 		must_find_re = [ 'logo.png.*saved \[22059/22059\]' ])
262 285
 
263 286
 
... ...
@@ -279,7 +302,7 @@ test_s3cmd("Rename (NoSuchKey)", ['mv', 's3://s3cmd-autotest-1/xyz/etc/logo.png'
279 279
 
280 280
 ## ====== Sync more from S3
281 281
 test_s3cmd("Sync more from S3", ['sync', '--delete-removed', 's3://s3cmd-autotest-1/xyz', 'testsuite-out'],
282
-	must_find = [ "deleted 'testsuite-out/etc/logo.png'", "stored as testsuite-out/etc2/Logo.PNG (22059 bytes", 
282
+	must_find = [ "deleted 'testsuite-out/logo.png'", "stored as testsuite-out/etc2/Logo.PNG (22059 bytes", 
283 283
 	              "stored as testsuite-out/.svn/format " ],
284 284
 	must_not_find_re = [ "not-deleted.*etc/logo.png" ])
285 285
 
... ...
@@ -898,9 +898,10 @@ def cmd_setacl(args):
898 898
 		seq_label = "[%d of %d]" % (seq, total_keys)
899 899
 		uri = key['remote_uri']
900 900
 		acl = s3.get_acl(uri)
901
+		debug(u"acl: %s - %r" % (uri, acl.grantees))
901 902
 		if cfg.acl_public:
902 903
 			if acl.isAnonRead():
903
-				info(u"%s: already Public, skippingi %s" % (uri, seq_label))
904
+				info(u"%s: already Public, skipping %s" % (uri, seq_label))
904 905
 				continue
905 906
 			acl.grantAnonRead()
906 907
 		else: