summaryrefslogtreecommitdiffstats
path: root/tests/lib/User/SessionTest.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-10-02 11:50:41 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2018-10-02 19:50:54 +0200
commit19f84f7b5485e204014671d0439e8af5693acbb1 (patch)
treea386a3212106ceab6c07a98ee4a320f8b0012f37 /tests/lib/User/SessionTest.php
parentd9febae5b2cbe2147c892030ca9d1b5db7304e9f (diff)
downloadnextcloud-server-19f84f7b5485e204014671d0439e8af5693acbb1.tar.gz
nextcloud-server-19f84f7b5485e204014671d0439e8af5693acbb1.zip
Add tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests/lib/User/SessionTest.php')
-rw-r--r--tests/lib/User/SessionTest.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php
index 81ceade9e02..114b2eb5597 100644
--- a/tests/lib/User/SessionTest.php
+++ b/tests/lib/User/SessionTest.php
@@ -1067,6 +1067,55 @@ class SessionTest extends \Test\TestCase {
$this->assertEquals(1000, $token->getLastCheck());
}
+ public function testValidateSessionInvalidPassword() {
+ $userManager = $this->createMock(Manager::class);
+ $session = $this->createMock(ISession::class);
+ $timeFactory = $this->createMock(ITimeFactory::class);
+ $tokenProvider = $this->createMock(IProvider::class);
+ $userSession = $this->getMockBuilder(Session::class)
+ ->setConstructorArgs([$userManager, $session, $timeFactory, $tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger])
+ ->setMethods(['logout'])
+ ->getMock();
+
+ $user = $this->createMock(IUser::class);
+ $token = new \OC\Authentication\Token\DefaultToken();
+ $token->setLoginName('susan');
+ $token->setLastCheck(20);
+
+ $session->expects($this->once())
+ ->method('get')
+ ->with('app_password')
+ ->will($this->returnValue('APP-PASSWORD'));
+ $tokenProvider->expects($this->once())
+ ->method('getToken')
+ ->with('APP-PASSWORD')
+ ->will($this->returnValue($token));
+ $timeFactory->expects($this->once())
+ ->method('getTime')
+ ->will($this->returnValue(1000)); // more than 5min since last check
+ $tokenProvider->expects($this->once())
+ ->method('getPassword')
+ ->with($token, 'APP-PASSWORD')
+ ->will($this->returnValue('123456'));
+ $userManager->expects($this->once())
+ ->method('checkPassword')
+ ->with('susan', '123456')
+ ->willReturn(false);
+ $user->expects($this->once())
+ ->method('isEnabled')
+ ->will($this->returnValue(true));
+ $tokenProvider->expects($this->never())
+ ->method('invalidateToken');
+ $tokenProvider->expects($this->once())
+ ->method('markPasswordInvalid')
+ ->with($token, 'APP-PASSWORD');
+ $userSession->expects($this->once())
+ ->method('logout');
+
+ $userSession->setUser($user);
+ $this->invokePrivate($userSession, 'validateSession');
+ }
+
public function testUpdateSessionTokenPassword() {
$userManager = $this->createMock(Manager::class);
$session = $this->createMock(ISession::class);
@@ -1362,4 +1411,12 @@ class SessionTest extends \Test\TestCase {
$this->assertFalse($userSession->tryBasicAuthLogin($request, $this->throttler));
}
+
+ public function testUpdateTokens() {
+ $this->tokenProvider->expects($this->once())
+ ->method('updatePasswords')
+ ->with('uid', 'pass');
+
+ $this->userSession->updateTokens('uid', 'pass');
+ }
}