-
Notifications
You must be signed in to change notification settings - Fork 56
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
add and update tests for new behaviour with empty backups #519
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d95a50a
add and update tests for new behaviour with empty backups
uhoreg 5d00839
make sure that fetching a bogus backup version 404s
uhoreg 32875e1
remove unused variable
uhoreg 74299c6
fix coding style and add some explanations
uhoreg 403f4f8
add more descriptive output, and fix function description to match re…
uhoreg 794136b
couple of cleanups
uhoreg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
my $fixture = local_user_fixture(); | ||
|
||
my $current_version; # FIXME: is there a better way of passing the backup version between tests? | ||
|
||
test "Can create backup version", | ||
requires => [ $fixture ], | ||
|
||
|
@@ -14,15 +12,15 @@ | |
|
||
matrix_create_key_backup( $user )->then( sub { | ||
my ( $content ) = @_; | ||
log_if_fail "Content", $content; | ||
log_if_fail "Create backup: ", $content; | ||
|
||
assert_json_keys( $content, "version" ); | ||
$version = $content->{version}; | ||
|
||
matrix_get_key_backup_info( $user ); | ||
})->then( sub { | ||
my ( $content ) = @_; | ||
log_if_fail "Content", $content; | ||
log_if_fail "Get backup info: ", $content; | ||
|
||
assert_json_keys( $content, "algorithm" ); | ||
|
||
|
@@ -40,6 +38,53 @@ | |
}); | ||
}; | ||
|
||
test "Responds correctly when backup is empty", | ||
requires => [ $fixture, qw( can_create_backup_version ) ], | ||
|
||
do => sub { | ||
my ( $user ) = @_; | ||
my $version; | ||
|
||
matrix_get_key_backup_info( $user )->then( sub { | ||
my ( $content ) = @_; | ||
|
||
log_if_fail "Get backup info: ", $content; | ||
|
||
$version = $content->{version}; | ||
|
||
# check that asking for a specific session that does not exist returns | ||
# an M_NOT_FOUND | ||
matrix_get_backup_key( $user, $version, '!notaroom', 'notassession' ); | ||
})->main::expect_m_not_found | ||
->then( sub { | ||
# check that asking for all the keys in a room returns an empty | ||
# response rather than an error when nothing has been backed up yet | ||
matrix_get_backup_key( $user, $version, '!notaroom' ); | ||
})->then( sub { | ||
my ( $content ) = @_; | ||
|
||
log_if_fail "Get keys from room: ", $content; | ||
|
||
assert_deeply_eq( $content, { "sessions" => {} } ); | ||
|
||
# check that asking for all the keys returns an empty response rather | ||
# than an error when nothing has been backed up yet | ||
matrix_get_backup_key( $user, $version ); | ||
})->then( sub { | ||
my ( $content ) = @_; | ||
|
||
log_if_fail "Get all keys: ", $content; | ||
|
||
assert_deeply_eq( $content, { "rooms" => {} } ); | ||
|
||
Future->done(1); | ||
|
||
# check that asking for a nonexistent backup version returns an | ||
# M_NOT_FOUND | ||
matrix_get_backup_key( $user, 'bogusversion' ); | ||
})->main::expect_m_not_found; | ||
}; | ||
|
||
test "Can backup keys", | ||
requires => [ $fixture, qw( can_create_backup_version ) ], | ||
|
||
|
@@ -63,12 +108,12 @@ | |
); | ||
})->then( sub { | ||
my ( $content ) = @_; | ||
log_if_fail "Content", $content; | ||
log_if_fail "Back up session: ", $content; | ||
|
||
matrix_get_backup_key( $user, '!abcd', '1234', $version ); | ||
matrix_get_backup_key( $user, $version, '!abcd', '1234' ); | ||
})->then( sub { | ||
my ( $content ) = @_; | ||
log_if_fail "Content", $content; | ||
log_if_fail "Get session backup: ", $content; | ||
|
||
assert_json_keys( $content, qw( first_message_index forwarded_count is_verified session_data ) ); | ||
|
||
|
@@ -115,12 +160,12 @@ | |
); | ||
})->then( sub { | ||
my ( $content ) = @_; | ||
log_if_fail "Content", $content; | ||
log_if_fail "Back up session: ", $content; | ||
|
||
matrix_get_backup_key( $user, '!abcd', '1234', $version ); | ||
matrix_get_backup_key( $user, $version, '!abcd', '1234' ); | ||
})->then( sub { | ||
my ( $content ) = @_; | ||
log_if_fail "Content", $content; | ||
log_if_fail "Get session backup: ", $content; | ||
|
||
assert_json_keys( $content, qw( first_message_index forwarded_count is_verified session_data ) ); | ||
|
||
|
@@ -167,12 +212,12 @@ | |
); | ||
})->then( sub { | ||
my ( $content ) = @_; | ||
log_if_fail "Content", $content; | ||
log_if_fail "Back up session: ", $content; | ||
|
||
matrix_get_backup_key( $user, '!abcd', '1234', $version ); | ||
matrix_get_backup_key( $user, $version, '!abcd', '1234' ); | ||
})->then( sub { | ||
my ( $content ) = @_; | ||
log_if_fail "Content", $content; | ||
log_if_fail "Get session backup: ", $content; | ||
|
||
assert_json_keys( $content, qw( first_message_index forwarded_count is_verified session_data ) ); | ||
|
||
|
@@ -239,7 +284,7 @@ | |
matrix_get_key_backup_info( $user ); | ||
})->then( sub { | ||
my ( $content ) = @_; | ||
log_if_fail "Content", $content; | ||
log_if_fail "Get backup: ", $content; | ||
|
||
my $new_version = $content->{version}; | ||
|
||
|
@@ -259,7 +304,7 @@ | |
|
||
matrix_create_key_backup( $user )->then( sub { | ||
my ( $content ) = @_; | ||
log_if_fail "Content", $content; | ||
log_if_fail "Create backup: ", $content; | ||
|
||
assert_json_keys( $content, "version" ); | ||
|
||
|
@@ -280,7 +325,7 @@ | |
matrix_delete_key_backup( $user, $version ); | ||
})->then( sub { | ||
my ( $content ) = @_; | ||
log_if_fail "Content", $content; | ||
log_if_fail "Delete backup: ", $content; | ||
|
||
matrix_create_key_backup( $user ); | ||
})->then( sub { | ||
|
@@ -295,7 +340,13 @@ | |
version => $content->{version}, | ||
} | ||
); | ||
})->main::expect_http_404; | ||
})->then( sub { | ||
my ( $content ) = @_; | ||
|
||
assert_deeply_eq($content, {"rooms" => {}}, "Expected new backup to be empty"); | ||
|
||
Future->done(1); | ||
}); | ||
}; | ||
|
||
|
||
|
@@ -384,18 +435,28 @@ sub matrix_backup_keys { | |
|
||
=head2 matrix_get_backup_key | ||
|
||
matrix_get_backup_key( $user, $room_id, $session_id, $version ) | ||
matrix_get_backup_key( $user, $version, $room_id, $session_id ) | ||
|
||
Send keys to a given key backup version | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this looks wrong. could you fix it while you're here? |
||
|
||
=cut | ||
|
||
sub matrix_get_backup_key { | ||
my ( $user, $room_id, $session_id, $version ) = @_; | ||
my ( $user, $version, $room_id, $session_id ) = @_; | ||
|
||
my $uri; | ||
|
||
if ( defined $session_id ) { | ||
$uri = "/unstable/room_keys/keys/$room_id/$session_id"; | ||
} elsif ( defined $room_id ) { | ||
$uri = "/unstable/room_keys/keys/$room_id"; | ||
} else { | ||
$uri = "/unstable/room_keys/keys"; | ||
} | ||
|
||
do_request_json_for( $user, | ||
method => "GET", | ||
uri => "/unstable/room_keys/keys/$room_id/$session_id", | ||
uri => $uri, | ||
params => { | ||
version => $version, | ||
}, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need this