Skip to content

Commit 30c9200

Browse files
committed
Fix bug caused by class property not being set in ServerController::logout().
1 parent c4e260a commit 30c9200

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

solid/lib/Controller/ServerController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use OCA\Solid\DpopFactoryTrait;
55
use OCA\Solid\ServerConfig;
6+
use OCA\Solid\Service\UserService;
67

78
use OCP\AppFramework\Controller;
89
use OCP\AppFramework\Http;
@@ -47,6 +48,8 @@ class ServerController extends Controller
4748
/* @var \Pdsinterop\Solid\Auth\TokenGenerator */
4849
private $tokenGenerator;
4950

51+
private UserService $userService;
52+
5053
public function __construct(
5154
$AppName,
5255
IRequest $request,
@@ -55,7 +58,7 @@ public function __construct(
5558
IURLGenerator $urlGenerator,
5659
$userId,
5760
IConfig $config,
58-
\OCA\Solid\Service\UserService $UserService,
61+
\OCA\Solid\Service\UserService $userService,
5962
IDBConnection $connection,
6063
) {
6164
parent::__construct($AppName, $request);
@@ -66,6 +69,7 @@ public function __construct(
6669
$this->request = $request;
6770
$this->urlGenerator = $urlGenerator;
6871
$this->session = $session;
72+
$this->userService = $userService;
6973

7074
$this->setJtiStorage($connection);
7175

solid/tests/Unit/Controller/ServerControllerTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,45 @@ public function testToken()
421421
$this->assertEquals($expected, $actual);
422422
}
423423

424+
/**
425+
* @testdox ServerController should return an OK when asked to logout
426+
*
427+
* @covers ::logout
428+
*/
429+
public function testLogout() {
430+
$parameters = $this->createMockConstructorParameters();
431+
432+
$controller = new ServerController(...array_values($parameters));
433+
434+
$actual = $controller->logout();
435+
$expected = new JSONResponse('ok', Http::STATUS_OK);
436+
437+
$this->assertEquals($expected, $actual);
438+
}
439+
440+
/**
441+
* @testdox ServerController should complain when asked to logout and the logout fails
442+
*
443+
* @covers ::logout
444+
*/
445+
public function testLogoutError() {
446+
$parameters = $this->createMockConstructorParameters();
447+
448+
$mockError = 'Mock logout error';
449+
$expectedException = new \Exception($mockError);
450+
$parameters['MockUserService']
451+
->method('logout')
452+
->willThrowException($expectedException)
453+
;
454+
455+
$controller = new ServerController(...array_values($parameters));
456+
457+
$this->expectException($expectedException::class);
458+
$this->expectExceptionMessage($mockError);
459+
460+
$controller->logout();
461+
}
462+
424463
////////////////////////////// MOCKS AND STUBS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
425464

426465
public function createMockConfig($clientData): IConfig|MockObject

0 commit comments

Comments
 (0)