Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minor cleanup in core Controllers
  • Loading branch information
rullzer committed Aug 29, 2016
commit f6423f74e3ca925fd43c67f2669384994ccc55fe
1 change: 0 additions & 1 deletion core/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

namespace OC\Core\Controller;

use OC\AppFramework\Utility\TimeFactory;
use OC\Authentication\TwoFactorAuth\Manager;
use OC\Security\Bruteforce\Throttler;
use OC\User\Session;
Expand Down
5 changes: 2 additions & 3 deletions core/Controller/LostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
use OCP\IUserManager;
use OCP\Mail\IMailer;
use OCP\Security\ISecureRandom;
use OCP\Security\StringUtils;

/**
* Class LostController
Expand Down Expand Up @@ -144,7 +143,7 @@ public function resetform($token, $userId) {
}

/**
* @param string $userId
* @param string $token
* @param string $userId
* @throws \Exception
*/
Expand All @@ -161,7 +160,7 @@ private function checkPasswordResetToken($token, $userId) {
throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired'));
}

if (!StringUtils::equals($splittedToken[1], $token)) {
if (!hash_equals($splittedToken[1], $token)) {
throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid'));
}
}
Expand Down
7 changes: 2 additions & 5 deletions core/Controller/TokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@
namespace OC\Core\Controller;

use OC\AppFramework\Http;
use OC\AppFramework\Utility\TimeFactory;
use OC\Authentication\Token\DefaultTokenProvider;
use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\IToken;
use OC\Authentication\TwoFactorAuth\Manager as TwoFactorAuthManager;
use OC\User\Manager as UserManager;
use OCA\User_LDAP\User\Manager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
Expand Down Expand Up @@ -100,9 +97,9 @@ public function generateToken($user, $password, $name = 'unknown client') {

$token = $this->secureRandom->generate(128);
$this->tokenProvider->generateToken($token, $user->getUID(), $loginName, $password, $name, IToken::PERMANENT_TOKEN);
return [
return new JSONResponse([
'token' => $token,
];
]);
}

}
2 changes: 1 addition & 1 deletion core/Controller/TwoFactorChallengeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function selectChallenge($redirect_url) {
*
* @param string $challengeProviderId
* @param string $redirect_url
* @return TemplateResponse
* @return TemplateResponse|RedirectResponse
*/
public function showChallenge($challengeProviderId, $redirect_url) {
$user = $this->userSession->getUser();
Expand Down
16 changes: 9 additions & 7 deletions tests/Core/Controller/TokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ class TokenControllerTest extends TestCase {
protected function setUp() {
parent::setUp();

$this->request = $this->getMock('\OCP\IRequest');
$this->request = $this->getMockBuilder('\OCP\IRequest')->getMock();
$this->userManager = $this->getMockBuilder('\OC\User\Manager')
->disableOriginalConstructor()
->getMock();
$this->tokenProvider = $this->getMock('\OC\Authentication\Token\IProvider');
$this->tokenProvider = $this->getMockBuilder('\OC\Authentication\Token\IProvider')
->getMock();
$this->twoFactorAuthManager = $this->getMockBuilder('\OC\Authentication\TwoFactorAuth\Manager')
->disableOriginalConstructor()
->getMock();
$this->secureRandom = $this->getMock('\OCP\Security\ISecureRandom');
$this->secureRandom = $this->getMockBuilder('\OCP\Security\ISecureRandom')
->getMock();

$this->tokenController = new TokenController('core', $this->request, $this->userManager, $this->tokenProvider, $this->twoFactorAuthManager, $this->secureRandom);
}
Expand Down Expand Up @@ -77,7 +79,7 @@ public function testWithInvalidCredentials() {
}

public function testWithValidCredentials() {
$user = $this->getMock('\OCP\IUser');
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$this->userManager->expects($this->once())
->method('checkPassword')
->with('john', '123456')
Expand All @@ -96,17 +98,17 @@ public function testWithValidCredentials() {
$this->tokenProvider->expects($this->once())
->method('generateToken')
->with('verysecurerandomtoken', 'john', 'john', '123456', 'unknown client', IToken::PERMANENT_TOKEN);
$expected = [
$expected = new JSONResponse([
'token' => 'verysecurerandomtoken'
];
]);

$actual = $this->tokenController->generateToken('john', '123456');

$this->assertEquals($expected, $actual);
}

public function testWithValidCredentialsBut2faEnabled() {
$user = $this->getMock('\OCP\IUser');
$user = $this->getMockBuilder('\OCP\IUser')->getMock();
$this->userManager->expects($this->once())
->method('checkPassword')
->with('john', '123456')
Expand Down