Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/SyTest/Federation/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ __PACKAGE__->mk_await_request_pair(
user_devices => [qw( :user_id )],
);

__PACKAGE__->mk_await_request_pair(
user_keys_query => [qw( )],
);

sub on_request_federation_v1_send
{
my $self = shift;
Expand Down
150 changes: 150 additions & 0 deletions tests/50federation/40devicelists.pl
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,153 @@
)
});
};

use Data::Dumper;
test "Device list doesn't change if remote server is down",
requires => [
$main::OUTBOUND_CLIENT,
$main::INBOUND_SERVER,
$main::HOMESERVER_INFO[0],
local_user_fixture,
federation_user_id_fixture(),
qw( can_upload_e2e_keys )
],

check => sub {
my (
$outbound_client,
$inbound_server,
$local_server_info,
$local_user,
$outbound_client_user
) = @_;

my ( $first_keys_query_body, $second_keys_query_body, @respond_503 );

my $client_user_devices = {
user_id => $outbound_client_user,
stream_id => 3,
devices => [{
device_id => "CURIOSITY_ROVER",
keys => {
user_id => $outbound_client_user,
device_id => "CURIOSITY_ROVER",
algorithms => ["fast", "and broken"],
keys => {
"c" => "sharp",
"b" => "flat"
},
signatures => {
$outbound_client_user => {"ed25519:JLAFKJWSCS" => "dSO80A01XiigH3uBiDVx/EjzaoycHcjq9lfQX0uWsqxl2giMIiSPR8a4d291W1ihKJL/a+myXS367WT6NAIcBA"},
},
},
device_display_name => "Curiosity Rover"
}],
};

my $client_user_keys = {
device_keys => {
$outbound_client_user => {
CURIOSITY_ROVER => {
user_id => $outbound_client_user,
device_id => "CURIOSITY_ROVER",
algorithms => ["fast", "and broken"],
keys => {
"c" => "sharp",
"b" => "flat"
},
signatures => {
$outbound_client_user => {"ed25519:JLAFKJWSCS" => "dSO80A01XiigH3uBiDVx/EjzaoycHcjq9lfQX0uWsqxl2giMIiSPR8a4d291W1ihKJL/a+myXS367WT6NAIcBA"}
},
unsigned => {
"device_display_name" => "Curiosity Rover"
},
},
},
},
};


my @respond_with_keys = (
$inbound_server->await_request_user_devices( $outbound_client_user )->then( sub {
my ( $req ) = @_;
$req->respond_json($client_user_devices);
Future->done(1)
}),
$inbound_server->await_request_user_keys_query( $outbound_client_user )->then( sub {
my ( $req ) = @_;
$req->respond_json($client_user_keys);
Future->done(1)
})
);

# First we succesfully request the remote users keys while the remote server is up.
# We do this once they share a room.
matrix_create_room(
$local_user,
preset => "public_chat",
room_version => "5",
)->then( sub {
my ( $room_id ) = @_;
$outbound_client->join_room(
server_name => $local_server_info->server_name,
room_id => $room_id,
user_id => $outbound_client_user,
)
})->then( sub {
do_request_json_for( $local_user,
method => "POST",
uri => "/r0/keys/query",
content => {
device_keys => {
$outbound_client_user => {}
}
}
)
})->then( sub {
( $first_keys_query_body ) = @_;
map {$_->cancel} @respond_with_keys;
log_if_fail (Dumper $first_keys_query_body);

# We take the remote server 'offline' and then make the same request for
# the users keys. We expect no change in the keys.
@respond_503 = (
$inbound_server->await_request_user_devices( $outbound_client_user )->then( sub {
my ( $req ) = @_;
log_if_fail "Responded with 503 to /user/devices request";
$req->respond_json({}, code => 503);
Future->done(1)
}),
$inbound_server->await_request_user_keys_query()->then( sub {
my ( $req ) = @_;
log_if_fail "Responded with 503 to /user/keys/query request";
$req->respond_json({}, code => 503);
Future->done(1)
})
);
do_request_json_for( $local_user,
method => "POST",
uri => "/r0/keys/query",
content => {
device_keys => {
$outbound_client_user => {}
}
}
)
})->then( sub {
( $second_keys_query_body ) = @_;
map {$_->cancel} @respond_503;
# The unsiged field is optional in the spec so we remove it from any response.
foreach ($first_keys_query_body, $second_keys_query_body) {
while (my ($user_key, $devices) = each %{$_->{ device_keys }} ) {
while (my ($device_key, $values) = each %$devices) {
delete $values->{ unsigned };
}
}
};

log_if_fail (Dumper $second_keys_query_body);
assert_deeply_eq( $second_keys_query_body, $first_keys_query_body, "Query matches while federation server is down." );
Future->done(1)
})
};