5 use Test::More tests => 21; # last test to print
10 $module = 'Net::Amazon::S3::Policy';
15 my $expiration = '1220292602';
16 my $policy = $module->new({expiration => $expiration});
18 ok($policy, 'new with expiration time');
19 isa_ok($policy, $module);
20 is($policy->expiration(), '2008-09-01T18:10:02.000Z',
26 q( provaxxx starts-with ciao ),
27 q( 0 <= something <= 123312391 ),
29 q( anything2 starts_with ),
30 q( anything2 starts_with blah ),
33 my $conditions = $policy->conditions();
34 ok($conditions, 'conditions exists');
35 is(scalar(@$conditions), 6, 'all conditions added');
39 [qw( eq $prova ciao )],
40 [qw( starts-with $provaxxx ciao )],
41 [qw( something 0 123312391 )],
42 [qw( starts-with $anything ), ''],
43 [qw( starts-with $anything2 ), ''],
44 [qw( starts-with $anything2 blah )],
50 '{"conditions":[["eq","$prova","ciao"],["starts-with","$provaxxx","ciao"],["something","0","123312391"],["starts-with","$anything",""],["starts-with","$anything2",""],["starts-with","$anything2","blah"]],"expiration":"2008-09-01T18:10:02.000Z"}';
51 is($policy->stringify({canonical => 1}), $expected_json, 'JSON generation');
56 '{"conditions":[["eq","$prova","ciao"],["starts-with","$provaxxx","ciao"],["something","0","123312391"],["starts-with","$anything",""],["starts-with","$anything2",""],["starts-with","$anything2","blah"],{"what":"this"}],"expiration":"2008-09-01T18:10:02.000Z"}';
58 my $policy = Net::Amazon::S3::Policy->new(json => $json);
59 ok($policy, 'new with expiration time');
60 isa_ok($policy, $module);
61 is($policy->expiration(), '2008-09-01T18:10:02.000Z',
64 my $conditions = $policy->conditions();
65 ok($conditions, 'conditions exists');
66 is(scalar(@$conditions), 7, 'all conditions present');
70 [qw( eq $prova ciao )],
71 [qw( starts-with $provaxxx ciao )],
72 [qw( something 0 123312391 )],
73 [qw( starts-with $anything ), ''],
74 [qw( starts-with $anything2 ), ''],
75 [qw( starts-with $anything2 blah )],
76 [qw( eq $what this )],
84 '{"conditions":[["eq","$prova","ciao"],["starts-with","$provaxxx","ciaoBLACKHEART"],["something","0","123312391"],["starts-with","$anything",""],["starts-with","$anything2",""],["starts-with","$anything2","blah"],{"what":"this"}],"expiration":"2008-09-01T18:10:02.000Z"}';
85 $json =~ s/BLACKHEART/\x{2665}/mxs;
87 my $policy = Net::Amazon::S3::Policy->new(json => $json);
88 ok($policy, 'new with expiration time');
89 isa_ok($policy, $module);
90 is($policy->expiration(), '2008-09-01T18:10:02.000Z',
93 my $conditions = $policy->conditions();
94 ok($conditions, 'conditions exists');
95 is(scalar(@$conditions), 7, 'all conditions present');
99 [qw( eq $prova ciao )],
100 [qw( starts-with $provaxxx ), "ciao\x{2665}"],
101 [qw( something 0 123312391 )],
102 [qw( starts-with $anything ), ''],
103 [qw( starts-with $anything2 ), ''],
104 [qw( starts-with $anything2 blah )],
105 [qw( eq $what this )],
110 my $base64 = 'undefined';
111 eval { $base64 = $policy->base64({canonical => 1}); };
112 my $expected_base64 = 'eyJjb25kaXRpb25zIjpbWyJlcSIsIiRwcm92YSIsImNpYW8iXSxbInN0YXJ0cy13aXRoIiwiJHByb3ZheHh4IiwiY2lhb+KZpSJdLFsic29tZXRoaW5nIiwiMCIsIjEyMzMxMjM5MSJdLFsic3RhcnRzLXdpdGgiLCIkYW55dGhpbmciLCIiXSxbInN0YXJ0cy13aXRoIiwiJGFueXRoaW5nMiIsIiJdLFsic3RhcnRzLXdpdGgiLCIkYW55dGhpbmcyIiwiYmxhaCJdLFsiZXEiLCIkd2hhdCIsInRoaXMiXV0sImV4cGlyYXRpb24iOiIyMDA4LTA5LTAxVDE4OjEwOjAyLjAwMFoifQ==';
113 is($base64, $expected_base64, 'base64 encoding');