diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-05-24 17:51:49 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-05-24 17:51:49 +0200 |
commit | d3fb5d618ea5902c989c39d72fd6ac2e5bcb65ed (patch) | |
tree | 815818e3077c629a5b5fe8a63213e4867546d5b6 /tests | |
parent | e8c37943081975b01f5dedc2284892a5335322f8 (diff) | |
parent | ad10485cec4377119aa14749e8e4aeda6e707f8e (diff) | |
download | nextcloud-server-d3fb5d618ea5902c989c39d72fd6ac2e5bcb65ed.tar.gz nextcloud-server-d3fb5d618ea5902c989c39d72fd6ac2e5bcb65ed.zip |
Merge pull request #24748 from owncloud/login-explicitly
Log in explicitly, save login name when generating browser/device tokens
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Controller/LoginControllerTest.php | 21 | ||||
-rw-r--r-- | tests/Core/Controller/TokenControllerTest.php | 9 | ||||
-rw-r--r-- | tests/lib/Authentication/Token/DefaultTokenMapperTest.php | 4 | ||||
-rw-r--r-- | tests/lib/Authentication/Token/DefaultTokenProviderTest.php | 4 | ||||
-rw-r--r-- | tests/lib/User/SessionTest.php | 19 | ||||
-rw-r--r-- | tests/settings/controller/AuthSettingsControllerTest.php | 5 |
6 files changed, 47 insertions, 15 deletions
diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index e82c4cdc076..ea9d6a44148 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -304,8 +304,11 @@ class LoginControllerTest extends TestCase { ->method('checkPassword') ->will($this->returnValue($user)); $this->userSession->expects($this->once()) + ->method('login') + ->with($user, $password); + $this->userSession->expects($this->once()) ->method('createSessionToken') - ->with($this->request, $user->getUID(), $password); + ->with($this->request, $user->getUID(), $user, $password); $this->twoFactorManager->expects($this->once()) ->method('isTwoFactorAuthenticated') ->with($user) @@ -330,11 +333,11 @@ class LoginControllerTest extends TestCase { $this->userManager->expects($this->once()) ->method('checkPassword') - ->with('jane', $password) + ->with('Jane', $password) ->will($this->returnValue($user)); $this->userSession->expects($this->once()) ->method('createSessionToken') - ->with($this->request, $user->getUID(), $password); + ->with($this->request, $user->getUID(), 'Jane', $password); $this->userSession->expects($this->once()) ->method('isLoggedIn') ->with() @@ -345,11 +348,14 @@ class LoginControllerTest extends TestCase { ->will($this->returnValue($redirectUrl)); $expected = new \OCP\AppFramework\Http\RedirectResponse(urldecode($redirectUrl)); - $this->assertEquals($expected, $this->loginController->tryLogin($user->getUID(), $password, $originalUrl)); + $this->assertEquals($expected, $this->loginController->tryLogin('Jane', $password, $originalUrl)); } public function testLoginWithTwoFactorEnforced() { $user = $this->getMock('\OCP\IUser'); + $user->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('john')); $password = 'secret'; $challengeUrl = 'challenge/url'; @@ -357,8 +363,11 @@ class LoginControllerTest extends TestCase { ->method('checkPassword') ->will($this->returnValue($user)); $this->userSession->expects($this->once()) + ->method('login') + ->with('john@doe.com', $password); + $this->userSession->expects($this->once()) ->method('createSessionToken') - ->with($this->request, $user->getUID(), $password); + ->with($this->request, $user->getUID(), 'john@doe.com', $password); $this->twoFactorManager->expects($this->once()) ->method('isTwoFactorAuthenticated') ->with($user) @@ -372,7 +381,7 @@ class LoginControllerTest extends TestCase { ->will($this->returnValue($challengeUrl)); $expected = new \OCP\AppFramework\Http\RedirectResponse($challengeUrl); - $this->assertEquals($expected, $this->loginController->tryLogin($user, $password, null)); + $this->assertEquals($expected, $this->loginController->tryLogin('john@doe.com', $password, null)); } } diff --git a/tests/Core/Controller/TokenControllerTest.php b/tests/Core/Controller/TokenControllerTest.php index b600bfa5451..386140a8a4f 100644 --- a/tests/Core/Controller/TokenControllerTest.php +++ b/tests/Core/Controller/TokenControllerTest.php @@ -75,14 +75,21 @@ class TokenControllerTest extends TestCase { } public function testWithValidCredentials() { + $user = $this->getMock('\OCP\IUser'); $this->userManager->expects($this->once()) ->method('checkPassword') ->with('john', '123456') - ->will($this->returnValue(true)); + ->will($this->returnValue($user)); + $user->expects($this->once()) + ->method('getUID') + ->will($this->returnValue('john')); $this->secureRandom->expects($this->once()) ->method('generate') ->with(128) ->will($this->returnValue('verysecurerandomtoken')); + $this->tokenProvider->expects($this->once()) + ->method('generateToken') + ->with('verysecurerandomtoken', 'john', 'john', '123456', 'unknown client', \OC\Authentication\Token\IToken::PERMANENT_TOKEN); $expected = [ 'token' => 'verysecurerandomtoken' ]; diff --git a/tests/lib/Authentication/Token/DefaultTokenMapperTest.php b/tests/lib/Authentication/Token/DefaultTokenMapperTest.php index 9179e23bfb2..5d49f75aaa4 100644 --- a/tests/lib/Authentication/Token/DefaultTokenMapperTest.php +++ b/tests/lib/Authentication/Token/DefaultTokenMapperTest.php @@ -57,6 +57,7 @@ class DefaultTokenMapperTest extends TestCase { $qb->delete('authtoken')->execute(); $qb->insert('authtoken')->values([ 'uid' => $qb->createNamedParameter('user1'), + 'login_name' => $qb->createNamedParameter('User1'), 'password' => $qb->createNamedParameter('a75c7116460c082912d8f6860a850904|3nz5qbG1nNSLLi6V|c55365a0e54cfdfac4a175bcf11a7612aea74492277bba6e5d96a24497fa9272488787cb2f3ad34d8b9b8060934fce02f008d371df3ff3848f4aa61944851ff0'), 'name' => $qb->createNamedParameter('Firefox on Linux'), 'token' => $qb->createNamedParameter('9c5a2e661482b65597408a6bb6c4a3d1af36337381872ac56e445a06cdb7fea2b1039db707545c11027a4966919918b19d875a8b774840b18c6cbb7ae56fe206'), @@ -65,6 +66,7 @@ class DefaultTokenMapperTest extends TestCase { ])->execute(); $qb->insert('authtoken')->values([ 'uid' => $qb->createNamedParameter('user2'), + 'login_name' => $qb->createNamedParameter('User2'), 'password' => $qb->createNamedParameter('971a337057853344700bbeccf836519f|UwOQwyb34sJHtqPV|036d4890f8c21d17bbc7b88072d8ef049a5c832a38e97f3e3d5f9186e896c2593aee16883f617322fa242728d0236ff32d163caeb4bd45e14ca002c57a88665f'), 'name' => $qb->createNamedParameter('Firefox on Android'), 'token' => $qb->createNamedParameter('1504445f1524fc801035448a95681a9378ba2e83930c814546c56e5d6ebde221198792fd900c88ed5ead0555780dad1ebce3370d7e154941cd5de87eb419899b'), @@ -73,6 +75,7 @@ class DefaultTokenMapperTest extends TestCase { ])->execute(); $qb->insert('authtoken')->values([ 'uid' => $qb->createNamedParameter('user1'), + 'login_name' => $qb->createNamedParameter('User1'), 'password' => $qb->createNamedParameter('063de945d6f6b26862d9b6f40652f2d5|DZ/z520tfdXPtd0T|395f6b89be8d9d605e409e20b9d9abe477fde1be38a3223f9e508f979bf906e50d9eaa4dca983ca4fb22a241eb696c3f98654e7775f78c4caf13108f98642b53'), 'name' => $qb->createNamedParameter('Iceweasel on Linux'), 'token' => $qb->createNamedParameter('47af8697ba590fb82579b5f1b3b6e8066773a62100abbe0db09a289a62f5d980dc300fa3d98b01d7228468d1ab05c1aa14c8d14bd5b6eee9cdf1ac14864680c3'), @@ -118,6 +121,7 @@ class DefaultTokenMapperTest extends TestCase { $token = '1504445f1524fc801035448a95681a9378ba2e83930c814546c56e5d6ebde221198792fd900c88ed5ead0555780dad1ebce3370d7e154941cd5de87eb419899b'; $token = new DefaultToken(); $token->setUid('user2'); + $token->setLoginName('User2'); $token->setPassword('971a337057853344700bbeccf836519f|UwOQwyb34sJHtqPV|036d4890f8c21d17bbc7b88072d8ef049a5c832a38e97f3e3d5f9186e896c2593aee16883f617322fa242728d0236ff32d163caeb4bd45e14ca002c57a88665f'); $token->setName('Firefox on Android'); $token->setToken('1504445f1524fc801035448a95681a9378ba2e83930c814546c56e5d6ebde221198792fd900c88ed5ead0555780dad1ebce3370d7e154941cd5de87eb419899b'); diff --git a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php index 8af5e1e933a..e04424e4628 100644 --- a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php +++ b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php @@ -61,6 +61,7 @@ class DefaultTokenProviderTest extends TestCase { public function testGenerateToken() { $token = 'token'; $uid = 'user'; + $user = 'User'; $password = 'passme'; $name = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12' . 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12' @@ -70,6 +71,7 @@ class DefaultTokenProviderTest extends TestCase { $toInsert = new DefaultToken(); $toInsert->setUid($uid); + $toInsert->setLoginName($user); $toInsert->setPassword('encryptedpassword'); $toInsert->setName($name); $toInsert->setToken(hash('sha512', $token . '1f4h9s')); @@ -88,7 +90,7 @@ class DefaultTokenProviderTest extends TestCase { ->method('insert') ->with($this->equalTo($toInsert)); - $actual = $this->tokenProvider->generateToken($token, $uid, $password, $name, $type); + $actual = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type); $this->assertEquals($toInsert, $actual); } diff --git a/tests/lib/User/SessionTest.php b/tests/lib/User/SessionTest.php index 140c4321c51..c4424c03480 100644 --- a/tests/lib/User/SessionTest.php +++ b/tests/lib/User/SessionTest.php @@ -38,8 +38,12 @@ class SessionTest extends \Test\TestCase { public function testGetUser() { $token = new \OC\Authentication\Token\DefaultToken(); + $token->setLoginName('User123'); - $expectedUser = new User('foo', null); + $expectedUser = $this->getMock('\OCP\IUser'); + $expectedUser->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('user123')); $session = $this->getMock('\OC\Session\Memory', array(), array('')); $session->expects($this->at(0)) ->method('get') @@ -66,7 +70,10 @@ class SessionTest extends \Test\TestCase { ->will($this->returnValue('password123')); $manager->expects($this->once()) ->method('checkPassword') - ->with($expectedUser->getUID(), 'password123') + ->with('User123', 'password123') + ->will($this->returnValue(true)); + $expectedUser->expects($this->once()) + ->method('isEnabled') ->will($this->returnValue(true)); $session->expects($this->at(3)) ->method('set') @@ -540,12 +547,12 @@ class SessionTest extends \Test\TestCase { ->method('getPassword') ->with($token, 'sessionid') ->will($this->returnValue('123456')); - $user->expects($this->once()) - ->method('getUID') - ->will($this->returnValue('user5')); + $token->expects($this->once()) + ->method('getLoginName') + ->will($this->returnValue('User5')); $userManager->expects($this->once()) ->method('checkPassword') - ->with('user5', '123456') + ->with('User5', '123456') ->will($this->returnValue(true)); $user->expects($this->once()) ->method('isEnabled') diff --git a/tests/settings/controller/AuthSettingsControllerTest.php b/tests/settings/controller/AuthSettingsControllerTest.php index 49491c8ff52..ee67b221022 100644 --- a/tests/settings/controller/AuthSettingsControllerTest.php +++ b/tests/settings/controller/AuthSettingsControllerTest.php @@ -89,6 +89,9 @@ class AuthSettingsControllerTest extends TestCase { ->method('getPassword') ->with($sessionToken, 'sessionid') ->will($this->returnValue($password)); + $sessionToken->expects($this->once()) + ->method('getLoginName') + ->will($this->returnValue('User13')); $this->secureRandom->expects($this->exactly(4)) ->method('generate') @@ -98,7 +101,7 @@ class AuthSettingsControllerTest extends TestCase { $this->tokenProvider->expects($this->once()) ->method('generateToken') - ->with($newToken, $this->uid, $password, $name, IToken::PERMANENT_TOKEN) + ->with($newToken, $this->uid, 'User13', $password, $name, IToken::PERMANENT_TOKEN) ->will($this->returnValue($deviceToken)); $expected = [ |