Skip to content

Commit 57c856c

Browse files
authored
Use a valid formatted key to test upload of a key (#1111)
The algorithms, keys and signatures parameters are required Signed-off-by: Kurt Roeckx <[email protected]>
1 parent 35c3274 commit 57c856c

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/41end-to-end-keys/01-upload-key.pl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use JSON qw( decode_json );
2+
13
my $fixture = local_user_fixture();
24

35
test "Can upload device keys",
@@ -15,6 +17,16 @@
1517
device_keys => {
1618
user_id => $user->user_id,
1719
device_id => $user->device_id,
20+
algorithms => ["m.olm.curve25519-aes-sha256", "m.megolm.v1.aes-sha"],
21+
keys => {
22+
"curve25519:".$user->device_id => "curve25519+key",
23+
"ed25519:".$user->device_id => "ed25519+key",
24+
},
25+
signatures => {
26+
$user->user_id => {
27+
"ed25519:".$user->device_id => "self+signature",
28+
},
29+
},
1830
},
1931
one_time_keys => {
2032
"my_algorithm:my_id_1", "KIhHVkAQi8r41aPNql2zTqQsInpFa8XdslQLC8F8BHc"
@@ -35,6 +47,36 @@
3547
})
3648
};
3749

50+
test "Rejects invalid device keys",
51+
requires => [ $fixture ],
52+
53+
proves => [qw( can_upload_e2e_keys )],
54+
55+
do => sub {
56+
my ( $user ) = @_;
57+
58+
# algorithms, keys and signatures are required fields, but missing
59+
do_request_json_for( $user,
60+
method => "POST",
61+
uri => "/r0/keys/upload",
62+
content => {
63+
device_keys => {
64+
user_id => $user->user_id,
65+
device_id => $user->device_id,
66+
},
67+
one_time_keys => {
68+
"my_algorithm:my_id_1", "KIhHVkAQi8r41aPNql2zTqQsInpFa8XdslQLC8F8BHc"
69+
}
70+
}
71+
)->main::expect_http_400()
72+
->then( sub {
73+
my ( $response ) = @_;
74+
my $body = decode_json( $response->content );
75+
assert_eq( $body->{errcode}, "M_BAD_JSON", 'responsecode' );
76+
Future->done( 1 );
77+
})
78+
};
79+
3880
test "Should reject keys claiming to belong to a different user",
3981
requires => [ $fixture ],
4082

0 commit comments

Comments
 (0)