AWS-Signature-V4
view release on metacpan or search on metacpan
eg/10-s3-content-encoding-probe.pl view on Meta::CPAN
# list, and the run already went and collected that: the Content-Encoding
# it kept, and whether the bytes came back as they were sent
my $confirmed = $gzip_case->{ok}
&& lc($gzip_case->{stored} // '') eq 'gzip'
&& ($gzip_case->{body} // '') eq 'identical';
# and a failure is only an answer when S3 itself refused the request. The
# control having gone through says nothing about the one after it: a 503
# SlowDown, a 500, a dropped connection or a key that expired in between
# would otherwise be read as a verdict on the order, and this report
# would send someone to change the signing code over a bad afternoon
my $put_status = $gzip_case->{status} // 0; # unset in a dry run, and
# if the preflight stopped
my $refused = !$gzip_case->{ok}
&& $put_status >= 400 && $put_status < 500
# 401 and 403 are answers about the credentials, not about the header:
# a key that expired between the control and this upload would land
# here, and it is not the ordering that was turned down
&& $put_status != 401 && $put_status != 403
&& defined $gzip_case->{s3_code};
my $status = 0;
if ($ENV{DRY_RUN}) {
push @out, 'verdict: nothing was sent (DRY_RUN): the announced length';
push @out, ' must equal the body size in both cases above';
}
elsif (!$control->{ok}) {
push @out, 'verdict: INCONCLUSIVE. The control upload failed, so this run';
push @out, ' says nothing about the ordering: check the bucket, the';
push @out, ' region and the credentials, then run it again.';
$status = 1;
}
elsif ($confirmed) {
push @out, "verdict: S3 accepted $gzip_case->{sent}, stored it as";
push @out, " Content-Encoding: $gzip_case->{stored}, and gave the";
push @out, ' bytes back unchanged.';
}
elsif ($gzip_case->{ok}) {
push @out, "verdict: INCONCLUSIVE. S3 took $gzip_case->{sent}, but what it";
push @out, ' stored is not what this probe expects: read the stored';
push @out, ' Content-Encoding and the body line above, because the';
push @out, ' upload being accepted is then not the whole story.';
$status = 1;
}
elsif ($refused) {
push @out, "verdict: S3 REJECTED $gzip_case->{sent} with $gzip_case->{s3_code},";
push @out, " while accepting $control->{sent} alone, so the order is";
push @out, ' the problem. Swap the last line of the $streaming';
push @out, ' branch in lib/AWS/Signature/V4.pm to';
push @out, q{ join ',', 'aws-chunked', @encodings;};
push @out, ' update V4.pod and t/streaming.t to match, and run';
push @out, ' this program again to confirm the other order.';
$status = 1;
}
else {
push @out, 'verdict: INCONCLUSIVE. The gzip upload failed, but not with a';
push @out, ' refusal from S3, so it says nothing about the order:';
push @out, ' see the error line above, then run it again.';
$status = 1;
}
# the keys themselves go on stderr, outside the block that gets pasted
my @leftover = grep { defined } map { $_->{leftover} } @cases;
if (@leftover) {
push @out, '', sprintf 'note: %d object%s left behind, delete %s by hand',
scalar @leftover, @leftover == 1 ? '' : 's', @leftover == 1 ? 'it' : 'them';
warn "could not delete: $_\n" for @leftover;
}
push @out, '-------------------------------------------------------';
say for @out;
exit $status;
( run in 0.926 second using v1.01-cache-2.11-cpan-60884a8df76 )