Skip to content
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
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 );
});
};