|
|
|
|
@ -29,10 +29,13 @@ 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; |
|
|
|
|
@ -66,6 +69,8 @@ class ClientFlowLoginControllerTest extends TestCase { |
|
|
|
|
private $accessTokenMapper; |
|
|
|
|
/** @var ICrypto|\PHPUnit_Framework_MockObject_MockObject */ |
|
|
|
|
private $crypto; |
|
|
|
|
/** @var IActivityManager|\PHPUnit_Framework_MockObject_MockObject */ |
|
|
|
|
private $activityManager; |
|
|
|
|
|
|
|
|
|
/** @var ClientFlowLoginController */ |
|
|
|
|
private $clientFlowLoginController; |
|
|
|
|
@ -90,6 +95,9 @@ 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->clientFlowLoginController = new ClientFlowLoginController( |
|
|
|
|
'core', |
|
|
|
|
@ -103,7 +111,9 @@ class ClientFlowLoginControllerTest extends TestCase { |
|
|
|
|
$this->urlGenerator, |
|
|
|
|
$this->clientMapper, |
|
|
|
|
$this->accessTokenMapper, |
|
|
|
|
$this->crypto |
|
|
|
|
$this->crypto, |
|
|
|
|
$this->activityManager, |
|
|
|
|
$logger |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -378,6 +388,12 @@ 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'); |
|
|
|
|
|
|
|
|
|
$expected = new Http\RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken'); |
|
|
|
|
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken')); |
|
|
|
|
} |
|
|
|
|
@ -462,6 +478,12 @@ 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'); |
|
|
|
|
|
|
|
|
|
$expected = new Http\RedirectResponse('https://example.com/redirect.php?state=MyOauthState&code=MyAccessCode'); |
|
|
|
|
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken', 'MyClientIdentifier')); |
|
|
|
|
} |
|
|
|
|
@ -534,6 +556,12 @@ 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'); |
|
|
|
|
|
|
|
|
|
$expected = new Http\RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken'); |
|
|
|
|
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken')); |
|
|
|
|
} |
|
|
|
|
@ -662,6 +690,12 @@ 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'); |
|
|
|
|
|
|
|
|
|
$expected = new Http\RedirectResponse('nc://login/server:' . $expected . '://example.com&user:MyLoginName&password:MyGeneratedToken'); |
|
|
|
|
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken')); |
|
|
|
|
} |
|
|
|
|
|