Skip to content

Commit 136031b

Browse files
committed
Updating tests and swagger OAPI doc.
1 parent 98e0a8f commit 136031b

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

docs/swagger.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5548,6 +5548,33 @@ paths:
55485548
responses:
55495549
'200':
55505550
description: 'Placeholder response'
5551+
'/v1/users/external-login/{service}/{externalId}':
5552+
get:
5553+
summary: 'Get details of a user identified via external login.'
5554+
description: 'Get details of a user identified via external login.'
5555+
operationId: usersPresenterActionFindByExternalLogin
5556+
parameters:
5557+
-
5558+
name: service
5559+
in: path
5560+
description: 'External authentication service name'
5561+
required: true
5562+
schema:
5563+
type: string
5564+
minLength: 1
5565+
nullable: false
5566+
-
5567+
name: externalId
5568+
in: path
5569+
description: 'External user identifier'
5570+
required: true
5571+
schema:
5572+
type: string
5573+
minLength: 1
5574+
nullable: false
5575+
responses:
5576+
'200':
5577+
description: 'Placeholder response'
55515578
'/v1/users/{id}/invalidate-tokens':
55525579
post:
55535580
summary: 'Invalidate all existing tokens issued for given user'

fixtures/demo/20-groups.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ App\Model\Entity\Login:
155155
- 'demoGroupMember<current()>\@example.com'
156156
- "password"
157157

158+
App\Model\Entity\ExternalLogin:
159+
demoGroupMemberExternalLogin:
160+
__construct:
161+
- @demoGroupMember1
162+
- 'ext-service'
163+
- 'external-login1'
164+
158165
App\Model\Entity\GroupInvitation:
159166
validInviation:
160167
__construct:

tests/Presenters/UsersPresenter.phpt

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ $container = require_once __DIR__ . "/../bootstrap.php";
55
use App\Exceptions\ForbiddenRequestException;
66
use App\Helpers\EmailVerificationHelper;
77
use App\Helpers\AnonymizationHelper;
8-
use App\Model\Entity\Exercise;
98
use App\Model\Entity\Login;
109
use App\Model\Entity\ExternalLogin;
1110
use App\Model\Entity\User;
@@ -225,6 +224,36 @@ class TestUsersPresenter extends Tester\TestCase
225224
Assert::same($user->getId(), $result["payload"]["id"]);
226225
}
227226

227+
public function testFindByExternalLogin()
228+
{
229+
PresenterTestHelper::loginDefaultAdmin($this->container);
230+
$extLogins = $this->presenter->externalLogins->findAll();
231+
Assert::count(1, $extLogins);
232+
$el = $extLogins[0];
233+
234+
$payload = PresenterTestHelper::performPresenterRequest(
235+
$this->presenter,
236+
$this->presenterPath,
237+
'GET',
238+
['action' => 'findByExternalLogin', 'service' => $el->getAuthService(), 'externalId' => $el->getExternalId()]
239+
);
240+
241+
Assert::same($el->getUser()->getId(), $payload["id"]);
242+
}
243+
244+
public function testFindByExternalLoginEmptyResult()
245+
{
246+
PresenterTestHelper::loginDefaultAdmin($this->container);
247+
Assert::exception(function () {
248+
PresenterTestHelper::performPresenterRequest(
249+
$this->presenter,
250+
$this->presenterPath,
251+
'GET',
252+
['action' => 'findByExternalLogin', 'service' => 'ext-service', 'externalId' => 'blabla']
253+
);
254+
}, App\Exceptions\NotFoundException::class);
255+
}
256+
228257
public function testUpdateProfileWithoutEmailAndPassword()
229258
{
230259
PresenterTestHelper::loginDefaultAdmin($this->container);
@@ -857,7 +886,7 @@ class TestUsersPresenter extends Tester\TestCase
857886
Assert::true($payload['privateData']['isExternal']);
858887
Assert::equal(['test-cas' => 'abc'], $payload['privateData']['externalIds']);
859888

860-
$els = $this->presenter->externalLogins->findAll();
889+
$els = $this->presenter->externalLogins->findBy(['authService' => 'test-cas']);
861890
Assert::count(1, $els);
862891
Assert::equal($user->getId(), $els[0]->getUser()->getId());
863892
Assert::equal('abc', $els[0]->getExternalId());
@@ -890,7 +919,7 @@ class TestUsersPresenter extends Tester\TestCase
890919
Assert::true($payload['privateData']['isExternal']);
891920
Assert::equal(['test-cas' => 'abc'], $payload['privateData']['externalIds']);
892921

893-
$els = $this->presenter->externalLogins->findAll();
922+
$els = $this->presenter->externalLogins->findBy(['authService' => 'test-cas']);
894923
Assert::count(1, $els);
895924
Assert::equal($user->getId(), $els[0]->getUser()->getId());
896925
Assert::equal('abc', $els[0]->getExternalId());
@@ -922,7 +951,7 @@ class TestUsersPresenter extends Tester\TestCase
922951
Assert::false($payload['privateData']['isExternal']);
923952
Assert::equal([], $payload['privateData']['externalIds']);
924953

925-
$els = $this->presenter->externalLogins->findAll();
954+
$els = $this->presenter->externalLogins->findBy(['authService' => 'test-cas']);
926955
Assert::count(0, $els);
927956

928957
$this->users->refresh($user);

0 commit comments

Comments
 (0)