aboutsummaryrefslogtreecommitdiffstats
path: root/includes/session
diff options
context:
space:
mode:
authorBrad Jorsch <bjorsch@wikimedia.org>2016-02-26 15:02:56 -0500
committerBryanDavis <bdavis@wikimedia.org>2016-02-26 20:14:27 +0000
commite75f2ab0f2d430015775e8c7fecc4f58aabeb974 (patch)
tree491659fb4800ee0aab5ba2dd8188267776df6b37 /includes/session
parent9fd930f74592234f95f83c0c831339e5b49553e7 (diff)
downloadmediawikicore-e75f2ab0f2d430015775e8c7fecc4f58aabeb974.tar.gz
mediawikicore-e75f2ab0f2d430015775e8c7fecc4f58aabeb974.zip
Improve SessionManager unit test coverage, and fix two namespacing bugs
Change-Id: Ie0bcba77625e04ca3e89eb400626f63024c6e1a1
Diffstat (limited to 'includes/session')
-rw-r--r--includes/session/BotPasswordSessionProvider.php7
-rw-r--r--includes/session/MetadataMergeException.php1
-rw-r--r--includes/session/PHPSessionHandler.php2
-rw-r--r--includes/session/SessionManager.php8
4 files changed, 16 insertions, 2 deletions
diff --git a/includes/session/BotPasswordSessionProvider.php b/includes/session/BotPasswordSessionProvider.php
index 44199bdec460..70c771dc314a 100644
--- a/includes/session/BotPasswordSessionProvider.php
+++ b/includes/session/BotPasswordSessionProvider.php
@@ -165,16 +165,19 @@ class BotPasswordSessionProvider extends ImmutableSessionProviderWithCookie {
return true;
}
+ /**
+ * @codeCoverageIgnore
+ */
public function preventSessionsForUser( $username ) {
BotPassword::removeAllPasswordsForUser( $username );
}
public function getAllowedUserRights( SessionBackend $backend ) {
if ( $backend->getProvider() !== $this ) {
- throw new InvalidArgumentException( 'Backend\'s provider isn\'t $this' );
+ throw new \InvalidArgumentException( 'Backend\'s provider isn\'t $this' );
}
$data = $backend->getProviderMetadata();
- if ( $data ) {
+ if ( $data && isset( $data['rights'] ) && is_array( $data['rights'] ) ) {
return $data['rights'];
}
diff --git a/includes/session/MetadataMergeException.php b/includes/session/MetadataMergeException.php
index 9f42c278bc45..882084d04e09 100644
--- a/includes/session/MetadataMergeException.php
+++ b/includes/session/MetadataMergeException.php
@@ -22,6 +22,7 @@
namespace MediaWiki\Session;
+use Exception;
use UnexpectedValueException;
/**
diff --git a/includes/session/PHPSessionHandler.php b/includes/session/PHPSessionHandler.php
index 863080945607..695ce5a92a7b 100644
--- a/includes/session/PHPSessionHandler.php
+++ b/includes/session/PHPSessionHandler.php
@@ -111,9 +111,11 @@ class PHPSessionHandler implements \SessionHandlerInterface {
return;
}
+ // @codeCoverageIgnoreStart
if ( defined( 'MW_NO_SESSION_HANDLER' ) ) {
throw new \BadMethodCallException( 'MW_NO_SESSION_HANDLER is defined' );
}
+ // @codeCoverageIgnoreEnd
self::$instance = new self( $manager );
diff --git a/includes/session/SessionManager.php b/includes/session/SessionManager.php
index b1d5d77e38c6..6a8b8a32ec98 100644
--- a/includes/session/SessionManager.php
+++ b/includes/session/SessionManager.php
@@ -296,9 +296,11 @@ final class SessionManager implements SessionManagerInterface {
}
public function getVaryHeaders() {
+ // @codeCoverageIgnoreStart
if ( defined( 'MW_NO_SESSION' ) && MW_NO_SESSION !== 'warn' ) {
return [];
}
+ // @codeCoverageIgnoreEnd
if ( $this->varyHeaders === null ) {
$headers = [];
foreach ( $this->getProviders() as $provider ) {
@@ -317,9 +319,11 @@ final class SessionManager implements SessionManagerInterface {
}
public function getVaryCookies() {
+ // @codeCoverageIgnoreStart
if ( defined( 'MW_NO_SESSION' ) && MW_NO_SESSION !== 'warn' ) {
return [];
}
+ // @codeCoverageIgnoreEnd
if ( $this->varyCookies === null ) {
$cookies = [];
foreach ( $this->getProviders() as $provider ) {
@@ -513,12 +517,14 @@ final class SessionManager implements SessionManagerInterface {
}
# Notify AuthPlugin
+ // @codeCoverageIgnoreStart
$tmpUser = $user;
$wgAuth->initUser( $tmpUser, true );
if ( $tmpUser !== $user ) {
$logger->warning( __METHOD__ . ': ' .
get_class( $wgAuth ) . '::initUser() replaced the user object' );
}
+ // @codeCoverageIgnoreEnd
# Notify hooks (e.g. Newuserlog)
\Hooks::run( 'AuthPluginAutoCreate', [ $user ] );
@@ -957,6 +963,7 @@ final class SessionManager implements SessionManagerInterface {
* @return Session
*/
public function getSessionFromInfo( SessionInfo $info, WebRequest $request ) {
+ // @codeCoverageIgnoreStart
if ( defined( 'MW_NO_SESSION' ) ) {
if ( MW_NO_SESSION === 'warn' ) {
// Undocumented safety case for converting existing entry points
@@ -965,6 +972,7 @@ final class SessionManager implements SessionManagerInterface {
throw new \BadMethodCallException( 'Sessions are disabled for this entry point' );
}
}
+ // @codeCoverageIgnoreEnd
$id = $info->getId();