Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Controller/SAMLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\Attribute\UseSession;
use OCP\AppFramework\Services\IAppConfig;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
Expand All @@ -38,6 +39,7 @@
use OCP\Security\ICrypto;
use OCP\Security\ITrustedDomainHelper;
use OCP\Server;
use OCP\User\Events\UserLoggedInEvent;
use OneLogin\Saml2\Auth;
use OneLogin\Saml2\Error;
use OneLogin\Saml2\Settings;
Expand Down Expand Up @@ -66,6 +68,7 @@ public function __construct(
private ICrypto $crypto,
private ITrustedDomainHelper $trustedDomainHelper,
private SessionService $sessionService,
private IEventDispatcher $eventDispatcher,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -402,6 +405,7 @@ public function assertionConsumerService(): Http\RedirectResponse {
if ($firstLogin) {
$this->userBackend->initializeHomeDir($user->getUID());
}
$this->eventDispatcher->dispatchTyped(new UserLoggedInEvent($user, $user->getUID(), null, false));
} catch (NoUserFoundException) {
throw new \InvalidArgumentException('User "' . $this->userBackend->getCurrentUserId() . '" is not valid');
} catch (Exception $e) {
Expand Down
12 changes: 9 additions & 3 deletions tests/unit/Controller/SAMLControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
Expand All @@ -28,6 +29,7 @@
use OCP\IUserSession;
use OCP\Security\ICrypto;
use OCP\Security\ITrustedDomainHelper;
use OCP\User\Events\UserLoggedInEvent;
use Override;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
Expand All @@ -49,8 +51,9 @@ class SAMLControllerTest extends TestCase {
private IL10N&MockObject $l;
private ICrypto&MockObject $crypto;
private SAMLController $samlController;
private ITrustedDomainHelper|MockObject $trustedDomainController;
private SessionService|MockObject $sessionService;
private ITrustedDomainHelper&MockObject $trustedDomainController;
private SessionService&MockObject $sessionService;
private IEventDispatcher&MockObject $eventDispatcher;

#[Override]
protected function setUp(): void {
Expand All @@ -71,6 +74,7 @@ protected function setUp(): void {
$this->crypto = $this->createMock(ICrypto::class);
$this->trustedDomainController = $this->createMock(ITrustedDomainHelper::class);
$this->sessionService = $this->createMock(SessionService::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);

$this->l->expects($this->any())->method('t')->willReturnCallback(
static fn (string $param): string => $param
Expand All @@ -95,7 +99,8 @@ protected function setUp(): void {
$this->userData,
$this->crypto,
$this->trustedDomainController,
$this->sessionService
$this->sessionService,
$this->eventDispatcher,
);
}

Expand Down Expand Up @@ -263,6 +268,7 @@ public function testLoginWithEnvVariable(array $samlUserData, string $redirect,

if (isset($samlUserData['uid']) && !($userState === 0 && $autoProvision === 0)) {
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('MyUid');
$im = $this->userResolver
->expects($this->once())
->method('findExistingUser')
Expand Down
Loading