Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a valid formatted key to test upload of a key #1111

Merged
merged 3 commits into from
Nov 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 => {
neilalexander marked this conversation as resolved.
Show resolved Hide resolved
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