Skip to content

Commit

Permalink
Test for correct error when logging out with invalid or missing acces…
Browse files Browse the repository at this point in the history
…s token

For matrix-org/synapse#5256

Signed-off-by: Aaron Raimist <[email protected]>
  • Loading branch information
aaronraimist committed May 27, 2019
1 parent 49bdb64 commit c078627
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion tests/13logout.pl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use JSON qw( decode_json );

test "Can logout current device",
requires => [ local_user_fixture( with_events => 0 ) ],

Expand Down Expand Up @@ -26,7 +28,7 @@

do_request_json_for( $user,
method => "POST",
uri => "/r0/logout",
uri => "/r0/logout",
content => {},
)
})->then( sub {
Expand Down Expand Up @@ -92,3 +94,42 @@
};
});
};

test "Request to logout with invalid an access token is rejected",
requires => [ $main::API_CLIENTS[0] ],

do => sub {
my ( $http ) = @_;

$http->do_request_json(
method => "POST",
uri => "/r0/logout",
content => {},
params => { access_token => "an/invalid/token" },
)->main::expect_http_401->then( sub {
my ( $resp ) = @_;
my $body = decode_json($resp->content);
assert_eq( $body->{errcode}, "M_UNKNOWN_TOKEN", "errcode" );

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

test "Request to logout without an access token is rejected",
requires => [ $main::API_CLIENTS[0] ],

do => sub {
my ( $http ) = @_;

$http->do_request_json(
method => "POST",
uri => "/r0/logout",
content => {},
)->main::expect_http_401->then( sub {
my ( $resp ) = @_;
my $body = decode_json($resp->content);
assert_eq( $body->{errcode}, "M_MISSING_TOKEN", "errcode" );

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

0 comments on commit c078627

Please sign in to comment.