AWS-S3
view release on metacpan or search on metacpan
0.15 2018-04-20
- More fixes for ->add_bucket. Fix an error when no location is provided or
us-east-1 is explicitly asked for. Patch by Dave Rolsky. (GH #9)
0.14 2018-04-13
- Fix sending of undefined location param in ->add_bucket (GH #9)
0.13 2017-02-06
- Add documentation for parameter 'prefix' for AWS::S3::FileIterator
- Add test coverage (GH #8, thanks to simbabque for these changes)
- Fix over encoding of characters in path (GH #6)
0.12 2016-03-07
- Fix DNS bucket name checking for non-valid DNS bucket nams (GH #4)
- Fix URI escaping for filenames to avoid infinite loop on spaces (GH #5)
0.11 2015-08-31
- Fix signed_url to URI escape the Signature param value (GH #3)
0.10 2015-06-23
- dist changes related to kwalitee (no functional changes)
lib/AWS/S3/Request/DeleteMulti.pm view on Meta::CPAN
sub request {
my $s = shift;
# keys are arbitrary strings so must be escaped, otherwise a crafted key
# can inject extra <Object> elements and delete unintended objects
my $objects = join "\n",
map { '<Object><Key>' . $s->_xml_escape( $_ ) . '</Key></Object>' }
@{ $s->keys };
my $xml = <<"XML";
<?xml version="1.0" encoding="UTF-8"?>
<Delete>
$objects
</Delete>
XML
$s->_send_request(
POST => $s->_uri => {
Date => $s->_http_date,
'content-md5' => $s->_content_md5( $xml ),
},
lib/AWS/S3/Roles/Request.pm view on Meta::CPAN
my $m = $self->meta;
my $uri = URI->new(
$self->protocol . '://'
. ( $m->has_attribute('bucket') ? $self->bucket . '.' : '' )
. $self->endpoint
. '/'
);
# note we add some extra exceptions to uri_escape to prevent
# encoding of things like "/", ":", "="
if ( $m->has_attribute('key') ) {
my $escaped_path = $self->_escape_key( $self->key );
# if we have a leading slash in the key name we need to add *another*
# slash in the call to ->path to ensure it is retained
if ( $escaped_path =~ m!^/! && $self->s3->honor_leading_slashes ) {
$uri->path( '/'.$escaped_path )
} else {
$uri->path( $escaped_path )
}
lib/AWS/S3/Roles/Request.pm view on Meta::CPAN
sub _uri_escape {
my ( $s, $str, $unsafe ) = @_;
return '' unless defined $str;
utf8::encode( $str ) if $str =~ /[^\x00-\xFF]/;
return defined $unsafe ? uri_escape( $str, $unsafe ) : uri_escape( $str );
}
# Escape an object key for use as the path of a URI; note we add some extra
# exceptions to uri_escape to prevent encoding of things like "/", ":", "="
sub _escape_key {
my ( $s, $key ) = @_;
return $s->_uri_escape( $key, "^A-Za-z0-9\-\._~\/:=" );
}
sub _send_request {
my ( $s, $method, $uri, $headers, $content ) = @_;
$LOG->debug('Making AWS request', {method => $method, uri => "$uri"});
local *LWP::UserAgent::Determined::request = sub {
return Mocked::HTTP::Response->new( 400,$xml );
};
throws_ok { $s3->add_bucket( name => 'too-many-buckets', location => 'us-west-1' ) }
qr/TooManyBuckets/, 'add_bucket throws an error';
}
__DATA__
@@ ListAllMyBucketsResult.xml
<?xml version="1.0" encoding="UTF-8"?>
<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Owner>
<ID>bcaf1ffd86f41161ca5fb16fd081034f</ID>
<DisplayName>webfile</DisplayName>
</Owner>
<Buckets>
<Bucket>
<Name>foo</Name>
<CreationDate>2006-02-03T16:45:09.000Z</CreationDate>
</Bucket>
<Bucket>
<Name>bar</Name>
<CreationDate>2006-02-03T16:41:58.000Z</CreationDate>
</Bucket>
</Buckets>
</ListAllMyBucketsResult>
@@ error.xml
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>TooManyBuckets</Code>
<Message>You have attempted to create more buckets than allowed.</Message>
<Resource>/mybucket</Resource>
<RequestId>4442587FB7D0A2F9</RequestId>
</Error>
@@ ListAllMyBucketsResult-noxmlns.xml
<ListAllMyBucketsResult>
<Owner>
<ID>bcaf1ffd86f41161ca5fb16fd081034f</ID>
t/aws/s3/file_iterator.t view on Meta::CPAN
is( $iterator->next_page->[0]->key,8,'... file 8' );
is( $iterator->next_page->[0]->key,9,'... file 9' );
is( $iterator->next_page->[0]->key,0,'do a new request and get file 0' );
is( $number_of_request,2,'did two requests' );
};
done_testing();
__DATA__
@@ ListBucketResult.xml
<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Name>bucket</Name>
<Prefix>img</Prefix>
<Marker/>
<MaxKeys>1000</MaxKeys>
<IsTruncated>false</IsTruncated>
<Contents>
<Key>img/my image.jpg</Key>
<LastModified>2009-10-12T17:50:30.000Z</LastModified>
<ETag>"fba9dede5f27731c9771645a39863328"</ETag>
t/aws/s3/file_iterator.t view on Meta::CPAN
</ListBucketResult>
@@ EmptyResult
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Name>bucket</Name>
<Prefix/>
<Marker/>
<MaxKeys>1000</MaxKeys>
<IsTruncated>false</IsTruncated>
</ListBucketResult>
@@ LongResult
<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Name>bucket</Name>
<Prefix/>
<Marker/>
<MaxKeys>1000</MaxKeys>
<IsTruncated>true</IsTruncated>
<Contents>
<Key>0</Key>
<LastModified>2009-10-12T17:50:30.000Z</LastModified>
<ETag>"fba9dede5f27731c9771645a39863328"</ETag>
t/aws/s3/response_parser.t view on Meta::CPAN
note( "a response with a DOCTYPE is refused when checking for errors" );
{
eval { _parser( $xxe, code => 400, expect_nothing => 1 ) };
like( $@, qr/DOCTYPE/, 'dies rather than parse it' );
unlike( $@, qr/TOP-SECRET/, '... and the file was not read' );
}
note( "error responses still work" );
{
my $error = <<'XML';
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>TooManyBuckets</Code>
<Message>You have attempted to create more buckets than allowed.</Message>
</Error>
XML
my $parser = _parser( $error, code => 400, expect_nothing => 1 );
is( $parser->error_code, 'TooManyBuckets', 'error code parsed' );
like( $parser->friendly_error, qr/TooManyBuckets.*more buckets than allowed/, 'friendly_error' );
}
( run in 1.170 second using v1.01-cache-2.11-cpan-39bc3f1cbff )