namespace OC\Authentication\Token;
-interface IWipeableToken {
+interface IWipeableToken extends IToken {
+
+ /**
+ * Mark the token for remote wipe
+ */
public function wipe(): void;
+
}
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
+use OCP\IUser;
use OCP\Notification\IManager as INotificationManager;
use Symfony\Component\EventDispatcher\EventDispatcher;
$this->logger = $logger;
}
+ public function markTokenForWipe(int $id): bool {
+ $token = $this->tokenProvider->getTokenById($id);
+
+ if (!($token instanceof IWipeableToken)) {
+ return false;
+ }
+
+ $token->wipe();
+ $this->tokenProvider->updateToken($token);
+
+ return true;
+ }
+
/**
* @param string $token
*
use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\IToken;
use OC\Authentication\Token\IWipeableToken;
+use OC\Authentication\Token\RemoteWipe;
use OC\Settings\Activity\Provider;
use OCP\Activity\IManager;
use OCP\AppFramework\Controller;
/** @var IManager */
private $activityManager;
+ /** @var RemoteWipe */
+ private $remoteWipe;
+
/** @var ILogger */
private $logger;
* @param ISecureRandom $random
* @param string|null $userId
* @param IManager $activityManager
+ * @param RemoteWipe $remoteWipe
* @param ILogger $logger
*/
public function __construct(string $appName,
ISecureRandom $random,
?string $userId,
IManager $activityManager,
+ RemoteWipe $remoteWipe,
ILogger $logger) {
parent::__construct($appName, $request);
$this->tokenProvider = $tokenProvider;
$this->session = $session;
$this->random = $random;
$this->activityManager = $activityManager;
+ $this->remoteWipe = $remoteWipe;
$this->logger = $logger;
}
* @throws \OC\Authentication\Exceptions\ExpiredTokenException
*/
public function wipe(int $id): JSONResponse {
- $token = $this->tokenProvider->getTokenById($id);
-
- if (!($token instanceof IWipeableToken)) {
+ if (!$this->remoteWipe->markTokenForWipe($id)) {
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
}
- $token->wipe();
- $this->tokenProvider->updateToken($token);
-
return new JSONResponse([]);
}
}
use OC\Authentication\Token\DefaultToken;
use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\IToken;
+use OC\Authentication\Token\RemoteWipe;
use OC\Settings\Controller\AuthSettingsController;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\ISession;
use OCP\Security\ISecureRandom;
use OCP\Session\Exceptions\SessionNotAvailableException;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class AuthSettingsControllerTest extends TestCase {
/** @var AuthSettingsController */
private $controller;
- /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IRequest|MockObject */
private $request;
- /** @var IProvider|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IProvider|MockObject */
private $tokenProvider;
- /** @var ISession|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var ISession|MockObject */
private $session;
- /** @var ISecureRandom|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var ISecureRandom|MockObject */
private $secureRandom;
- /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IManager|MockObject */
private $activityManager;
+ /** @var RemoteWipe|MockObject */
+ private $remoteWipe;
private $uid = 'jane';
protected function setUp() {
$this->session = $this->createMock(ISession::class);
$this->secureRandom = $this->createMock(ISecureRandom::class);
$this->activityManager = $this->createMock(IManager::class);
- /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject $logger */
+ $this->remoteWipe = $this->createMock(RemoteWipe::class);
+ /** @var ILogger|MockObject $logger */
$logger = $this->createMock(ILogger::class);
$this->controller = new AuthSettingsController(
$this->secureRandom,
$this->uid,
$this->activityManager,
+ $this->remoteWipe,
$logger
);
}
/**
* @dataProvider dataRenameToken
+ *
* @param string $name
* @param string $newName
*/
/**
* @dataProvider dataUpdateFilesystemScope
+ *
* @param bool $filesystem
* @param bool $newFilesystem
*/
->with($this->equalTo($tokenId))
->willReturn($token);
}
+
+ public function testRemoteWipeNotSuccessful(): void {
+ $this->remoteWipe->expects($this->once())
+ ->method('markTokenForWipe')
+ ->with(123)
+ ->willReturn(false);
+
+ $response = $this->controller->wipe(123);
+
+ $expected = new JSONResponse([], Http::STATUS_BAD_REQUEST);
+ $this->assertEquals($expected, $response);
+ }
+
+ public function testRemoteWipeSuccessful(): void {
+ $this->remoteWipe->expects($this->once())
+ ->method('markTokenForWipe')
+ ->with(123)
+ ->willReturn(true);
+
+ $response = $this->controller->wipe(123);
+
+ $expected = new JSONResponse([]);
+ $this->assertEquals($expected, $response);
+ }
+
}
use OC\Authentication\Token\IProvider as ITokenProvider;
use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\IToken;
+use OC\Authentication\Token\IWipeableToken;
use OC\Authentication\Token\RemoteWipe;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
);
}
+ public function testMarkNonWipableTokenForWipe(): void {
+ $token = $this->createMock(IToken::class);
+ $this->tokenProvider->expects($this->once())
+ ->method('getTokenById')
+ ->with(123)
+ ->willReturn($token);
+
+ $result = $this->remoteWipe->markTokenForWipe(123);
+
+ $this->assertFalse($result);
+ }
+
+ public function testMarkTokenForWipe(): void {
+ $token = $this->createMock(IWipeableToken::class);
+ $this->tokenProvider->expects($this->once())
+ ->method('getTokenById')
+ ->with(123)
+ ->willReturn($token);
+ $token->expects($this->once())
+ ->method('wipe');
+ $this->tokenProvider->expects($this->once())
+ ->method('updateToken')
+ ->with($token);
+
+ $result = $this->remoteWipe->markTokenForWipe(123);
+
+ $this->assertTrue($result);
+ }
+
public function testStartWipingNotAWipeToken() {
$token = $this->createMock(IToken::class);
$this->tokenProvider->expects($this->once())