-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy path48admin-quarantine.pl
85 lines (74 loc) · 2.75 KB
/
48admin-quarantine.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use File::Basename qw( dirname );
use File::Slurper qw( read_binary );
my $dir = dirname __FILE__;
multi_test "Can quarantine media in rooms",
requires => [ local_admin_fixture(), local_user_and_room_fixtures(), remote_user_fixture(),
qw( can_upload_media can_download_media )],
do => sub {
my ( $admin, $user, $room_id, $remote_user ) = @_;
my $pngdata = read_binary( "$dir/test.png" );
my $content_id;
# Because we're POST'ing non-JSON
$user->http->do_request(
method => "POST",
full_uri => "/_matrix/media/v3/upload",
params => {
access_token => $user->access_token,
},
content_type => "image/png",
content => $pngdata,
)->then( sub {
my ( $body ) = @_;
my $content_uri = URI->new( $body->{content_uri} );
my $server = $content_uri->authority;
my $path = $content_uri->path;
$content_id = "$server$path";
matrix_send_room_message( $user, $room_id,
content => {
msgtype => "m.image",
body => "test.png",
url => "$content_uri",
},
);
})->then( sub {
do_request_json_for( $admin,
method => "POST",
full_uri => "/_synapse/admin/v1/room/$room_id/media/quarantine",
content => {},
);
})->SyTest::pass_on_done( "Quarantine returns success" )
->then( sub {
$user->http->do_request(
method => "GET",
full_uri => "/_matrix/media/v3/download/$content_id",
)->main::expect_http_404;
})->SyTest::pass_on_done( "404 on getting quarantined local media" )
->then( sub {
$user->http->do_request(
method => "GET",
full_uri => "/_matrix/media/v3/thumbnail/$content_id",
params => {
width => 32,
height => 32,
method => "scale",
},
)->main::expect_http_404
})->SyTest::pass_on_done( "404 on getting quarantined local thumbnails" )
->then( sub {
$remote_user->http->do_request(
method => "GET",
full_uri => "/_matrix/media/v3/download/$content_id",
)->main::expect_http_404;
})->SyTest::pass_on_done( "404 on getting quarantined remote media" )
->then( sub {
$remote_user->http->do_request(
method => "GET",
full_uri => "/_matrix/media/v3/thumbnail/$content_id",
params => {
width => 32,
height => 32,
method => "scale",
}
)->main::expect_http_404;
})->SyTest::pass_on_done( "404 on getting quarantined remote thumbnails" );
};