Skip to content

Commit

Permalink
Merge pull request #756 from matrix-org/babolivier/ephemeral-messages
Browse files Browse the repository at this point in the history
Add tests for ephemeral messages
  • Loading branch information
babolivier authored Dec 3, 2019
2 parents 83e7c28 + 1ac8d0f commit afd2b6f
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/SyTest/Homeserver/Synapse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ sub start

require_membership_for_aliases => "false",

# Enable ephemeral message support (MSC2228)
enable_ephemeral_messages => "true",

$self->{recaptcha_config} ? (
recaptcha_siteverify_api => $self->{recaptcha_config}->{siteverify_api},
recaptcha_public_key => $self->{recaptcha_config}->{public_key},
Expand Down
50 changes: 50 additions & 0 deletions tests/30rooms/04messages.pl
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,53 @@
})
});
};

# Test for MSC2228 for local messages.
test "Ephemeral messages received from clients are correctly expired",
requires => [ local_user_and_room_fixtures() ],

do => sub {
my ( $user, $room_id ) = @_;

my $now_ms = int( time() * 1000 );
my $filter = '{"types":["m.room.message"]}';

matrix_send_room_message( $user, $room_id,
content => {
msgtype => "m.text",
body => "This is a message",
"org.matrix.self_destruct_after" => $now_ms + 1000,
},
)->then( sub {
await_sync_timeline_contains($user, $room_id, check => sub {
my ($event) = @_;
return $event->{content}{body} eq "This is a message"
})
})->then( sub {
# wait for the message to expire
delay( 1.5 )
})->then( sub {
my $iter = 0;
retry_until_success {
matrix_get_room_messages( $user, $room_id, filter => $filter )->then( sub {
$iter++;
my ( $body ) = @_;
log_if_fail "Iteration $iter: response body after expiry", $body;

my $chunk = $body->{chunk};

@$chunk == 1 or
die "Expected 1 message";

# Check that we can't read the message's content after its expiry.
assert_deeply_eq( $chunk->[0]{content}, {}, 'chunk[0] content size' );

Future->done(1);
})->on_fail( sub {
my ( $exc ) = @_;
chomp $exc;
log_if_fail "Iteration $iter: not ready yet: $exc";
});
}
});
};
56 changes: 56 additions & 0 deletions tests/50federation/31room-send.pl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use Time::HiRes qw( time );
use Protocol::Matrix qw( redact_event );


Expand Down Expand Up @@ -145,3 +146,58 @@
});
});
};

# Test for MSC2228 for messages received through federation.
test "Ephemeral messages received from servers are correctly expired",
requires => [ local_user_and_room_fixtures(), remote_user_fixture() ],

do => sub {
my ( $local_user, $room_id, $federated_user ) = @_;

my $filter = '{"types":["m.room.message"]}';

matrix_invite_user_to_room( $local_user, $federated_user, $room_id )->then( sub {
matrix_join_room( $federated_user, $room_id )
})->then( sub {
my $now_ms = int( time() * 1000 );

matrix_send_room_message( $local_user, $room_id,
content => {
msgtype => "m.text",
body => "This is a message",
"org.matrix.self_destruct_after" => $now_ms + 1000,
},
)
})->then( sub {
await_sync_timeline_contains($local_user, $room_id, check => sub {
my ($event) = @_;
return $event->{content}{body} eq "This is a message"
})
})->then( sub {
# wait for the message to expire
delay( 1.5 )
})->then( sub {
my $iter = 0;
retry_until_success {
matrix_get_room_messages( $local_user, $room_id, filter => $filter )->then( sub {
$iter++;
my ( $body ) = @_;
log_if_fail "Iteration $iter: response body after expiry", $body;

my $chunk = $body->{chunk};

@$chunk == 1 or
die "Expected 1 message";

# Check that we can't read the message's content after its expiry.
assert_deeply_eq( $chunk->[0]{content}, {}, 'chunk[0] content size' );

Future->done(1);
})->on_fail( sub {
my ( $exc ) = @_;
chomp $exc;
log_if_fail "Iteration $iter: not ready yet: $exc";
});
}
});
};

0 comments on commit afd2b6f

Please sign in to comment.