Exemple #1
0
    def test_bucket_PUT(self):
        req = Request.blank('/bucket',
                            environ={'REQUEST_METHOD': 'PUT'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header()})
        status, headers, body = self.call_s3api(req)
        self.assertEqual(body, '')
        self.assertEqual(status.split()[0], '200')
        self.assertEqual(headers['Location'], '/bucket')

        # Apparently some clients will include a chunked transfer-encoding
        # even with no body
        req = Request.blank('/bucket',
                            environ={'REQUEST_METHOD': 'PUT'},
                            headers={'Authorization': 'AWS test:tester:hmac',
                                     'Date': self.get_date_header(),
                                     'Transfer-Encoding': 'chunked'})
        status, headers, body = self.call_s3api(req)
        self.assertEqual(body, '')
        self.assertEqual(status.split()[0], '200')
        self.assertEqual(headers['Location'], '/bucket')

        with UnreadableInput(self) as fake_input:
            req = Request.blank(
                '/bucket',
                environ={'REQUEST_METHOD': 'PUT',
                         'wsgi.input': fake_input},
                headers={'Authorization': 'AWS test:tester:hmac',
                         'Date': self.get_date_header()})
            status, headers, body = self.call_s3api(req)
        self.assertEqual(body, '')
        self.assertEqual(status.split()[0], '200')
        self.assertEqual(headers['Location'], '/bucket')
Exemple #2
0
 def _test_put_no_body(self, use_content_length=False,
                       use_transfer_encoding=False, string_to_md5=b''):
     content_md5 = base64.b64encode(md5(string_to_md5).digest()).strip()
     with UnreadableInput(self) as fake_input:
         req = Request.blank(
             '/bucket?acl',
             environ={
                 'REQUEST_METHOD': 'PUT',
                 'wsgi.input': fake_input},
             headers={
                 'Authorization': 'AWS test:tester:hmac',
                 'Date': self.get_date_header(),
                 'Content-MD5': content_md5},
             body='')
         if not use_content_length:
             req.environ.pop('CONTENT_LENGTH')
         if use_transfer_encoding:
             req.environ['HTTP_TRANSFER_ENCODING'] = 'chunked'
         status, headers, body = self.call_s3api(req)
     self.assertEqual(status, '400 Bad Request')
     self.assertEqual(self._get_error_code(body), 'MissingSecurityHeader')
     self.assertEqual(self._get_error_message(body),
                      'Your request was missing a required header.')
     self.assertIn(b'<MissingHeaderName>x-amz-acl</MissingHeaderName>',
                   body)
 def _test_no_body(self,
                   use_content_length=False,
                   use_transfer_encoding=False,
                   string_to_md5=b''):
     content_md5 = (base64.b64encode(
         md5(string_to_md5, usedforsecurity=False).digest()).strip())
     with UnreadableInput(self) as fake_input:
         req = Request.blank('/bucket?delete',
                             environ={
                                 'REQUEST_METHOD': 'POST',
                                 'wsgi.input': fake_input
                             },
                             headers={
                                 'Authorization': 'AWS test:tester:hmac',
                                 'Date': self.get_date_header(),
                                 'Content-MD5': content_md5
                             },
                             body='')
         if not use_content_length:
             req.environ.pop('CONTENT_LENGTH')
         if use_transfer_encoding:
             req.environ['HTTP_TRANSFER_ENCODING'] = 'chunked'
         status, headers, body = self.call_s3api(req)
     self.assertEqual(status, '400 Bad Request')
     self.assertEqual(self._get_error_code(body), 'MissingRequestBodyError')