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

Tests for erasure #464

Merged
merged 2 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
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
23 changes: 13 additions & 10 deletions tests/14account/02deactivate.pl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use JSON qw( decode_json );

my $password = "my secure password";

sub matrix_deactivate_account
{
my ( $user, $password ) = @_;
my ( $user, %opts ) = @_;

# use the user's password unless one was given in opts
my $password = (delete $opts{password}) // $user->password;

do_request_json_for( $user,
method => "POST",
Expand All @@ -15,26 +16,28 @@ sub matrix_deactivate_account
user => $user->user_id,
password => $password,
},
%opts,
},
);
}
push our @EXPORT, qw( matrix_deactivate_account );

test "Can deactivate account",
requires => [ local_user_fixture( password => $password ) ],
requires => [ local_user_fixture() ],

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

matrix_deactivate_account( $user, $password );
matrix_deactivate_account( $user );
};

test "Can't deactivate account with wrong password",
requires => [ local_user_fixture( password => $password ) ],
requires => [ local_user_fixture() ],

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

matrix_deactivate_account( $user, "wrong password" )
matrix_deactivate_account( $user, password=>"wrong password" )
->main::expect_http_401->then( sub {
my ( $resp ) = @_;

Expand All @@ -52,20 +55,20 @@ sub matrix_deactivate_account
};

test "After deactivating account, can't log in with password",
requires => [ local_user_fixture( password => $password ) ],
requires => [ local_user_fixture() ],

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

matrix_deactivate_account( $user, $password )
matrix_deactivate_account( $user )
->then( sub {
do_request_json_for( $user,
method => "POST",
uri => "/r0/login",
content => {
type => "m.login.password",
user => $user->user_id,
password => $password,
password => $user->password,
}
# We don't mandate the exact failure code here
# (that should be done in the login test if
Expand Down
74 changes: 74 additions & 0 deletions tests/30rooms/32erasure.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright 2018 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

use List::Util qw( first );

test "Only original members of the room can see messages from erased users",
requires => [ local_user_and_room_fixtures(), local_user_fixture(), local_user_fixture() ],

do => sub {
my ( $creator, $room_id, $member, $joiner ) = @_;

my $message_id;
matrix_join_room_synced( $member, $room_id )
->then( sub {
matrix_send_room_text_message( $creator, $room_id, body => "body1" );
})->then( sub {
( $message_id ) = @_;
matrix_join_room_synced( $joiner, $room_id );
})->then( sub {
# now both users should see the message event
matrix_sync( $joiner, limit => 4 );
})->then( sub {
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};
my $events = $room->{timeline}->{events};
log_if_fail "messages for joining user before erasure", $events;

my $e = first { $_->{event_id} eq $message_id } @$events;
assert_eq( $e->{type}, "m.room.message", "event type" );
assert_eq( $e->{content}->{body}, "body1", "event content body" );

matrix_deactivate_account( $creator, erase => JSON::true );
})->then( sub {
# now the original member should see the message event, but the joiner
# should see a redacted version
matrix_sync( $member );
})->then( sub {
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};
my $events = $room->{timeline}->{events};
log_if_fail "messages for original member after erasure", $events;

my $e = first { $_->{event_id} eq $message_id } @$events;
assert_eq( $e->{type}, "m.room.message", "event type" );
assert_eq( $e->{content}->{body}, "body1", "event content body" );

matrix_sync( $joiner );
})->then( sub {
my ( $body ) = @_;

my $room = $body->{rooms}{join}{$room_id};
my $events = $room->{timeline}->{events};
log_if_fail "messages for joining user after erasure", $events;

my $e = first { $_->{event_id} eq $message_id } @$events;
assert_eq( $e->{type}, "m.room.message", "event type" );
assert_deeply_eq( $e->{content}, {}, "event content" );

Future->done(1);
});
};