diff --git a/tests/51media/01unicode.pl b/tests/51media/01unicode.pl index b450d4be6..d5f007d57 100644 --- a/tests/51media/01unicode.pl +++ b/tests/51media/01unicode.pl @@ -45,7 +45,7 @@ =head2 upload_test_content my ( $content_id, $content_uri ) = upload_test_content( - $user, filename => "filename", + $user, filename => "filename", $content_type ) -> get; Uploads some test content with the given filename. @@ -55,13 +55,15 @@ =head2 upload_test_content =cut sub upload_test_content { - my ( $user, %params ) = @_; + my ( $user, %params, $content_type) = @_; + + $content_type ||= "application/octet-stream"; $user->http->do_request( method => "POST", full_uri => "/_matrix/media/v3/upload", content => "Test media file", - content_type => "text/plain", + content_type => $content_type, params => { access_token => $user->access_token, @@ -88,14 +90,16 @@ sub upload_test_content =head2 get_media - my ( $content_disposition_params, $content ) = get_media( $http, $content_id ) -> get; + my ( $content_disposition_params, $content ) = get_media( $http, $content_id, $allow_inline_disposition ) -> get; Fetches a piece of media from the server. =cut sub get_media { - my ( $http, $content_id ) = @_; + my ( $http, $content_id, $allow_inline_disposition ) = @_; + + $allow_inline_disposition ||= 0; $http->do_request( method => "GET", @@ -107,7 +111,7 @@ sub get_media my $cd_params; if ( defined $disposition ) { - $cd_params = parse_content_disposition_params( $disposition ); + $cd_params = parse_content_disposition_params( $disposition, $allow_inline_disposition ); } Future->done( $cd_params, $body ); }); @@ -115,7 +119,7 @@ sub get_media push @EXPORT, qw( get_media ); sub parse_content_disposition_params { - my ( $disposition ) = @_; + my ( $disposition, $allow_inline_disposition ) = @_; my @parts = split_header_words( $disposition ); # should be only one list of words @@ -125,7 +129,14 @@ sub parse_content_disposition_params { # the first part must be 'attachment' my $k = shift @parts; my $v = shift @parts; - assert_eq( $k, "attachment", "content-disposition" ); + + if ($allow_inline_disposition) { + assert_ok( $k eq "attachment" or $k eq "inline", "content-disposition"); + } + else { + assert_eq( $k, "attachment", "content-disposition" ); + } + die "invalid CD" if defined $v; my %params; diff --git a/tests/51media/02nofilename.pl b/tests/51media/02nofilename.pl index 968a7a6cb..b5a2b17f2 100644 --- a/tests/51media/02nofilename.pl +++ b/tests/51media/02nofilename.pl @@ -6,7 +6,7 @@ do => sub { my ( $user ) = @_; - upload_test_content( $user, )->then( sub { + upload_test_content( $user )->then( sub { ( $content_id ) = @_; Future->done(1) }); @@ -19,7 +19,7 @@ sub test_using_client { my ( $client ) = @_; - get_media( $client, $content_id )->then( sub { + get_media( $client, $content_id, 0 )->then( sub { my ( $disposition ) = @_; # Require `attachment` `Content-Disposition` without a filename portion. diff --git a/tests/51media/04inline.pl b/tests/51media/04inline.pl new file mode 100644 index 000000000..e20715574 --- /dev/null +++ b/tests/51media/04inline.pl @@ -0,0 +1,17 @@ +my $content_id; + +# This test ensures an uploaded file may optionally be rendered inline +# in the browser. This is checked in get_media + +test "Can download a file that optionally inlines", + requires => [ $main::API_CLIENTS[0], local_user_fixture() ], + + check => sub { + my ( $http, $user ) = @_; + upload_test_content( $user, {} , "text/plain")->then( sub { + ( $content_id ) = @_; + get_media( $http, $content_id, 1 )->then( sub { + Future->done(1); + }) + }); + };