def test_put_bucket_error(self): event_system = self.conn.meta.events event_system.unregister('before-parameter-build.s3', botocore.handlers.validate_bucket_name) with self.assertRaises(botocore.exceptions.ClientError) as ctx: self.conn.create_bucket(Bucket='bucket+invalid') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 400) self.assertEqual(ctx.exception.response['Error']['Code'], 'InvalidBucketName') auth_error_conn = get_boto3_conn(tf.config['s3_access_key'], 'invalid') with self.assertRaises(botocore.exceptions.ClientError) as ctx: auth_error_conn.create_bucket(Bucket='bucket') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 403) self.assertEqual(ctx.exception.response['Error']['Code'], 'SignatureDoesNotMatch') self.conn.create_bucket(Bucket='bucket') with self.assertRaises(botocore.exceptions.ClientError) as ctx: self.conn.create_bucket(Bucket='bucket') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 409) self.assertEqual(ctx.exception.response['Error']['Code'], 'BucketAlreadyOwnedByYou')
def test_head_bucket_error(self): event_system = self.conn.meta.events event_system.unregister('before-parameter-build.s3', botocore.handlers.validate_bucket_name) self.conn.create_bucket(Bucket='bucket') with self.assertRaises(botocore.exceptions.ClientError) as ctx: self.conn.head_bucket(Bucket='bucket+invalid') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 400) self.assertEqual(ctx.exception.response['Error']['Code'], '400') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPHeaders'] ['content-length'], '0') auth_error_conn = get_boto3_conn(tf.config['s3_access_key'], 'invalid') with self.assertRaises(botocore.exceptions.ClientError) as ctx: auth_error_conn.head_bucket(Bucket='bucket') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 403) self.assertEqual(ctx.exception.response['Error']['Code'], '403') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPHeaders'] ['content-length'], '0') with self.assertRaises(botocore.exceptions.ClientError) as ctx: self.conn.head_bucket(Bucket='nothing') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 404) self.assertEqual(ctx.exception.response['Error']['Code'], '404') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPHeaders'] ['content-length'], '0')
def test_put_bucket_error(self): event_system = self.conn.meta.events event_system.unregister( 'before-parameter-build.s3', botocore.handlers.validate_bucket_name) with self.assertRaises(botocore.exceptions.ClientError) as ctx: self.conn.create_bucket(Bucket='bucket+invalid') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 400) self.assertEqual( ctx.exception.response['Error']['Code'], 'InvalidBucketName') auth_error_conn = get_boto3_conn(aws_secret_key='invalid') with self.assertRaises(botocore.exceptions.ClientError) as ctx: auth_error_conn.create_bucket(Bucket='bucket') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 403) self.assertEqual(ctx.exception.response['Error']['Code'], 'SignatureDoesNotMatch') self.conn.create_bucket(Bucket='bucket') with self.assertRaises(botocore.exceptions.ClientError) as ctx: self.conn.create_bucket(Bucket='bucket') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 409) self.assertEqual( ctx.exception.response['Error']['Code'], 'BucketAlreadyOwnedByYou')
def setUp(self): if 's3api' not in tf.cluster_info: raise tf.SkipTest('s3api middleware is not enabled') try: self.conn = get_boto3_conn() self.endpoint_url = self.conn._endpoint.host self.access_key = self.conn._request_signer._credentials.access_key self.region = self.conn._client_config.region_name tear_down_s3(self.conn) except Exception: message = '%s got an error during initialize process.\n\n%s' % \ (self.method_name, traceback.format_exc()) # TODO: Find a way to make this go to FAIL instead of Error self.fail(message)
def setUp(self): if 's3api' not in tf.cluster_info: raise tf.SkipTest('s3api middleware is not enabled') try: self.conn = get_boto3_conn() self.endpoint_url = self.conn._endpoint.host self.access_key = self.conn._request_signer._credentials.access_key self.region = self.conn._client_config.region_name tear_down_s3(self.conn) except Exception: message = '%s got an error during initialize process.\n\n%s' % \ (self.method_name, traceback.format_exc()) # TODO: Find a way to make this go to FAIL instead of Error self.fail(message)
def test_put_bucket_error_key3(self): if 's3_access_key3' not in tf.config or \ 's3_secret_key3' not in tf.config: raise tf.SkipTest('Cannot test for AccessDenied; need ' 's3_access_key3 and s3_secret_key3 configured') self.conn.create_bucket(Bucket='bucket') # If the user can't create buckets, they shouldn't even know # whether the bucket exists. conn3 = get_boto3_conn(tf.config['s3_access_key3'], tf.config['s3_secret_key3']) with self.assertRaises(botocore.exceptions.ClientError) as ctx: conn3.create_bucket(Bucket='bucket') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 403) self.assertEqual(ctx.exception.response['Error']['Code'], 'AccessDenied')
def test_put_bucket_error_key3(self): if 's3_access_key3' not in tf.config or \ 's3_secret_key3' not in tf.config: raise tf.SkipTest('Cannot test for AccessDenied; need ' 's3_access_key3 and s3_secret_key3 configured') self.conn.create_bucket(Bucket='bucket') # If the user can't create buckets, they shouldn't even know # whether the bucket exists. conn3 = get_boto3_conn(tf.config['s3_access_key3'], tf.config['s3_secret_key3']) with self.assertRaises(botocore.exceptions.ClientError) as ctx: conn3.create_bucket(Bucket='bucket') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 403) self.assertEqual( ctx.exception.response['Error']['Code'], 'AccessDenied')
def test_delete_bucket_error(self): event_system = self.conn.meta.events event_system.unregister('before-parameter-build.s3', botocore.handlers.validate_bucket_name) with self.assertRaises(botocore.exceptions.ClientError) as ctx: self.conn.delete_bucket(Bucket='bucket+invalid') self.assertEqual(ctx.exception.response['Error']['Code'], 'InvalidBucketName') auth_error_conn = get_boto3_conn(tf.config['s3_access_key'], 'invalid') with self.assertRaises(botocore.exceptions.ClientError) as ctx: auth_error_conn.delete_bucket(Bucket='bucket') self.assertEqual(ctx.exception.response['Error']['Code'], 'SignatureDoesNotMatch') with self.assertRaises(botocore.exceptions.ClientError) as ctx: self.conn.delete_bucket(Bucket='bucket') self.assertEqual(ctx.exception.response['Error']['Code'], 'NoSuchBucket')
def test_put_bucket_error_key2(self): if config_true_value(tf.cluster_info['s3api'].get('s3_acl')): if 's3_access_key2' not in tf.config or \ 's3_secret_key2' not in tf.config: raise tf.SkipTest( 'Cannot test for BucketAlreadyExists with second user; ' 'need s3_access_key2 and s3_secret_key2 configured') self.conn.create_bucket(Bucket='bucket') # Other users of the same account get the same 409 error conn2 = get_boto3_conn(tf.config['s3_access_key2'], tf.config['s3_secret_key2']) with self.assertRaises(botocore.exceptions.ClientError) as ctx: conn2.create_bucket(Bucket='bucket') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 409) self.assertEqual(ctx.exception.response['Error']['Code'], 'BucketAlreadyExists')
def test_delete_bucket_error(self): event_system = self.conn.meta.events event_system.unregister( 'before-parameter-build.s3', botocore.handlers.validate_bucket_name) with self.assertRaises(botocore.exceptions.ClientError) as ctx: self.conn.delete_bucket(Bucket='bucket+invalid') self.assertEqual( ctx.exception.response['Error']['Code'], 'InvalidBucketName') auth_error_conn = get_boto3_conn(aws_secret_key='invalid') with self.assertRaises(botocore.exceptions.ClientError) as ctx: auth_error_conn.delete_bucket(Bucket='bucket') self.assertEqual( ctx.exception.response['Error']['Code'], 'SignatureDoesNotMatch') with self.assertRaises(botocore.exceptions.ClientError) as ctx: self.conn.delete_bucket(Bucket='bucket') self.assertEqual( ctx.exception.response['Error']['Code'], 'NoSuchBucket')
def test_put_bucket_error_key2(self): if config_true_value(tf.cluster_info['s3api'].get('s3_acl')): if 's3_access_key2' not in tf.config or \ 's3_secret_key2' not in tf.config: raise tf.SkipTest( 'Cannot test for BucketAlreadyExists with second user; ' 'need s3_access_key2 and s3_secret_key2 configured') self.conn.create_bucket(Bucket='bucket') # Other users of the same account get the same 409 error conn2 = get_boto3_conn(tf.config['s3_access_key2'], tf.config['s3_secret_key2']) with self.assertRaises(botocore.exceptions.ClientError) as ctx: conn2.create_bucket(Bucket='bucket') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 409) self.assertEqual( ctx.exception.response['Error']['Code'], 'BucketAlreadyExists')
def test_head_bucket_error(self): event_system = self.conn.meta.events event_system.unregister( 'before-parameter-build.s3', botocore.handlers.validate_bucket_name) self.conn.create_bucket(Bucket='bucket') with self.assertRaises(botocore.exceptions.ClientError) as ctx: self.conn.head_bucket(Bucket='bucket+invalid') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 400) self.assertEqual(ctx.exception.response['Error']['Code'], '400') self.assertEqual( ctx.exception.response[ 'ResponseMetadata']['HTTPHeaders']['content-length'], '0') auth_error_conn = get_boto3_conn(aws_secret_key='invalid') with self.assertRaises(botocore.exceptions.ClientError) as ctx: auth_error_conn.head_bucket(Bucket='bucket') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 403) self.assertEqual( ctx.exception.response['Error']['Code'], '403') self.assertEqual( ctx.exception.response[ 'ResponseMetadata']['HTTPHeaders']['content-length'], '0') with self.assertRaises(botocore.exceptions.ClientError) as ctx: self.conn.head_bucket(Bucket='nothing') self.assertEqual( ctx.exception.response['ResponseMetadata']['HTTPStatusCode'], 404) self.assertEqual( ctx.exception.response['Error']['Code'], '404') self.assertEqual( ctx.exception.response[ 'ResponseMetadata']['HTTPHeaders']['content-length'], '0')