diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2019-02-18 17:38:38 +0100 |
---|---|---|
committer | Daniel Kesselberg <mail@danielkesselberg.de> | 2019-02-18 17:47:43 +0100 |
commit | c583c5e7e2608c3a5a1f5d15f750b7f3f57c6c93 (patch) | |
tree | 45f28d5df2dbf56d11aa75f96a3b82c2a7fe40e4 /tests/Core | |
parent | 149a98edf69558ade2176467fd1d78919ee0b8c7 (diff) | |
download | nextcloud-server-c583c5e7e2608c3a5a1f5d15f750b7f3f57c6c93.tar.gz nextcloud-server-c583c5e7e2608c3a5a1f5d15f750b7f3f57c6c93.zip |
Emit event if app password created
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'tests/Core')
-rw-r--r-- | tests/Core/Controller/AppPasswordControllerTest.php | 29 | ||||
-rw-r--r-- | tests/Core/Controller/ClientFlowLoginControllerTest.php | 44 |
2 files changed, 23 insertions, 50 deletions
diff --git a/tests/Core/Controller/AppPasswordControllerTest.php b/tests/Core/Controller/AppPasswordControllerTest.php index ace6170f984..a66bcb3fc26 100644 --- a/tests/Core/Controller/AppPasswordControllerTest.php +++ b/tests/Core/Controller/AppPasswordControllerTest.php @@ -27,18 +27,16 @@ namespace Tests\Core\Controller; use OC\Authentication\Token\IProvider; use OC\Authentication\Token\IToken; use OC\Core\Controller\AppPasswordController; -use OCP\Activity\IEvent; -use OCP\Activity\IManager as IActivityManager; use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\Authentication\Exceptions\CredentialsUnavailableException; use OCP\Authentication\Exceptions\PasswordUnavailableException; use OCP\Authentication\LoginCredentials\ICredentials; use OCP\Authentication\LoginCredentials\IStore; -use OCP\ILogger; use OCP\IRequest; use OCP\ISession; use OCP\Security\ISecureRandom; use PHPUnit\Framework\MockObject\MockObject; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; class AppPasswordControllerTest extends TestCase { @@ -58,8 +56,8 @@ class AppPasswordControllerTest extends TestCase { /** @var IRequest|MockObject */ private $request; - /** @var IActivityManager|\PHPUnit_Framework_MockObject_MockObject */ - private $activityManager; + /** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */ + private $eventDispatcher; /** @var AppPasswordController */ private $controller; @@ -72,9 +70,7 @@ class AppPasswordControllerTest extends TestCase { $this->tokenProvider = $this->createMock(IProvider::class); $this->credentialStore = $this->createMock(IStore::class); $this->request = $this->createMock(IRequest::class); - $this->activityManager = $this->createMock(IActivityManager::class); - /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject $logger */ - $logger = $this->createMock(ILogger::class); + $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); $this->controller = new AppPasswordController( 'core', @@ -83,8 +79,7 @@ class AppPasswordControllerTest extends TestCase { $this->random, $this->tokenProvider, $this->credentialStore, - $this->activityManager, - $logger + $this->eventDispatcher ); } @@ -145,11 +140,8 @@ class AppPasswordControllerTest extends TestCase { IToken::DO_NOT_REMEMBER ); - $this->activityManager->expects($this->once()) - ->method('generateEvent') - ->willReturn($this->createMock(IEvent::class)); - $this->activityManager->expects($this->once()) - ->method('publish'); + $this->eventDispatcher->expects($this->once()) + ->method('dispatch'); $this->controller->getAppPassword(); } @@ -189,11 +181,8 @@ class AppPasswordControllerTest extends TestCase { IToken::DO_NOT_REMEMBER ); - $this->activityManager->expects($this->once()) - ->method('generateEvent') - ->willReturn($this->createMock(IEvent::class)); - $this->activityManager->expects($this->once()) - ->method('publish'); + $this->eventDispatcher->expects($this->once()) + ->method('dispatch'); $this->controller->getAppPassword(); } diff --git a/tests/Core/Controller/ClientFlowLoginControllerTest.php b/tests/Core/Controller/ClientFlowLoginControllerTest.php index ed84d456de1..73b8118a876 100644 --- a/tests/Core/Controller/ClientFlowLoginControllerTest.php +++ b/tests/Core/Controller/ClientFlowLoginControllerTest.php @@ -29,13 +29,10 @@ use OC\Core\Controller\ClientFlowLoginController; use OCA\OAuth2\Db\AccessTokenMapper; use OCA\OAuth2\Db\Client; use OCA\OAuth2\Db\ClientMapper; -use OCP\Activity\IEvent; -use OCP\Activity\IManager as IActivityManager; use OCP\AppFramework\Http; use OCP\AppFramework\Http\StandaloneTemplateResponse; use OCP\Defaults; use OCP\IL10N; -use OCP\ILogger; use OCP\IRequest; use OCP\ISession; use OCP\IURLGenerator; @@ -44,6 +41,7 @@ use OCP\IUserSession; use OCP\Security\ICrypto; use OCP\Security\ISecureRandom; use OCP\Session\Exceptions\SessionNotAvailableException; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; class ClientFlowLoginControllerTest extends TestCase { @@ -69,8 +67,9 @@ class ClientFlowLoginControllerTest extends TestCase { private $accessTokenMapper; /** @var ICrypto|\PHPUnit_Framework_MockObject_MockObject */ private $crypto; - /** @var IActivityManager|\PHPUnit_Framework_MockObject_MockObject */ - private $activityManager; + /** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */ + private $eventDispatcher; + /** @var ClientFlowLoginController */ private $clientFlowLoginController; @@ -95,9 +94,7 @@ class ClientFlowLoginControllerTest extends TestCase { $this->clientMapper = $this->createMock(ClientMapper::class); $this->accessTokenMapper = $this->createMock(AccessTokenMapper::class); $this->crypto = $this->createMock(ICrypto::class); - $this->activityManager = $this->createMock(IActivityManager::class); - /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject $logger */ - $logger = $this->createMock(ILogger::class); + $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); $this->clientFlowLoginController = new ClientFlowLoginController( 'core', @@ -112,8 +109,7 @@ class ClientFlowLoginControllerTest extends TestCase { $this->clientMapper, $this->accessTokenMapper, $this->crypto, - $this->activityManager, - $logger + $this->eventDispatcher ); } @@ -388,11 +384,8 @@ class ClientFlowLoginControllerTest extends TestCase { ->method('getHeader') ->willReturn(''); - $this->activityManager->expects($this->once()) - ->method('generateEvent') - ->willReturn($this->createMock(IEvent::class)); - $this->activityManager->expects($this->once()) - ->method('publish'); + $this->eventDispatcher->expects($this->once()) + ->method('dispatch'); $expected = new Http\RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken'); $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken')); @@ -478,11 +471,8 @@ class ClientFlowLoginControllerTest extends TestCase { ->with('MyClientIdentifier') ->willReturn($client); - $this->activityManager->expects($this->once()) - ->method('generateEvent') - ->willReturn($this->createMock(IEvent::class)); - $this->activityManager->expects($this->once()) - ->method('publish'); + $this->eventDispatcher->expects($this->once()) + ->method('dispatch'); $expected = new Http\RedirectResponse('https://example.com/redirect.php?state=MyOauthState&code=MyAccessCode'); $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken', 'MyClientIdentifier')); @@ -556,11 +546,8 @@ class ClientFlowLoginControllerTest extends TestCase { ->method('getHeader') ->willReturn(''); - $this->activityManager->expects($this->once()) - ->method('generateEvent') - ->willReturn($this->createMock(IEvent::class)); - $this->activityManager->expects($this->once()) - ->method('publish'); + $this->eventDispatcher->expects($this->once()) + ->method('dispatch'); $expected = new Http\RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken'); $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken')); @@ -690,11 +677,8 @@ class ClientFlowLoginControllerTest extends TestCase { ->method('getHeader') ->willReturnMap($headers); - $this->activityManager->expects($this->once()) - ->method('generateEvent') - ->willReturn($this->createMock(IEvent::class)); - $this->activityManager->expects($this->once()) - ->method('publish'); + $this->eventDispatcher->expects($this->once()) + ->method('dispatch'); $expected = new Http\RedirectResponse('nc://login/server:' . $expected . '://example.com&user:MyLoginName&password:MyGeneratedToken'); $this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken')); |