Skip to content

Commit

Permalink
Use a valid formatted key to test upload of a key (#1111)
Browse files Browse the repository at this point in the history
The algorithms, keys and signatures parameters are required

Signed-off-by: Kurt Roeckx <[email protected]>
  • Loading branch information
kroeckx authored Nov 8, 2021
1 parent 35c3274 commit 57c856c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/41end-to-end-keys/01-upload-key.pl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use JSON qw( decode_json );

my $fixture = local_user_fixture();

test "Can upload device keys",
Expand All @@ -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"
Expand All @@ -35,6 +47,36 @@
})
};

test "Rejects invalid device keys",
requires => [ $fixture ],

proves => [qw( can_upload_e2e_keys )],

do => sub {
my ( $user ) = @_;

# algorithms, keys and signatures are required fields, but missing
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 ],

Expand Down

0 comments on commit 57c856c

Please sign in to comment.