Skip to content

Commit

Permalink
Add tests for filenames with spaces and semicolons
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Feb 27, 2019
1 parent 9452b01 commit 5c1f1e7
Showing 1 changed file with 46 additions and 48 deletions.
94 changes: 46 additions & 48 deletions tests/51media/03ascii.pl
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,48 @@
});
};

# These next two tests do the same thing with two different HTTP clients, to
# test locally and via federation

sub test_using_client
{
my ( $client ) = @_;

get_media( $client, $content_id )->then( sub {
my ( $disposition ) = @_;

$disposition eq "inline; filename=ascii" or
die "Expected an ASCII filename parameter";

Future->done(1);
});
# we only need one user for these tests
my $user_fixture = local_user_fixture();

my %TEST_CASES = (
"ascii" => "inline; filename=ascii",

# synapse uses filename* encoding for this, though regular filename encoding
# with a quoted string would be valid too
"name with spaces" => "inline; filename*=utf-8''name%20with%20spaces",

"name;with;semicolons" => "inline; filename*=utf-8''name%3Bwith%3Bsemicolons",
);

while ( my ( $filename, $expected_disposition ) = each %TEST_CASES ) {
test "Can download file '$filename'",
requires => [
$user_fixture, $main::API_CLIENTS[1]
],

check => sub {
my ( $user, $federation_client ) = @_;

my $content_id;

# first upload the content with the given filename
upload_test_content( $user, $filename )->then( sub {
( $content_id ) = @_;

# try and fetch it as a local user
get_media( $user->http, $content_id );
})->then( sub {
assert_eq( $_[0], $expected_disposition );

# do the same over federation
get_media( $federation_client, $content_id );
})->then( sub {
assert_eq( $_[0], $expected_disposition );
Future->done(1);
});
};
}

test "Can download with ASCII file name locally",
requires => [ $main::API_CLIENTS[0] ],

check => sub {
my ( $http ) = @_;
test_using_client( $http )
->then( sub {
test_using_client( $http )
});
};

test "Can download with ASCII file name over federation",
requires => [ $main::API_CLIENTS[1] ],

check => sub {
my ( $http ) = @_;
test_using_client( $http )
->then( sub {
test_using_client( $http )
});
};

test "Can download specifying a different ASCII file name",
requires => [ $main::API_CLIENTS[0] ],
Expand All @@ -76,25 +80,19 @@ sub test_using_client

check => sub {
my ( $http, $user, $room_id ) = @_;
test_using_client( $http )
->then( sub {
matrix_send_room_message( $user, $room_id,
content => { msgtype => "m.file", body => "test.txt", url => $content_uri }
)
});
matrix_send_room_message( $user, $room_id,
content => { msgtype => "m.file", body => "test.txt", url => $content_uri }
);
};

test "Can fetch images in room",
requires => [ $main::API_CLIENTS[0], local_user_and_room_fixtures() ],

check => sub {
my ( $http, $user, $room_id ) = @_;
test_using_client( $http )
->then( sub {
matrix_send_room_message_synced( $user, $room_id,
content => { msgtype => "m.text", body => "test" }
)
})->then( sub {
matrix_send_room_message_synced( $user, $room_id,
content => { msgtype => "m.text", body => "test" }
)->then( sub {
matrix_send_room_message_synced( $user, $room_id,
content => { msgtype => "m.file", body => "test.txt", url => $content_uri }
)
Expand Down

0 comments on commit 5c1f1e7

Please sign in to comment.