Merge "Return early in ApiLogout if user not logged in"
This commit is contained in:
commit
e6d0f05427
2 changed files with 21 additions and 0 deletions
|
|
@ -51,6 +51,13 @@ class ApiLogout extends ApiBase {
|
|||
}
|
||||
|
||||
$user = $this->getUser();
|
||||
|
||||
if ( $user->isAnon() ) {
|
||||
// Cannot logout a anon user, so add a warning and return early.
|
||||
$this->addWarning( 'apierror-mustbeloggedin-generic', 'notloggedin' );
|
||||
return;
|
||||
}
|
||||
|
||||
$oldName = $user->getName();
|
||||
$user->logout();
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,20 @@ class ApiLogoutTest extends ApiTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function testUserLogoutAlreadyLoggedOut() {
|
||||
$user = $this->getServiceContainer()->getUserFactory()->newAnonymous( '1.2.3.4' );
|
||||
|
||||
$this->assertFalse( $user->isRegistered() );
|
||||
$token = $this->getUserCsrfTokenFromApi( $user );
|
||||
$response = $this->doUserLogout( $token, $user )[0];
|
||||
$this->assertFalse( $user->isRegistered() );
|
||||
|
||||
$this->assertArrayEquals(
|
||||
[ 'warnings' => [ 'logout' => [ 'warnings' => 'You must be logged in.' ] ] ],
|
||||
$response
|
||||
);
|
||||
}
|
||||
|
||||
public function testUserLogout() {
|
||||
$user = $this->getTestSysop()->getUser();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue