From e06aa41ba2787997ce6ac69cf7e268726566f1c9 Mon Sep 17 00:00:00 2001 From: Kurt Roeckx Date: Sat, 7 Aug 2021 13:20:07 +0200 Subject: [PATCH 1/2] Use a valid formatted key to test upload of a key The algorithms, keys and signatures parameters are required Signed-off-by: Kurt Roeckx --- tests/41end-to-end-keys/01-upload-key.pl | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/41end-to-end-keys/01-upload-key.pl b/tests/41end-to-end-keys/01-upload-key.pl index 15cdfc753..f5856c050 100644 --- a/tests/41end-to-end-keys/01-upload-key.pl +++ b/tests/41end-to-end-keys/01-upload-key.pl @@ -1,3 +1,5 @@ +use JSON qw( decode_json ); + my $fixture = local_user_fixture(); test "Can upload device keys", @@ -15,6 +17,16 @@ device_keys => { user_id => $user->user_id, device_id => $user->device_id, + algorithms => ["m.olm.curve25519-aes-sha256", "m.megolm.v1.aes-sha"], + keys => { + "curve25519:".$user->device_id => "curve25519+key", + "ed25519:".$user->device_id => "ed25519+key", + }, + signatures => { + $user->user_id => { + "ed25519:".$user->device_id => "self+signature", + }, + }, }, one_time_keys => { "my_algorithm:my_id_1", "KIhHVkAQi8r41aPNql2zTqQsInpFa8XdslQLC8F8BHc" @@ -35,6 +47,35 @@ }) }; +test "Rejects invalid device keys", + requires => [ $fixture ], + + proves => [qw( can_upload_e2e_keys )], + + do => sub { + my ( $user ) = @_; + + do_request_json_for( $user, + method => "POST", + uri => "/r0/keys/upload", + content => { + device_keys => { + user_id => $user->user_id, + device_id => $user->device_id, + }, + one_time_keys => { + "my_algorithm:my_id_1", "KIhHVkAQi8r41aPNql2zTqQsInpFa8XdslQLC8F8BHc" + } + } + )->main::expect_http_400() + ->then( sub { + my ( $response ) = @_; + my $body = decode_json( $response->content ); + assert_eq( $body->{errcode}, "M_BAD_JSON", 'responsecode' ); + Future->done( 1 ); + }) + }; + test "Should reject keys claiming to belong to a different user", requires => [ $fixture ], From 5dc26c18486a54a46b87634557ed6a0b1ca354ad Mon Sep 17 00:00:00 2001 From: Kurt Roeckx Date: Tue, 10 Aug 2021 21:42:47 +0200 Subject: [PATCH 2/2] fixup! Use a valid formatted key to test upload of a key --- tests/41end-to-end-keys/01-upload-key.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/41end-to-end-keys/01-upload-key.pl b/tests/41end-to-end-keys/01-upload-key.pl index f5856c050..403c38d54 100644 --- a/tests/41end-to-end-keys/01-upload-key.pl +++ b/tests/41end-to-end-keys/01-upload-key.pl @@ -55,6 +55,7 @@ do => sub { my ( $user ) = @_; + # algorithms, keys and signatures are required fields, but missing do_request_json_for( $user, method => "POST", uri => "/r0/keys/upload",