Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Authentication')
-rw-r--r--tests/lib/Authentication/Token/DefaultTokenMapperTest.php1
-rw-r--r--tests/lib/Authentication/Token/DefaultTokenProviderTest.php18
-rw-r--r--tests/lib/Authentication/TwoFactorAuth/ManagerTest.php29
3 files changed, 40 insertions, 8 deletions
diff --git a/tests/lib/Authentication/Token/DefaultTokenMapperTest.php b/tests/lib/Authentication/Token/DefaultTokenMapperTest.php
index d71d9468477..418a4d14f62 100644
--- a/tests/lib/Authentication/Token/DefaultTokenMapperTest.php
+++ b/tests/lib/Authentication/Token/DefaultTokenMapperTest.php
@@ -130,6 +130,7 @@ class DefaultTokenMapperTest extends TestCase {
$token->setName('Firefox on Android');
$token->setToken('1504445f1524fc801035448a95681a9378ba2e83930c814546c56e5d6ebde221198792fd900c88ed5ead0555780dad1ebce3370d7e154941cd5de87eb419899b');
$token->setType(IToken::TEMPORARY_TOKEN);
+ $token->setRemember(IToken::DO_NOT_REMEMBER);
$token->setLastActivity($this->time - 60 * 60 * 24 * 3);
$token->setLastCheck($this->time - 10);
diff --git a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php
index 7f90cf051f4..cd6bf7bad57 100644
--- a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php
+++ b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php
@@ -25,7 +25,6 @@ namespace Test\Authentication\Token;
use OC\Authentication\Token\DefaultToken;
use OC\Authentication\Token\DefaultTokenProvider;
use OC\Authentication\Token\IToken;
-use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\ILogger;
@@ -81,6 +80,7 @@ class DefaultTokenProviderTest extends TestCase {
$toInsert->setName($name);
$toInsert->setToken(hash('sha512', $token . '1f4h9s'));
$toInsert->setType($type);
+ $toInsert->setRemember(IToken::DO_NOT_REMEMBER);
$toInsert->setLastActivity($this->time);
$this->config->expects($this->any())
@@ -95,7 +95,7 @@ class DefaultTokenProviderTest extends TestCase {
->method('insert')
->with($this->equalTo($toInsert));
- $actual = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type);
+ $actual = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type, IToken::DO_NOT_REMEMBER);
$this->assertEquals($toInsert, $actual);
}
@@ -245,13 +245,19 @@ class DefaultTokenProviderTest extends TestCase {
public function testInvalidateOldTokens() {
$defaultSessionLifetime = 60 * 60 * 24;
- $this->config->expects($this->once())
+ $defaultRememberMeLifetime = 60 * 60 * 24 * 15;
+ $this->config->expects($this->exactly(2))
->method('getSystemValue')
- ->with('session_lifetime', $defaultSessionLifetime)
- ->will($this->returnValue(150));
- $this->mapper->expects($this->once())
+ ->will($this->returnValueMap([
+ ['session_lifetime', $defaultSessionLifetime, 150],
+ ['remember_login_cookie_lifetime', $defaultRememberMeLifetime, 300],
+ ]));
+ $this->mapper->expects($this->at(0))
->method('invalidateOld')
->with($this->time - 150);
+ $this->mapper->expects($this->at(1))
+ ->method('invalidateOld')
+ ->with($this->time - 300);
$this->tokenProvider->invalidateOldTokens();
}
diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
index 72b70d817d2..52f3ca28500 100644
--- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
+++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
@@ -233,8 +233,15 @@ class ManagerTest extends TestCase {
->with($this->user, $challenge)
->will($this->returnValue(true));
$this->session->expects($this->once())
+ ->method('get')
+ ->with('two_factor_remember_login')
+ ->will($this->returnValue(false));
+ $this->session->expects($this->at(1))
->method('remove')
->with('two_factor_auth_uid');
+ $this->session->expects($this->at(2))
+ ->method('remove')
+ ->with('two_factor_remember_login');
$this->assertTrue($this->manager->verifyChallenge('email', $this->user, $challenge));
}
@@ -304,11 +311,29 @@ class ManagerTest extends TestCase {
->method('getUID')
->will($this->returnValue('ferdinand'));
- $this->session->expects($this->once())
+ $this->session->expects($this->at(0))
+ ->method('set')
+ ->with('two_factor_auth_uid', 'ferdinand');
+ $this->session->expects($this->at(1))
+ ->method('set')
+ ->with('two_factor_remember_login', true);
+
+ $this->manager->prepareTwoFactorLogin($this->user, true);
+ }
+
+ public function testPrepareTwoFactorLoginDontRemember() {
+ $this->user->expects($this->once())
+ ->method('getUID')
+ ->will($this->returnValue('ferdinand'));
+
+ $this->session->expects($this->at(0))
->method('set')
->with('two_factor_auth_uid', 'ferdinand');
+ $this->session->expects($this->at(1))
+ ->method('set')
+ ->with('two_factor_remember_login', false);
- $this->manager->prepareTwoFactorLogin($this->user);
+ $this->manager->prepareTwoFactorLogin($this->user, false);
}
}