SessionManager: Save 'persisted' flag in session metadata
This allows SessionManager::getSessionById()->isPersisted() to be reliably set. Otherwise it depends on whether the SessionBackend is still loaded or not. Change-Id: I17733559ac5d8fff13881664333f61d36f610b6d
This commit is contained in:
parent
5346065e02
commit
296ccfd4a9
3 changed files with 37 additions and 0 deletions
|
|
@ -262,6 +262,7 @@ final class SessionBackend {
|
|||
if ( !$this->persist ) {
|
||||
$this->persist = true;
|
||||
$this->forcePersist = true;
|
||||
$this->metaDirty = true;
|
||||
$this->logger->debug( "SessionBackend $this->id force-persist due to persist()" );
|
||||
$this->autosave();
|
||||
} else {
|
||||
|
|
@ -601,6 +602,7 @@ final class SessionBackend {
|
|||
'forceHTTPS' => $this->forceHTTPS,
|
||||
'expires' => time() + $this->lifetime,
|
||||
'loggedOut' => $this->loggedOut,
|
||||
'persisted' => $this->persist,
|
||||
);
|
||||
|
||||
\Hooks::run( 'SessionMetadata', array( $this, &$metadata, $this->requests ) );
|
||||
|
|
|
|||
|
|
@ -801,6 +801,9 @@ final class SessionManager implements SessionManagerInterface {
|
|||
if ( !empty( $metadata['forceHTTPS'] ) && !$info->forceHTTPS() ) {
|
||||
$newParams['forceHTTPS'] = true;
|
||||
}
|
||||
if ( !empty( $metadata['persisted'] ) && !$info->wasPersisted() ) {
|
||||
$newParams['persisted'] = true;
|
||||
}
|
||||
|
||||
if ( !$info->isIdSafe() ) {
|
||||
$newParams['idIsSafe'] = true;
|
||||
|
|
|
|||
|
|
@ -1604,6 +1604,38 @@ class SessionManagerTest extends MediaWikiTestCase {
|
|||
$this->assertTrue( $info->forceHTTPS() );
|
||||
$this->assertSame( array(), $logger->getBuffer() );
|
||||
|
||||
// "Persist" flag from session
|
||||
$this->store->setSessionMeta( $id, $metadata );
|
||||
$info = new SessionInfo( SessionInfo::MIN_PRIORITY, array(
|
||||
'provider' => $provider,
|
||||
'id' => $id,
|
||||
'userInfo' => $userInfo
|
||||
) );
|
||||
$this->assertTrue( $loadSessionInfoFromStore( $info ) );
|
||||
$this->assertFalse( $info->wasPersisted() );
|
||||
$this->assertSame( array(), $logger->getBuffer() );
|
||||
|
||||
$this->store->setSessionMeta( $id, array( 'persisted' => true ) + $metadata );
|
||||
$info = new SessionInfo( SessionInfo::MIN_PRIORITY, array(
|
||||
'provider' => $provider,
|
||||
'id' => $id,
|
||||
'userInfo' => $userInfo
|
||||
) );
|
||||
$this->assertTrue( $loadSessionInfoFromStore( $info ) );
|
||||
$this->assertTrue( $info->wasPersisted() );
|
||||
$this->assertSame( array(), $logger->getBuffer() );
|
||||
|
||||
$this->store->setSessionMeta( $id, array( 'persisted' => false ) + $metadata );
|
||||
$info = new SessionInfo( SessionInfo::MIN_PRIORITY, array(
|
||||
'provider' => $provider,
|
||||
'id' => $id,
|
||||
'userInfo' => $userInfo,
|
||||
'persisted' => true
|
||||
) );
|
||||
$this->assertTrue( $loadSessionInfoFromStore( $info ) );
|
||||
$this->assertTrue( $info->wasPersisted() );
|
||||
$this->assertSame( array(), $logger->getBuffer() );
|
||||
|
||||
// Provider refreshSessionInfo() returning false
|
||||
$info = new SessionInfo( SessionInfo::MIN_PRIORITY, array(
|
||||
'provider' => $provider3,
|
||||
|
|
|
|||
Loading…
Reference in a new issue