summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2016-12-13 15:15:14 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2016-12-19 11:59:48 +0100
commited4017dfb4d605943988c6686b088b41d1680110 (patch)
treec50d57d247c46b20e514f10f3b381820c2578b4f
parent93003120461648140ee244b345cfcb6690071faa (diff)
downloadnextcloud-server-ed4017dfb4d605943988c6686b088b41d1680110.tar.gz
nextcloud-server-ed4017dfb4d605943988c6686b088b41d1680110.zip
fix minor issues
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
-rw-r--r--apps/twofactor_backupcodes/lib/Activity/GenericFilter.php2
-rw-r--r--apps/twofactor_backupcodes/lib/Activity/Provider.php2
-rw-r--r--apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php20
-rw-r--r--apps/twofactor_backupcodes/tests/Unit/Activity/GenericFilterTest.php3
-rw-r--r--apps/twofactor_backupcodes/tests/Unit/Service/BackupCodeStorageTest.php8
-rw-r--r--lib/private/Authentication/TwoFactorAuth/Manager.php23
-rw-r--r--lib/private/Server.php2
7 files changed, 45 insertions, 15 deletions
diff --git a/apps/twofactor_backupcodes/lib/Activity/GenericFilter.php b/apps/twofactor_backupcodes/lib/Activity/GenericFilter.php
index f2b0ef6f23f..27c0274b600 100644
--- a/apps/twofactor_backupcodes/lib/Activity/GenericFilter.php
+++ b/apps/twofactor_backupcodes/lib/Activity/GenericFilter.php
@@ -40,7 +40,7 @@ class GenericFilter implements IFilter {
}
public function allowedApps() {
- return null;
+ return [];
}
public function filterTypes(array $types) {
diff --git a/apps/twofactor_backupcodes/lib/Activity/Provider.php b/apps/twofactor_backupcodes/lib/Activity/Provider.php
index db139a0e674..cfb16c9f8d3 100644
--- a/apps/twofactor_backupcodes/lib/Activity/Provider.php
+++ b/apps/twofactor_backupcodes/lib/Activity/Provider.php
@@ -55,7 +55,7 @@ class Provider implements IProvider {
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:
diff --git a/apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php b/apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php
index d7bcfe01475..d9f75fa5a33 100644
--- a/apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php
+++ b/apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php
@@ -22,9 +22,11 @@
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;
@@ -43,11 +45,16 @@ class BackupCodeStorage {
/** @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;
}
/**
@@ -89,9 +96,14 @@ class BackupCodeStorage {
$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']);
+ }
}
/**
diff --git a/apps/twofactor_backupcodes/tests/Unit/Activity/GenericFilterTest.php b/apps/twofactor_backupcodes/tests/Unit/Activity/GenericFilterTest.php
index a367a18fe95..ca24c0be647 100644
--- a/apps/twofactor_backupcodes/tests/Unit/Activity/GenericFilterTest.php
+++ b/apps/twofactor_backupcodes/tests/Unit/Activity/GenericFilterTest.php
@@ -26,7 +26,6 @@ use OCA\TwoFactorBackupCodes\Activity\GenericFilter;
use OCP\IL10N;
use OCP\IURLGenerator;
use Test\TestCase;
-use function returnValue;
class GenericFilterTest extends TestCase {
@@ -46,7 +45,7 @@ class GenericFilterTest extends TestCase {
}
public function testAllowedApps() {
- $this->assertEquals(0, $this->filter->allowedApps());
+ $this->assertEquals([], $this->filter->allowedApps());
}
public function testFilterTypes() {
diff --git a/apps/twofactor_backupcodes/tests/Unit/Service/BackupCodeStorageTest.php b/apps/twofactor_backupcodes/tests/Unit/Service/BackupCodeStorageTest.php
index fbaac0220aa..54738f74600 100644
--- a/apps/twofactor_backupcodes/tests/Unit/Service/BackupCodeStorageTest.php
+++ b/apps/twofactor_backupcodes/tests/Unit/Service/BackupCodeStorageTest.php
@@ -27,6 +27,7 @@ use OCA\TwoFactorBackupCodes\Db\BackupCodeMapper;
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;
@@ -46,6 +47,9 @@ class BackupCodeStorageTest extends TestCase {
/** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
private $activityManager;
+ /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
+ private $logger;
+
/** @var BackupCodeStorage */
private $storage;
@@ -58,7 +62,9 @@ class BackupCodeStorageTest extends TestCase {
$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() {
diff --git a/lib/private/Authentication/TwoFactorAuth/Manager.php b/lib/private/Authentication/TwoFactorAuth/Manager.php
index 297e69fac99..1d0deada696 100644
--- a/lib/private/Authentication/TwoFactorAuth/Manager.php
+++ b/lib/private/Authentication/TwoFactorAuth/Manager.php
@@ -31,6 +31,7 @@ use OCP\Activity\IManager;
use OCP\AppFramework\QueryException;
use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\IConfig;
+use OCP\ILogger;
use OCP\ISession;
use OCP\IUser;
@@ -53,16 +54,23 @@ class Manager {
/** @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;
}
/**
@@ -211,11 +219,16 @@ class Manager {
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']);
+ }
}
/**
diff --git a/lib/private/Server.php b/lib/private/Server.php
index d51ae7d8655..6f4d4f066e7 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -312,7 +312,7 @@ class Server extends ServerContainer implements IServerContainer {
});
$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) {