Skip to content
Merged
Changes from 1 commit
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
91 changes: 91 additions & 0 deletions tests/50federation/40devicelists.pl
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,97 @@
};


test "Server correctly resyncs when client query keys and there is no remote cache",
requires => [ local_user_fixture(),
$main::INBOUND_SERVER, $main::OUTBOUND_CLIENT,
federation_user_id_fixture(),
room_alias_name_fixture() ],

check => sub {
my ( $user, $inbound_server, $outbound_client, $creator_id, $room_alias_name ) = @_;

my ( $room_id );

my $remote_server_name = $inbound_server->server_name;
my $datastore = $inbound_server->datastore;

my $room_alias = "#$room_alias_name:$remote_server_name";

# We return two devices, as there was a bug in synapse which correctly
# handled returning one device but not two.
my $device_id1 = "random_device_id1";
my $device_id2 = "random_device_id2";


# We set up a situation where sytest joins a room with a user without
# relaying any device keys, and then a client of synapse requests the keys
# for that user. This should cause synapse to do a resync and cache those
# keys correctly.
my $room = $datastore->create_room(
creator => $creator_id,
alias => $room_alias,
);

do_request_json_for( $user,
method => "POST",
uri => "/r0/join/$room_alias",

content => {},
)->then( sub {
Future->needs_all(
$inbound_server->await_request_user_devices( $creator_id )
->then( sub {
my ( $req, undef ) = @_;

assert_eq( $req->method, "GET", 'request method' );

$req->respond_json( {
user_id => $creator_id,
stream_id => 1,
devices => [ {
device_id => $device_id1,

keys => {
device_keys => {}
}
}, {
device_id => $device_id2,

keys => {
device_keys => {}
}
} ]
} );
Future->done(1);
}),
do_request_json_for( $user,
method => "POST",
uri => "/unstable/keys/query",
content => {
device_keys => {
$creator_id => [],
}
}
)
)
})->then( sub {
my ( $first, $content ) = @_;

log_if_fail "query response", $content;

assert_json_keys( $content, "device_keys" );

my $device_keys = $content->{device_keys};
assert_json_keys( $device_keys, $creator_id );

my $alice_keys = $device_keys->{ $creator_id };
assert_json_keys( $alice_keys, ( $device_id1, $device_id2 ) );

Future->done( 1 )
});
};


test "Local device key changes get to remote servers with correct prev_id",
requires => [ local_user_fixtures( 2 ), $main::INBOUND_SERVER, federation_user_id_fixture(), room_alias_name_fixture() ],

Expand Down