Debian Codegraph @

t/multipart_content.t

raw
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Plack::Test;
6 use HTTP::Request::Common;
7 use Ref::Util qw<is_coderef>;
8
9 {
10 package App;
11 use Dancer2;
12
13 get '/' => sub {1};
14 }
15
16 #
17 # Test for this issue: https://github.com/PerlDancer/Dancer2/issues/1507
18 # When a request comes with Content-Type: multipart/form-data with no boundary,
19 # Dancer currently wrongly returns HTTP code 500 Internal Server Error.
20 # It should return HTTP code 400 Bad Request.
21 # We also test that a request with Content-Type: multipart/form-data boundary=------boundary-------' returns 200.
22
23 my $app = App->to_app;
24 ok( is_coderef($app), 'Got app' );
25
26 test_psgi $app, sub {
27 my $cb = shift;
28
29 is(
30 $cb->( GET '/' => 'Content-Type' => 'multipart/form-data' )->code,
31 400,
32 'multipart with incorrect boundary returns 400',
33 );
34
35 my $headers =
36
37
38 is(
39 $cb->(
40 GET '/' =>
41 'Content-Type' =>
42 'Content-Type: multipart/form-data boundary=------boundary-------',
43 )->code,
44 200,
45 'Providing multipart with correct boundary works',
46 );
47 };
48
49 done_testing();