diff options
author | Christoph Wurst <christoph@owncloud.com> | 2016-05-06 16:31:40 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-05-11 13:36:46 +0200 |
commit | 46bdf6ea2b1e10c2f4d2fae214ecc81b188fa981 (patch) | |
tree | 56c5fb779556bea6489463a315affa6726d81655 /tests/lib | |
parent | 3ffa7d986a3bb2a67ae37e017f3e34097774cbf2 (diff) | |
download | nextcloud-server-46bdf6ea2b1e10c2f4d2fae214ecc81b188fa981.tar.gz nextcloud-server-46bdf6ea2b1e10c2f4d2fae214ecc81b188fa981.zip |
fix PHPDoc and other minor issues
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/authentication/token/defaulttokenmappertest.php | 4 | ||||
-rw-r--r-- | tests/lib/authentication/token/defaulttokenprovidertest.php | 36 | ||||
-rw-r--r-- | tests/lib/user/session.php | 27 |
3 files changed, 37 insertions, 30 deletions
diff --git a/tests/lib/authentication/token/defaulttokenmappertest.php b/tests/lib/authentication/token/defaulttokenmappertest.php index 1f0fdc160e9..b77bf31aa48 100644 --- a/tests/lib/authentication/token/defaulttokenmappertest.php +++ b/tests/lib/authentication/token/defaulttokenmappertest.php @@ -79,12 +79,12 @@ class DefaultTokenMapperTest extends TestCase { private function getNumberOfTokens() { $qb = $this->dbConnection->getQueryBuilder(); - $result = $qb->select($qb->createFunction('COUNT(*)')) + $result = $qb->select($qb->createFunction('count(*) as `count`')) ->from('authtoken') ->execute() ->fetch(); print_r($result); - return (int) $result['COUNT(*)']; + return (int) $result['count']; } public function testInvalidate() { diff --git a/tests/lib/authentication/token/defaulttokenprovidertest.php b/tests/lib/authentication/token/defaulttokenprovidertest.php index 54e29a7ef52..567068ef06a 100644 --- a/tests/lib/authentication/token/defaulttokenprovidertest.php +++ b/tests/lib/authentication/token/defaulttokenprovidertest.php @@ -36,18 +36,25 @@ class DefaultTokenProviderTest extends TestCase { private $crypto; private $config; private $logger; + private $timeFactory; + private $time; protected function setUp() { parent::setUp(); - $this->mapper = $this->getMock('\OC\Authentication\Token\DefaultTokenMapper') + $this->mapper = $this->getMockBuilder('\OC\Authentication\Token\DefaultTokenMapper') ->disableOriginalConstructor() ->getMock(); $this->crypto = $this->getMock('\OCP\Security\ICrypto'); $this->config = $this->getMock('\OCP\IConfig'); $this->logger = $this->getMock('\OCP\ILogger'); + $this->timeFactory = $this->getMock('\OCP\AppFramework\Utility\ITimeFactory'); + $this->time = 1313131; + $this->timeFactory->expects($this->any()) + ->method('getTime') + ->will($this->returnValue($this->time)); - $this->tokenProvider = new DefaultTokenProvider($this->mapper, $this->crypto, $this->config, $this->logger); + $this->tokenProvider = new DefaultTokenProvider($this->mapper, $this->crypto, $this->config, $this->logger, $this->timeFactory); } public function testGenerateToken() { @@ -61,11 +68,11 @@ class DefaultTokenProviderTest extends TestCase { $toInsert->setUid($uid); $toInsert->setPassword('encryptedpassword'); $toInsert->setName($name); - $toInsert->setToken(hash('sha512', $token)); + $toInsert->setToken(hash('sha512', $token . '1f4h9s')); $toInsert->setType($type); - $toInsert->setLastActivity(time()); + $toInsert->setLastActivity($this->time); - $this->config->expects($this->once()) + $this->config->expects($this->any()) ->method('getSystemValue') ->with('secret') ->will($this->returnValue('1f4h9s')); @@ -83,27 +90,20 @@ class DefaultTokenProviderTest extends TestCase { } public function testUpdateToken() { - $tk = $this->getMockBuilder('\OC\Authentication\Token\DefaultTokenProvider') - ->disableOriginalConstructor() - ->getMock(); - $tk->expects($this->once()) - ->method('setLastActivity') - ->with(time()); + $tk = new DefaultToken(); $this->mapper->expects($this->once()) ->method('update') ->with($tk); $this->tokenProvider->updateToken($tk); + + $this->assertEquals($this->time, $tk->getLastActivity()); } public function testGetPassword() { $token = 'token1234'; - $tk = $this->getMockBuilder('\OC\Authentication\Token\DefaultToken') - ->disableOriginalConstructor() - ->getMock(); - $tk->expects($this->once()) - ->method('getPassword') - ->will($this->returnValue('someencryptedvalue')); + $tk = new DefaultToken(); + $tk->setPassword('someencryptedvalue'); $this->config->expects($this->once()) ->method('getSystemValue') ->with('secret') @@ -134,7 +134,7 @@ class DefaultTokenProviderTest extends TestCase { ->will($this->returnValue(150)); $this->mapper->expects($this->once()) ->method('invalidateOld') - ->with(time() - 150); + ->with($this->time - 150); $this->tokenProvider->invalidateOldTokens(); } diff --git a/tests/lib/user/session.php b/tests/lib/user/session.php index bbbe5e0c796..c6ddeb416fb 100644 --- a/tests/lib/user/session.php +++ b/tests/lib/user/session.php @@ -45,39 +45,43 @@ class Session extends \Test\TestCase { ->method('get') ->with('user_id') ->will($this->returnValue($expectedUser->getUID())); + $sessionId = 'abcdef12345'; $manager = $this->getMockBuilder('\OC\User\Manager') ->disableOriginalConstructor() ->getMock(); + $session->expects($this->once()) + ->method('getId') + ->will($this->returnValue($sessionId)); $this->defaultProvider->expects($this->once()) ->method('getToken') ->will($this->returnValue($token)); - // TODO: check passed session id once it's mockable - $session->expects($this->at(1)) - ->method('last_login_check') + $session->expects($this->at(2)) + ->method('get') + ->with('last_login_check') ->will($this->returnValue(null)); // No check has been run yet $this->defaultProvider->expects($this->once()) ->method('getPassword') - // TODO: check passed UID and session id once it's mockable + ->with($token, $sessionId) ->will($this->returnValue('password123')); $manager->expects($this->once()) ->method('checkPassword') ->with($expectedUser->getUID(), 'password123') ->will($this->returnValue(true)); - $session->expects($this->at(2)) + $session->expects($this->at(3)) ->method('set') ->with('last_login_check', 10000); - $session->expects($this->at(3)) + $session->expects($this->at(4)) ->method('get') ->with('last_token_update') ->will($this->returnValue(null)); // No check run so far $this->defaultProvider->expects($this->once()) ->method('updateToken') ->with($token); - $session->expects($this->at(4)) + $session->expects($this->at(5)) ->method('set') - ->with('last_token_update', $this->equalTo(time(), 10)); + ->with('last_token_update', $this->equalTo(10000)); $manager->expects($this->any()) ->method('get') @@ -171,7 +175,7 @@ class Session extends \Test\TestCase { $backend = $this->getMock('\Test\Util\User\Dummy'); $user = $this->getMock('\OC\User\User', array(), array('foo', $backend)); - $user->expects($this->once()) + $user->expects($this->any()) ->method('isEnabled') ->will($this->returnValue(true)); $user->expects($this->any()) @@ -197,6 +201,9 @@ class Session extends \Test\TestCase { $this->assertEquals($user, $userSession->getUser()); } + /** + * @expectedException \OC\User\LoginException + */ public function testLoginValidPasswordDisabled() { $session = $this->getMock('\OC\Session\Memory', array(), array('')); $session->expects($this->never()) @@ -219,7 +226,7 @@ class Session extends \Test\TestCase { $backend = $this->getMock('\Test\Util\User\Dummy'); $user = $this->getMock('\OC\User\User', array(), array('foo', $backend)); - $user->expects($this->once()) + $user->expects($this->any()) ->method('isEnabled') ->will($this->returnValue(false)); $user->expects($this->never()) |