}
public function allowedApps() {
- return null;
+ return [];
}
public function filterTypes(array $types) {
switch ($event->getSubject()) {
case 'codes_generated':
- $event->setParsedSubject($l->t('You created backup codes for your account'));
+ $event->setParsedSubject($l->t('You created two-factor backup codes for your account'));
$event->setIcon($this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg')));
break;
default:
namespace OCA\TwoFactorBackupCodes\Service;
+use Exception;
use OCA\TwoFactorBackupCodes\Db\BackupCode;
use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper;
use OCP\Activity\IManager;
+use OCP\ILogger;
use OCP\IUser;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
/** @var IManager */
private $activityManager;
- public function __construct(BackupCodeMapper $mapper, ISecureRandom $random, IHasher $hasher, IManager $activityManager) {
+ /** @var ILogger */
+ private $logger;
+
+ public function __construct(BackupCodeMapper $mapper, ISecureRandom $random, IHasher $hasher,
+ IManager $activityManager, ILogger $logger) {
$this->mapper = $mapper;
$this->hasher = $hasher;
$this->random = $random;
$this->activityManager = $activityManager;
+ $this->logger = $logger;
}
/**
$activity->setApp('twofactor_backupcodes')
->setType('twofactor')
->setAuthor($user->getUID())
- ->setAffectedUser($user->getUID());
- $activity->setSubject($event);
- $this->activityManager->publish($activity);
+ ->setAffectedUser($user->getUID())
+ ->setSubject($event);
+ try {
+ $this->activityManager->publish($activity);
+ } catch (Exception $e) {
+ $this->logger->warning('could not publish backup code creation activity', ['app' => 'twofactor_backupcodes']);
+ $this->logger->logException($e, ['app' => 'twofactor_backupcodes']);
+ }
}
/**
use OCP\IL10N;
use OCP\IURLGenerator;
use Test\TestCase;
-use function returnValue;
class GenericFilterTest extends TestCase {
}
public function testAllowedApps() {
- $this->assertEquals(0, $this->filter->allowedApps());
+ $this->assertEquals([], $this->filter->allowedApps());
}
public function testFilterTypes() {
use OCA\TwoFactorBackupCodes\Service\BackupCodeStorage;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
+use OCP\ILogger;
use OCP\IUser;
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
/** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
private $activityManager;
+ /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
+ private $logger;
+
/** @var BackupCodeStorage */
private $storage;
$this->random = $this->getMockBuilder(ISecureRandom::class)->getMock();
$this->hasher = $this->getMockBuilder(IHasher::class)->getMock();
$this->activityManager = $this->createMock(IManager::class);
- $this->storage = new BackupCodeStorage($this->mapper, $this->random, $this->hasher, $this->activityManager);
+ $this->logger = $this->createMock(ILogger::class);
+
+ $this->storage = new BackupCodeStorage($this->mapper, $this->random, $this->hasher, $this->activityManager, $this->logger);
}
public function testCreateCodes() {
use OCP\AppFramework\QueryException;
use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\IConfig;
+use OCP\ILogger;
use OCP\ISession;
use OCP\IUser;
/** @var IManager */
private $activityManager;
+ /** @var ILogger */
+ private $logger;
+
/**
* @param AppManager $appManager
* @param ISession $session
* @param IConfig $config
+ * @param IManager $activityManager
+ * @param ILogger $logger
*/
- public function __construct(AppManager $appManager, ISession $session, IConfig $config, IManager $activityManager) {
+ public function __construct(AppManager $appManager, ISession $session, IConfig $config, IManager $activityManager,
+ ILogger $logger) {
$this->appManager = $appManager;
$this->session = $session;
$this->config = $config;
$this->activityManager = $activityManager;
+ $this->logger = $logger;
}
/**
private function publishEvent(IUser $user, $event, array $params) {
$activity = $this->activityManager->generateEvent();
$activity->setApp('twofactor_generic')
- ->setType('twofactor_generic')
+ ->setType('twofactor')
->setAuthor($user->getUID())
- ->setAffectedUser($user->getUID());
- $activity->setSubject($event, $params);
- $this->activityManager->publish($activity);
+ ->setAffectedUser($user->getUID())
+ ->setSubject($event, $params);
+ try {
+ $this->activityManager->publish($activity);
+ } catch (Exception $e) {
+ $this->logger->warning('could not publish backup code creation activity', ['app' => 'twofactor_backupcodes']);
+ $this->logger->logException($e, ['app' => 'twofactor_backupcodes']);
+ }
}
/**
});
$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
- return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager());
+ return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
});
$this->registerService('NavigationManager', function ($c) {