]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix minor issues
authorChristoph Wurst <christoph@winzerhof-wurst.at>
Tue, 13 Dec 2016 14:15:14 +0000 (15:15 +0100)
committerChristoph Wurst <christoph@winzerhof-wurst.at>
Mon, 19 Dec 2016 10:59:48 +0000 (11:59 +0100)
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
apps/twofactor_backupcodes/lib/Activity/GenericFilter.php
apps/twofactor_backupcodes/lib/Activity/Provider.php
apps/twofactor_backupcodes/lib/Service/BackupCodeStorage.php
apps/twofactor_backupcodes/tests/Unit/Activity/GenericFilterTest.php
apps/twofactor_backupcodes/tests/Unit/Service/BackupCodeStorageTest.php
lib/private/Authentication/TwoFactorAuth/Manager.php
lib/private/Server.php

index f2b0ef6f23f6bc25b689730e2aee66e5e1b24ed1..27c0274b600ae46aebb3b92654d8a314a15afc1d 100644 (file)
@@ -40,7 +40,7 @@ class GenericFilter implements IFilter {
        }
 
        public function allowedApps() {
-               return null;
+               return [];
        }
 
        public function filterTypes(array $types) {
index db139a0e6741c4e6ecf17022c38abbef4b6c8ed8..cfb16c9f8d31fa3d61d744be69a4694b78d47695 100644 (file)
@@ -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:
index d7bcfe014750c8ffdc0e43d63d8fe76276bdf915..d9f75fa5a33f9cbcd98058e250e02ea64089d171 100644 (file)
 
 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']);
+               }
        }
 
        /**
index a367a18fe95cf02181c0643b04da6b637392dc13..ca24c0be647226bb280fe3896963e93ac57329ab 100644 (file)
@@ -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() {
index fbaac0220aa3cf6ed87ad1458c3f7b3df6e4d999..54738f74600a17b01df6ee2f8f5f0d9fac32ff22 100644 (file)
@@ -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() {
index 297e69fac99a900ba4246a6f8d0c239c1a28a16b..1d0deada69657c3b9ceef349213b8e2bb9dffa85 100644 (file)
@@ -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']);
+               }
        }
 
        /**
index d51ae7d86552ff9de6c69f5968958f21495f38b2..6f4d4f066e720715db147d4832357988335352a8 100644 (file)
@@ -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) {