예제 #1
0
 def test_presigned_post_throws_unsupported_signature_error(self):
     self.request_signer = RequestSigner(
         'service_name', 'region_name', 'signing_name',
         'foo', self.credentials, self.emitter)
     self.signer = S3PostPresigner(self.request_signer)
     with self.assertRaises(UnsupportedSignatureVersionError):
         self.signer.generate_presigned_post({})
예제 #2
0
    def setUp(self):
        super(TestS3PostPresigner, self).setUp()
        self.request_signer = RequestSigner(
            ServiceId('service_name'), 'region_name', 'signing_name',
            's3v4', self.credentials, self.emitter)
        self.signer = S3PostPresigner(self.request_signer)
        self.request_dict = {
            'headers': {},
            'url': 'https://s3.amazonaws.com/mybucket',
            'body': b'',
            'url_path': '/',
            'method': 'POST',
            'context': {}
        }
        self.auth = mock.Mock()
        self.auth.REQUIRES_REGION = True
        self.add_auth = mock.Mock()
        self.auth.return_value.add_auth = self.add_auth
        self.fixed_credentials = self.credentials.get_frozen_credentials()

        self.datetime_patch = mock.patch('botocore.signers.datetime')
        self.datetime_mock = self.datetime_patch.start()
        self.fixed_date = datetime.datetime(2014, 3, 10, 17, 2, 55, 0)
        self.fixed_delta = datetime.timedelta(seconds=3600)
        self.datetime_mock.datetime.utcnow.return_value = self.fixed_date
        self.datetime_mock.timedelta.return_value = self.fixed_delta
예제 #3
0
    def test_generate_presigned_post_fixes_s3_host(self):
        self.request_signer = RequestSigner(
            'service_name', 'region_name', 'signing_name',
            's3', self.credentials, self.emitter)
        self.signer = S3PostPresigner(self.request_signer)

        with mock.patch.dict(botocore.auth.AUTH_TYPE_MAPS,
                             {'s3-presign-post': self.auth}):
            post_form_args = self.signer.generate_presigned_post(
                self.request_dict)
        self.auth.assert_called_with(
            credentials=self.credentials, region_name='region_name',
            service_name='signing_name')
        self.assertEqual(post_form_args['url'],
                         'https://mybucket.s3.amazonaws.com/')
예제 #4
0
 def test_presigned_post_throws_unsupported_signature_error(self):
     request_dict = {
         'headers': {},
         'url': 'https://s3.amazonaws.com/mybucket/myobject',
         'body': b'',
         'url_path': '/',
         'method': 'POST',
         'context': {}
     }
     self.request_signer = RequestSigner(
         ServiceId('service_name'), 'region_name', 'signing_name',
         'foo', self.credentials, self.emitter)
     self.signer = S3PostPresigner(self.request_signer)
     with self.assertRaises(UnsupportedSignatureVersionError):
         self.signer.generate_presigned_post(request_dict)