summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2016-12-20 15:23:36 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2016-12-20 15:23:36 +0100
commit88b7d033dfca053e5a726f04c96c312092671245 (patch)
treec048e08d82a0cab2b2fc67d518678a6724074a70
parent3f4ba2d15d2f8910e852cc0e1e321c72fcad47e8 (diff)
downloadnextcloud-server-88b7d033dfca053e5a726f04c96c312092671245.tar.gz
nextcloud-server-88b7d033dfca053e5a726f04c96c312092671245.zip
fix 2fa activities tests
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
-rw-r--r--tests/lib/Authentication/TwoFactorAuth/ManagerTest.php81
1 files changed, 77 insertions, 4 deletions
diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
index 52f3ca28500..1ea17f5d307 100644
--- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
+++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php
@@ -26,8 +26,11 @@ use Exception;
use OC;
use OC\App\AppManager;
use OC\Authentication\TwoFactorAuth\Manager;
+use OCP\Activity\IEvent;
+use OCP\Activity\IManager;
use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\IConfig;
+use OCP\ILogger;
use OCP\ISession;
use OCP\IUser;
use Test\TestCase;
@@ -49,6 +52,12 @@ class ManagerTest extends TestCase {
/** @var IConfig|PHPUnit_Framework_MockObject_MockObject */
private $config;
+ /** @var IManager|PHPUnit_Framework_MockObject_MockObject */
+ private $activityManager;
+
+ /** @var ILogger|PHPUnit_Framework_MockObject_MockObject */
+ private $logger;
+
/** @var IProvider|PHPUnit_Framework_MockObject_MockObject */
private $fakeProvider;
@@ -59,14 +68,14 @@ class ManagerTest extends TestCase {
parent::setUp();
$this->user = $this->createMock(IUser::class);
- $this->appManager = $this->getMockBuilder('\OC\App\AppManager')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->appManager = $this->createMock('\OC\App\AppManager');
$this->session = $this->createMock(ISession::class);
$this->config = $this->createMock(IConfig::class);
+ $this->activityManager = $this->createMock(IManager::class);
+ $this->logger = $this->createMock(ILogger::class);
$this->manager = $this->getMockBuilder('\OC\Authentication\TwoFactorAuth\Manager')
- ->setConstructorArgs([$this->appManager, $this->session, $this->config])
+ ->setConstructorArgs([$this->appManager, $this->session, $this->config, $this->activityManager, $this->logger])
->setMethods(['loadTwoFactorApp']) // Do not actually load the apps
->getMock();
@@ -228,6 +237,7 @@ class ManagerTest extends TestCase {
$this->prepareProviders();
$challenge = 'passme';
+ $event = $this->createMock(IEvent::class);
$this->fakeProvider->expects($this->once())
->method('verifyChallenge')
->with($this->user, $challenge)
@@ -242,6 +252,37 @@ class ManagerTest extends TestCase {
$this->session->expects($this->at(2))
->method('remove')
->with('two_factor_remember_login');
+ $this->activityManager->expects($this->once())
+ ->method('generateEvent')
+ ->willReturn($event);
+ $this->user->expects($this->any())
+ ->method('getUID')
+ ->willReturn('jos');
+ $event->expects($this->once())
+ ->method('setApp')
+ ->with($this->equalTo('twofactor_generic'))
+ ->willReturnSelf();
+ $event->expects($this->once())
+ ->method('setType')
+ ->with($this->equalTo('twofactor'))
+ ->willReturnSelf();
+ $event->expects($this->once())
+ ->method('setAuthor')
+ ->with($this->equalTo('jos'))
+ ->willReturnSelf();
+ $event->expects($this->once())
+ ->method('setAffectedUser')
+ ->with($this->equalTo('jos'))
+ ->willReturnSelf();
+ $this->fakeProvider->expects($this->once())
+ ->method('getDisplayName')
+ ->willReturn('Fake 2FA');
+ $event->expects($this->once())
+ ->method('setSubject')
+ ->with($this->equalTo('twofactor_success'), $this->equalTo([
+ 'provider' => 'Fake 2FA',
+ ]))
+ ->willReturnSelf();
$this->assertTrue($this->manager->verifyChallenge('email', $this->user, $challenge));
}
@@ -263,12 +304,44 @@ class ManagerTest extends TestCase {
$this->prepareProviders();
$challenge = 'dontpassme';
+ $event = $this->createMock(IEvent::class);
$this->fakeProvider->expects($this->once())
->method('verifyChallenge')
->with($this->user, $challenge)
->will($this->returnValue(false));
$this->session->expects($this->never())
->method('remove');
+ $this->activityManager->expects($this->once())
+ ->method('generateEvent')
+ ->willReturn($event);
+ $this->user->expects($this->any())
+ ->method('getUID')
+ ->willReturn('jos');
+ $event->expects($this->once())
+ ->method('setApp')
+ ->with($this->equalTo('twofactor_generic'))
+ ->willReturnSelf();
+ $event->expects($this->once())
+ ->method('setType')
+ ->with($this->equalTo('twofactor'))
+ ->willReturnSelf();
+ $event->expects($this->once())
+ ->method('setAuthor')
+ ->with($this->equalTo('jos'))
+ ->willReturnSelf();
+ $event->expects($this->once())
+ ->method('setAffectedUser')
+ ->with($this->equalTo('jos'))
+ ->willReturnSelf();
+ $this->fakeProvider->expects($this->once())
+ ->method('getDisplayName')
+ ->willReturn('Fake 2FA');
+ $event->expects($this->once())
+ ->method('setSubject')
+ ->with($this->equalTo('twofactor_failed'), $this->equalTo([
+ 'provider' => 'Fake 2FA',
+ ]))
+ ->willReturnSelf();
$this->assertFalse($this->manager->verifyChallenge('email', $this->user, $challenge));
}