Skip to content

Commit

Permalink
Do not create remember me cookie
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Apr 21, 2020
1 parent 3c5914c commit 6052f82
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@
namespace OC\Authentication\Login;

use OC\User\Session;
use OCP\IConfig;

class FinishRememberedLoginCommand extends ALoginCommand {

/** @var Session */
private $userSession;
/** @var IConfig */
private $config;

public function __construct(Session $userSession) {
public function __construct(Session $userSession, IConfig $config) {
$this->userSession = $userSession;
$this->config = $config;
}

public function process(LoginData $loginData): LoginResult {
if ($loginData->isRememberLogin()) {
if ($loginData->isRememberLogin() && $this->config->getSystemValue('auto_logout', false) === false) {
$this->userSession->createRememberMeToken($loginData->getUser());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,25 @@

use OC\Authentication\Login\FinishRememberedLoginCommand;
use OC\User\Session;
use OCP\IConfig;
use PHPUnit\Framework\MockObject\MockObject;

class FinishRememberedLoginCommandTest extends ALoginCommandTest {

/** @var Session|MockObject */
private $userSession;
/** @var IConfig|MockObject */
private $config;

protected function setUp(): void {
parent::setUp();

$this->userSession = $this->createMock(Session::class);
$this->config = $this->createMock(IConfig::class);

$this->cmd = new FinishRememberedLoginCommand(
$this->userSession
$this->userSession,
$this->config
);
}

Expand All @@ -57,6 +62,10 @@ public function testProcessNotRememberedLogin() {

public function testProcess() {
$data = $this->getLoggedInLoginData();
$this->config->expects($this->once())
->method('getSystemValue')
->with('auto_logout', false)
->willReturn(false);
$this->userSession->expects($this->once())
->method('createRememberMeToken')
->with($this->user);
Expand All @@ -65,4 +74,18 @@ public function testProcess() {

$this->assertTrue($result->isSuccess());
}

public function testProcessNotRemeberedLoginWithAutologout() {
$data = $this->getLoggedInLoginData();
$this->config->expects($this->once())
->method('getSystemValue')
->with('auto_logout', false)
->willReturn(true);
$this->userSession->expects($this->never())
->method('createRememberMeToken');

$result = $this->cmd->process($data);

$this->assertTrue($result->isSuccess());
}
}

0 comments on commit 6052f82

Please sign in to comment.