|
| 1 | +use JSON qw( decode_json ); |
| 2 | + |
1 | 3 | my $fixture = local_user_fixture();
|
2 | 4 |
|
3 | 5 | test "Can upload device keys",
|
|
15 | 17 | device_keys => {
|
16 | 18 | user_id => $user->user_id,
|
17 | 19 | 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 | + }, |
18 | 30 | },
|
19 | 31 | one_time_keys => {
|
20 | 32 | "my_algorithm:my_id_1", "KIhHVkAQi8r41aPNql2zTqQsInpFa8XdslQLC8F8BHc"
|
|
35 | 47 | })
|
36 | 48 | };
|
37 | 49 |
|
| 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 | + |
38 | 80 | test "Should reject keys claiming to belong to a different user",
|
39 | 81 | requires => [ $fixture ],
|
40 | 82 |
|
|
0 commit comments