$authenticated = $this->session->get('public_link_authenticated') === $share->getId() ||
$this->shareManager->checkPassword($share, $password);
if (!empty($storedPassword) && !$authenticated ) {
- return new JSONResponse(
+ $response = new JSONResponse(
['message' => 'No permission to access the share'],
Http::STATUS_BAD_REQUEST
);
+ $response->throttle();
+ return $response;
}
$share->setSharedWith($shareWith);
return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.showShare', array('token' => $token)));
}
- return new TemplateResponse($this->appName, 'authenticate', array('wrongpw' => true), 'guest');
+ $response = new TemplateResponse($this->appName, 'authenticate', array('wrongpw' => true), 'guest');
+ $response->throttle();
+ return $response;
}
/**
$response = $this->shareController->authenticate('token', 'invalidpassword');
$expectedResponse = new TemplateResponse($this->appName, 'authenticate', array('wrongpw' => true), 'guest');
+ $expectedResponse->throttle();
$this->assertEquals($expectedResponse, $response);
}
use OC\CapabilitiesManager;
use OC\Core\Controller\OCSController;
-use OC\Security\Bruteforce\Throttler;
use OC\Security\IdentityProof\Manager;
use OCA\User_LDAP\Configuration;
use OCA\User_LDAP\Helper;
CapabilitiesManager $capabilitiesManager,
IUserSession $userSession,
IUserManager $userManager,
- Throttler $throttler,
Manager $keyManager,
Helper $ldapHelper,
ILogger $logger
$capabilitiesManager,
$userSession,
$userManager,
- $throttler,
$keyManager
);
use OCA\Encryption\Exceptions\PrivateKeyMissingException;
use \OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\JSONResponse;
use \OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Defaults;
* @BruteForceProtection(action=passwordResetEmail)
*
* @param string $user
- * @return array
+ * @return JSONResponse
*/
public function email($user){
// FIXME: use HTTP error codes
try {
$this->sendEmail($user);
} catch (\Exception $e){
- return $this->error($e->getMessage());
+ $response = new JSONResponse($this->error($e->getMessage()));
+ $response->throttle();
+ return $response;
}
- return $this->success();
+ $response = new JSONResponse($this->success());
+ $response->throttle();
+ return $response;
}
/**
namespace OC\Core\Controller;
use OC\CapabilitiesManager;
-use OC\Security\Bruteforce\Throttler;
use OC\Security\IdentityProof\Manager;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
private $userManager;
/** @var Manager */
private $keyManager;
- /** @var Throttler */
- private $throttler;
/**
* OCSController constructor.
* @param CapabilitiesManager $capabilitiesManager
* @param IUserSession $userSession
* @param IUserManager $userManager
- * @param Throttler $throttler
* @param Manager $keyManager
*/
public function __construct($appName,
CapabilitiesManager $capabilitiesManager,
IUserSession $userSession,
IUserManager $userManager,
- Throttler $throttler,
Manager $keyManager) {
parent::__construct($appName, $request);
$this->capabilitiesManager = $capabilitiesManager;
$this->userSession = $userSession;
$this->userManager = $userManager;
- $this->throttler = $throttler;
$this->keyManager = $keyManager;
}
/**
* @PublicPage
+ * @BruteForceProtection(action=login)
*
* @param string $login
* @param string $password
*/
public function personCheck($login = '', $password = '') {
if ($login !== '' && $password !== '') {
- $this->throttler->sleepDelay($this->request->getRemoteAddress(), 'login');
if ($this->userManager->checkPassword($login, $password)) {
return new DataResponse([
'person' => [
]
]);
}
- $this->throttler->registerAttempt('login', $this->request->getRemoteAddress());
- return new DataResponse(null, 102);
+
+ $response = new DataResponse(null, 102);
+ $response->throttle();
+ return $response;
}
return new DataResponse(null, 101);
}
use OC\Core\Controller\LostController;
use OC\Mail\Message;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Defaults;
$this->assertEquals($expectedResponse, $response);
}
- public function testEmailUnsucessful() {
+ public function testEmailUnsuccessful() {
$existingUser = 'ExistingUser';
$nonExistingUser = 'NonExistingUser';
$this->userManager
// With a non existing user
$response = $this->lostController->email($nonExistingUser);
- $expectedResponse = [
+ $expectedResponse = new JSONResponse([
'status' => 'error',
'msg' => 'Couldn\'t send reset email. Please make sure your username is correct.'
- ];
- $this->assertSame($expectedResponse, $response);
+ ]);
+ $expectedResponse->throttle();
+ $this->assertEquals($expectedResponse, $response);
// With no mail address
$this->config
->with($existingUser, 'settings', 'email')
->will($this->returnValue(null));
$response = $this->lostController->email($existingUser);
- $expectedResponse = [
+ $expectedResponse = new JSONResponse([
'status' => 'error',
'msg' => 'Couldn\'t send reset email. Please make sure your username is correct.'
- ];
- $this->assertSame($expectedResponse, $response);
+ ]);
+ $expectedResponse->throttle();
+ $this->assertEquals($expectedResponse, $response);
}
public function testEmailSuccessful() {
)->willReturn('encryptedToken');
$response = $this->lostController->email('ExistingUser');
- $expectedResponse = array('status' => 'success');
- $this->assertSame($expectedResponse, $response);
+ $expectedResponse = new JSONResponse(['status' => 'success']);
+ $expectedResponse->throttle();
+ $this->assertEquals($expectedResponse, $response);
}
public function testEmailWithMailSuccessful() {
)->willReturn('encryptedToken');
$response = $this->lostController->email('test@example.com');
- $expectedResponse = array('status' => 'success');
- $this->assertSame($expectedResponse, $response);
+ $expectedResponse = new JSONResponse(['status' => 'success']);
+ $expectedResponse->throttle();
+ $this->assertEquals($expectedResponse, $response);
}
public function testEmailCantSendException() {
)->willReturn('encryptedToken');
$response = $this->lostController->email('ExistingUser');
- $expectedResponse = ['status' => 'error', 'msg' => 'Couldn\'t send reset email. Please contact your administrator.'];
- $this->assertSame($expectedResponse, $response);
+ $expectedResponse = new JSONResponse(['status' => 'error', 'msg' => 'Couldn\'t send reset email. Please contact your administrator.']);
+ $expectedResponse->throttle();
+ $this->assertEquals($expectedResponse, $response);
}
public function testSetPasswordUnsuccessful() {
->willReturn($user);
$response = $this->lostController->email('ExistingUser');
- $expectedResponse = ['status' => 'error', 'msg' => 'Could not send reset email because there is no email address for this username. Please contact your administrator.'];
- $this->assertSame($expectedResponse, $response);
+ $expectedResponse = new JSONResponse(['status' => 'error', 'msg' => 'Could not send reset email because there is no email address for this username. Please contact your administrator.']);
+ $expectedResponse->throttle();
+ $this->assertEquals($expectedResponse, $response);
}
public function testSetPasswordEncryptionDontProceed() {
private $userSession;
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;
- /** @var Throttler|\PHPUnit_Framework_MockObject_MockObject */
- private $throttler;
/** @var Manager|\PHPUnit_Framework_MockObject_MockObject */
private $keyManager;
/** @var OCSController */
$this->capabilitiesManager = $this->createMock(CapabilitiesManager::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->userManager = $this->createMock(IUserManager::class);
- $this->throttler = $this->createMock(Throttler::class);
$this->keyManager = $this->createMock(Manager::class);
$this->controller = new OCSController(
$this->capabilitiesManager,
$this->userSession,
$this->userManager,
- $this->throttler,
$this->keyManager
);
}
}
public function testPersonCheckValid() {
- $this->request->method('getRemoteAddress')
- ->willReturn('1.2.3.4');
-
- $this->throttler->expects($this->once())
- ->method('sleepDelay')
- ->with('1.2.3.4');
-
- $this->throttler->expects($this->never())
- ->method('registerAttempt');
-
$this->userManager->method('checkPassword')
->with(
$this->equalTo('user'),
'personid' => 'user'
]
]);
-
$this->assertEquals($expected, $this->controller->personCheck('user', 'pass'));
}
public function testPersonInvalid() {
- $this->request->method('getRemoteAddress')
- ->willReturn('1.2.3.4');
-
- $this->throttler->expects($this->once())
- ->method('sleepDelay')
- ->with('1.2.3.4');
-
- $this->throttler->expects($this->once())
- ->method('registerAttempt')
- ->with(
- $this->equalTo('login'),
- $this->equalTo('1.2.3.4')
- );
-
$this->userManager->method('checkPassword')
->with(
$this->equalTo('user'),
)->willReturn(false);
$expected = new DataResponse(null, 102);
-
+ $expected->throttle();
$this->assertEquals($expected, $this->controller->personCheck('user', 'wrongpass'));
}
public function testPersonNoLogin() {
- $this->request->method('getRemoteAddress')
- ->willReturn('1.2.3.4');
-
- $this->throttler->expects($this->never())
- ->method('sleepDelay');
-
- $this->throttler->expects($this->never())
- ->method('registerAttempt');
-
$this->userManager->method('checkPassword')
->with(
$this->equalTo('user'),
)->willReturn(false);
$expected = new DataResponse(null, 101);
-
$this->assertEquals($expected, $this->controller->personCheck('', ''));
}