Merge pull request #11541 from owncloud/usersession-activeuser-setsession

Unset the cached active user when using a different session object
This commit is contained in:
Vincent Petry 2014-10-15 13:31:05 +02:00
commit 6fa03870e9
2 changed files with 75 additions and 44 deletions

View File

@ -110,6 +110,7 @@ class Session implements IUserSession, Emitter {
$this->session->close(); $this->session->close();
} }
$this->session = $session; $this->session = $session;
$this->activeUser = null;
// maintain deprecated \OC::$session // maintain deprecated \OC::$session
if (\OC::$session !== $this->session) { if (\OC::$session !== $this->session) {

View File

@ -9,6 +9,9 @@
namespace Test\User; namespace Test\User;
use OC\Session\Memory;
use OC\User\User;
class Session extends \PHPUnit_Framework_TestCase { class Session extends \PHPUnit_Framework_TestCase {
public function testGetUser() { public function testGetUser() {
$session = $this->getMock('\OC\Session\Memory', array(), array('')); $session = $this->getMock('\OC\Session\Memory', array(), array(''));
@ -327,4 +330,31 @@ class Session extends \PHPUnit_Framework_TestCase {
$this->assertSame($granted, false); $this->assertSame($granted, false);
} }
public function testActiveUserAfterSetSession() {
$users = array(
'foo' => new User('foo', null),
'bar' => new User('bar', null)
);
$manager = $this->getMockBuilder('\OC\User\Manager')
->disableOriginalConstructor()
->getMock();
$manager->expects($this->any())
->method('get')
->will($this->returnCallback(function ($uid) use ($users) {
return $users[$uid];
}));
$session = new Memory('');
$session->set('user_id', 'foo');
$userSession = new \OC\User\Session($manager, $session);
$this->assertEquals($users['foo'], $userSession->getUser());
$session2 = new Memory('');
$session2->set('user_id', 'bar');
$userSession->setSession($session2);
$this->assertEquals($users['bar'], $userSession->getUser());
}
} }