File: aws.t

package info (click to toggle)
libwebservice-s3-tiny-perl 0.003-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 852 kB
  • sloc: perl: 137; sh: 5; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,249 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use warnings;

BEGIN { *CORE::GLOBAL::gmtime = sub(;$) { CORE::gmtime(1440938160) } }

use HTTP::Request;
use Test::More;
use WebService::S3::Tiny;

{
    no warnings 'redefine';

    *HTTP::Tiny::request = sub { $_[3]{headers}{authorization} };
}

sub slurp($) { local ( @ARGV, $/ ) = @_; scalar <> }

my $s3 = WebService::S3::Tiny->new(
    access_key => 'AKIDEXAMPLE',
    host       => 'example.amazonaws.com',
    region     => 'us-east-1',
    secret_key => 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY',
    service    => 'service',
);

chdir 't/aws';

for (<{get,post}-*>) {
    utf8::decode my $foo = slurp "$_/$_.req";

    my ( $method, $path, $headers ) =
        $foo =~ m(^(GET|POST) (.+) HTTP/1.1\n(.+))s;

    ( $path, my $query ) = split /\?/, $path;

    my @query = split /&/, ( $query // '' );
    @query = map { split /=/, $_, 2 } sort @query;

    ( $headers, my $content ) = split /\n\n/, $headers;

    my $req = HTTP::Request->parse( slurp "$_/$_.req" );

    my %headers = %{ $req->headers };

    delete $headers{'::std_case'};

    is +$s3->request(
        $req->method,
        $path,
        undef,
        $req->content,
        \%headers,
        \@query,
    ) => slurp "$_/$_.authz", $_;
}

done_testing;