Skip to content

Commit ad83c5c

Browse files
committed
Deflake 'uploading signed devices gets propagated over federation'
This test started to fail after implementing element-hq/synapse#18899. The failure appeared to be due to the test not waiting for signatures to propagate over federation. The loop would exit as soon as it saw a 'signatures' key. But the value was an empty dict. A few moments later, the dict would be populated with the key we were waiting for. But while that was being sent over federation, the test would fail and exit abruptly. This commit changes the loop to actually check for the signature we're waiting for, instead of exiting upon seeing the 'signatures' key. This seems like it would be less flaky in general, and prevents the test from failing in this case.
1 parent d1c931a commit ad83c5c

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

tests/41end-to-end-keys/08-cross-signing.pl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
=> "nqOvzeuGWT/sRx3h7+MHoInYj3Uk2LD/unI9kDYcHwk",
3030
},
3131
},
32-
})->then( sub {
32+
})->then( sub {#get_media_config_for_user
3333
matrix_get_e2e_keys( $user, $user_id );
3434
})->then( sub {
3535
my ( $content ) = @_;
@@ -587,6 +587,8 @@
587587

588588
my $user2_id = $user2->user_id;
589589
my $user2_device = $user2->device_id;
590+
my $user2_device_key_id_hash = "EmkqvokUn8p+vQAGZitOk4PWjp7Ukp3txV2TbMPEiBQ";
591+
my $user2_device_key_id = "ed25519:$user2_device_key_id_hash";
590592

591593
my $room_id;
592594

@@ -597,8 +599,7 @@
597599
"user_id" => $user2_id,
598600
"usage" => ["self_signing"],
599601
"keys" => {
600-
"ed25519:EmkqvokUn8p+vQAGZitOk4PWjp7Ukp3txV2TbMPEiBQ"
601-
=> "EmkqvokUn8p+vQAGZitOk4PWjp7Ukp3txV2TbMPEiBQ",
602+
$user2_device_key_id => $user2_device_key_id_hash,
602603
},
603604
};
604605
sign_json(
@@ -668,10 +669,10 @@
668669
})->then( sub {
669670
sign_json(
670671
$device, secret_key => $self_signing_secret_key,
671-
origin => $user2_id, key_id => "ed25519:EmkqvokUn8p+vQAGZitOk4PWjp7Ukp3txV2TbMPEiBQ"
672+
origin => $user2_id, key_id => $user2_device_key_id
672673
);
673674
log_if_fail "sent signature", $device;
674-
$cross_signature = $device->{signatures}->{$user2_id}->{"ed25519:EmkqvokUn8p+vQAGZitOk4PWjp7Ukp3txV2TbMPEiBQ"};
675+
$cross_signature = $device->{signatures}->{$user2_id}->{$user2_device_key_id};
675676
matrix_upload_signatures( $user2, {
676677
$user2_id => {
677678
$user2_device => $device
@@ -690,11 +691,19 @@
690691
# On server0, user1 syncs until they see user2's device. This is racey: the
691692
# sync may complete before the signatures have uploaded, propagated over
692693
# federation to server 1 and then over replication to the sync worker.
694+
#
695+
# Thus we check for the expected signatures inside this function.
693696
matrix_get_e2e_keys( $user1, $user2_id )->then( sub {
694697
my ( $content ) = @_;
695698
log_if_fail "key query content2", $content;
696-
$content->{device_keys}{$user2_id}{$user2_device}{"signatures"}
699+
my $sigs = $content->{device_keys}{$user2_id}{$user2_device}{"signatures"}
697700
or die "No 'signatures' key present";
701+
702+
exists $sigs->{$user2_id}
703+
&& exists $sigs->{$user2_id}{$user2_device_key_id}
704+
&& $sigs->{$user2_id}{$user2_device_key_id} eq $cross_signature
705+
or die "Expected cross-signature not visible";
706+
698707
Future->done( $content );
699708
});
700709
};
@@ -703,15 +712,6 @@
703712

704713
log_if_fail "key query content3", $content;
705714

706-
# Check that fetching the devices again returns the new signature
707-
assert_json_keys( $content->{device_keys}->{$user2_id}->{$user2_device}, "signatures" );
708-
709-
assert_deeply_eq( $content->{device_keys}->{$user2_id}->{$user2_device}->{signatures}, {
710-
$user2_id => {
711-
"ed25519:EmkqvokUn8p+vQAGZitOk4PWjp7Ukp3txV2TbMPEiBQ" => $cross_signature
712-
},
713-
} );
714-
715715
# Check that we still see the master key when querying the devices.
716716
assert_json_keys( $content->{master_keys}, $user2_id );
717717
assert_json_keys( $content->{master_keys}->{$user2_id}, "keys");

0 commit comments

Comments
 (0)