Example #1
0
    def testBucketConditionalSetXmlAcl(self):
        b = self._MakeVersionedBucket()
        k = b.new_key("foo")
        s1 = "test1"
        k.set_contents_from_string(s1)

        g1 = k.generation
        mg1 = k.meta_generation
        self.assertEqual(str(mg1), "1")

        acl_xml = (
            '<ACCESSControlList><EntrIes><Entry>' +
            '<Scope type="AllUsers"></Scope><Permission>READ</Permission>' +
            '</Entry></EntrIes></ACCESSControlList>')
        acl = ACL()
        h = handler.XmlHandler(acl, b)
        sax.parseString(acl_xml, h)
        acl = acl.to_xml()

        b.set_xml_acl(acl, key_name="foo")

        k = b.get_key("foo")
        g2 = k.generation
        mg2 = k.meta_generation

        self.assertEqual(g2, g1)
        self.assertGreater(mg2, mg1)

        with self.assertRaisesRegexp(ValueError, ("Received if_metageneration "
                                                  "argument with no "
                                                  "if_generation argument")):
            b.set_xml_acl(acl, key_name="foo", if_metageneration=123)

        with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
            b.set_xml_acl(acl, key_name="foo", if_generation=int(g2) + 1)

        with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
            b.set_xml_acl(acl,
                          key_name="foo",
                          if_generation=g2,
                          if_metageneration=int(mg2) + 1)

        b.set_xml_acl(acl, key_name="foo", if_generation=g2)

        k = b.get_key("foo")
        g3 = k.generation
        mg3 = k.meta_generation
        self.assertEqual(g3, g2)
        self.assertGreater(mg3, mg2)

        b.set_xml_acl(acl,
                      key_name="foo",
                      if_generation=g3,
                      if_metageneration=mg3)
    def testBucketConditionalSetXmlAcl(self):
        b = self._MakeVersionedBucket()
        k = b.new_key("foo")
        s1 = "test1"
        k.set_contents_from_string(s1)

        g1 = k.generation
        mg1 = k.meta_generation
        self.assertEqual(str(mg1), "1")

        acl_xml = (
            '<ACCESSControlList><EntrIes><Entry>'    +
            '<Scope type="AllUsers"></Scope><Permission>READ</Permission>' +
            '</Entry></EntrIes></ACCESSControlList>')
        acl = ACL()
        h = handler.XmlHandler(acl, b)
        sax.parseString(acl_xml, h)
        acl = acl.to_xml()

        b.set_xml_acl(acl, key_name="foo")

        k = b.get_key("foo")
        g2 = k.generation
        mg2 = k.meta_generation

        self.assertEqual(g2, g1)
        self.assertGreater(mg2, mg1)

        with self.assertRaisesRegexp(ValueError, ("Received if_metageneration "
                                                  "argument with no "
                                                  "if_generation argument")):
            b.set_xml_acl(acl, key_name="foo", if_metageneration=123)

        with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
            b.set_xml_acl(acl, key_name="foo", if_generation=int(g2) + 1)

        with self.assertRaisesRegexp(GSResponseError, VERSION_MISMATCH):
            b.set_xml_acl(acl, key_name="foo", if_generation=g2,
                          if_metageneration=int(mg2) + 1)

        b.set_xml_acl(acl, key_name="foo", if_generation=g2)

        k = b.get_key("foo")
        g3 = k.generation
        mg3 = k.meta_generation
        self.assertEqual(g3, g2)
        self.assertGreater(mg3, mg2)

        b.set_xml_acl(acl, key_name="foo", if_generation=g3,
                      if_metageneration=mg3)
Example #3
0
 def _get_acl_helper(self, key_name, headers, query_args):
     """Provides common functionality for get_acl and get_def_acl."""
     body = self._get_xml_acl_helper(key_name, headers, query_args)
     acl = ACL(self)
     h = handler.XmlHandler(acl, self)
     xml.sax.parseString(body, h)
     return acl
Example #4
0
    def test_acl(self):
        """Test bucket and key ACLs."""
        bucket = self._MakeBucket()

        # try some acl stuff
        bucket.set_acl('public-read')
        acl = bucket.get_acl()
        self.assertEqual(len(acl.entries.entry_list), 2)
        bucket.set_acl('private')
        acl = bucket.get_acl()
        self.assertEqual(len(acl.entries.entry_list), 1)
        k = self._MakeKey(bucket=bucket)
        k.set_acl('public-read')
        acl = k.get_acl()
        self.assertEqual(len(acl.entries.entry_list), 2)
        k.set_acl('private')
        acl = k.get_acl()
        self.assertEqual(len(acl.entries.entry_list), 1)

        # Test case-insensitivity of XML ACL parsing.
        acl_xml = (
            '<ACCESSControlList><EntrIes><Entry>'    +
            '<Scope type="AllUsers"></Scope><Permission>READ</Permission>' +
            '</Entry></EntrIes></ACCESSControlList>')
        acl = ACL()
        h = handler.XmlHandler(acl, bucket)
        xml.sax.parseString(acl_xml, h)
        bucket.set_acl(acl)
        self.assertEqual(len(acl.entries.entry_list), 1)
        aclstr = k.get_xml_acl()
        self.assertGreater(aclstr.count('/Entry', 1), 0)
Example #5
0
 def get_acl(self, key_name='', headers=None):
     response = self.connection.make_request('GET', self.name, key_name,
             query_args='acl', headers=headers)
     body = response.read()
     if response.status == 200:
         acl = ACL(self)
         h = handler.XmlHandler(acl, self)
         xml.sax.parseString(body, h)
         return acl
     else:
         raise S3ResponseError(response.status, response.reason, body)
Example #6
0
 def get_acl_helper(self, key_name, headers, query_args):
     """provides common functionality for get_acl() and get_def_acl()"""
     response = self.connection.make_request('GET', self.name, key_name,
                                             query_args=query_args, 
                                             headers=headers)
     body = response.read()
     if response.status == 200:
         acl = ACL(self)
         h = handler.XmlHandler(acl, self)
         xml.sax.parseString(body, h)
         return acl
     else:
         raise self.connection.provider.storage_response_error(
             response.status, response.reason, body)
Example #7
0
 def BotoAclFromJson(cls, acl_json):
     acl = ACL()
     acl.parent = None
     acl.entries = cls.BotoEntriesFromJson(acl_json, acl)
     return acl
Example #8
0
 def BotoAclFromJson(cls, acl_json):
   acl = ACL()
   acl.parent = None
   acl.entries = cls.BotoEntriesFromJson(acl_json, acl)
   return acl