Commit | Line | Data |
7ad87df9 |
1 | use strict; |
2 | use warnings; |
10018fb4 |
3 | use Test::More; |
7ad87df9 |
4 | use FindBin; |
5 | |
e601adda |
6 | use lib ( "$FindBin::Bin/lib", "$FindBin::Bin/../lib" ); |
7ad87df9 |
7 | use Test::Rest; |
8 | |
e601adda |
9 | use_ok 'Catalyst::Test', 'Test::Serialize'; |
10 | |
11 | my %ctypes =( |
12 | 'text/x-data-dumper' => 'Data::Dumper' , |
13 | 'text/x-data-denter' => 'Data::Denter' , |
14 | 'text/x-data-taxi' => 'Data::Taxi' , |
15 | 'application/x-storable' => 'Storable' , |
16 | 'application/x-freezethaw' => 'FreezeThaw' , |
17 | 'text/x-config-general' => 'Config::General' , |
18 | 'text/x-php-serialization' => 'PHP::Serialization' , |
19 | ); |
20 | |
21 | my $has_serializer = eval "require Data::Serializer"; |
22 | |
23 | foreach my $content_type (keys(%ctypes)) { |
24 | my $dso; |
25 | my $skip = 0; |
26 | my $loadclass = $ctypes{$content_type}; |
27 | $loadclass =~ s/::/\//g; |
28 | $loadclass .= '.pm'; |
29 | eval { |
30 | require $loadclass |
31 | }; |
32 | if ($@) { |
33 | $skip = 1; |
34 | } |
35 | SKIP: { |
36 | skip "$ctypes{$content_type} not installed", 4 if $skip; |
37 | $dso = Data::Serializer->new( serializer => $ctypes{$content_type} ); |
38 | my $t = Test::Rest->new( 'content_type' => $content_type ); |
39 | |
40 | my $monkey_template = { monkey => 'likes chicken!', }; |
41 | my $mres = request( $t->get( url => '/monkey_get' ) ); |
42 | ok( $mres->is_success, "GET $content_type succeeded" ); |
43 | is_deeply( $dso->raw_deserialize( $mres->content ), |
44 | $monkey_template, "GET $content_type has the right data" ); |
45 | |
46 | my $post_data = { 'sushi' => 'is good for monkey', }; |
47 | my $mres_post = request( |
48 | $t->post( |
49 | url => '/monkey_put', |
50 | data => $dso->raw_serialize($post_data) |
51 | ) |
52 | ); |
53 | ok( $mres_post->is_success, "POST $content_type succeeded" ); |
54 | is_deeply( |
55 | $mres_post->content, |
56 | "is good for monkey", |
57 | "POST $content_type data matches" |
58 | ); |
59 | } |
60 | } |
7ad87df9 |
61 | |
0fd45d2a |
62 | { |
63 | my $t = Test::Rest->new( 'content_type' => 'text/x-data-dumper' ); |
64 | |
65 | my $post_data = "{ 'sushi' => die('hack attempt') }"; |
66 | my $mres_post = request( |
67 | $t->post( |
68 | url => '/monkey_put', |
69 | data => $post_data, |
70 | ) |
71 | ); |
72 | ok( ! $mres_post->is_success, "POST Data::Dumper fails due to invalid input" ); |
73 | like( |
74 | $mres_post->content, |
75 | qr%Content-Type text/x-data-dumper had a problem with your request.*'die' trapped by operation mask%s, |
76 | "POST Data::Dumper data error matches" |
77 | ); |
78 | } |
79 | |
7ad87df9 |
80 | 1; |
10018fb4 |
81 | |
82 | done_testing; |