Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test that fetching device correctly resyncs #791

Merged
merged 3 commits into from
Jan 29, 2020
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 );
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved

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";

erikjohnston marked this conversation as resolved.
Show resolved Hide resolved

# We set up a situation where sytest joins a room with a user without
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
# 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 {
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
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 => {}
}
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
}, {
device_id => $device_id2,

keys => {
device_keys => {}
}
} ]
} );
Future->done(1);
}),
do_request_json_for( $user,
method => "POST",
uri => "/unstable/keys/query",
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
content => {
device_keys => {
$creator_id => [],
}
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
}
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
)
)
erikjohnston marked this conversation as resolved.
Show resolved Hide resolved
})->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