Skip to content

Commit 189e91e

Browse files
authored
Merge pull request #5944 from nextcloud/fix/take-sso-into-consideration-when-provisioning
Consider passwordless signins when provisioning accounts
2 parents b2e9746 + 8ae7b9a commit 189e91e

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/Http/Middleware/ProvisioningMiddleware.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,15 @@ public function beforeController($controller, $methodName) {
7070
}
7171
try {
7272
$this->provisioningManager->provisionSingleUser($configs, $user);
73+
$password = $this->credentialStore->getLoginCredentials()->getPassword();
74+
if ($password === null) {
75+
// Nothing to update, might be passwordless signin
76+
$this->logger->debug('No password set for ' . $user->getUID());
77+
return;
78+
}
7379
$this->provisioningManager->updatePassword(
7480
$user,
75-
$this->credentialStore->getLoginCredentials()->getPassword()
81+
$password
7682
);
7783
} catch (CredentialsUnavailableException | PasswordUnavailableException $e) {
7884
// Nothing to update

tests/Unit/Http/Middleware/ProvisioningMiddlewareTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,36 @@ public function testBeforeControllerNoPasswordAvailable() {
140140
);
141141
}
142142

143+
public function testBeforeControllerPasswordlessSignin() {
144+
$user = $this->createConfiguredMock(IUser::class, [
145+
'getEmailAddress' => 'bruce.wayne@batman.com'
146+
]);
147+
$this->userSession->expects($this->once())
148+
->method('getUser')
149+
->willReturn($user);
150+
$configs = [new Provisioning()];
151+
$this->provisioningManager->expects($this->once())
152+
->method('getConfigs')
153+
->willReturn($configs);
154+
$this->provisioningManager->expects($this->once())
155+
->method('provisionSingleUser')
156+
->with($configs, $user);
157+
$credentials = $this->createMock(ICredentials::class);
158+
$this->credentialStore->expects($this->once())
159+
->method('getLoginCredentials')
160+
->willReturn($credentials);
161+
$credentials->expects($this->once())
162+
->method('getPassword')
163+
->willReturn(null);
164+
$this->provisioningManager->expects($this->never())
165+
->method('updatePassword');
166+
167+
$this->middleware->beforeController(
168+
$this->createMock(PageController::class),
169+
'index'
170+
);
171+
}
172+
143173
public function testBeforeControllerNoConfigAvailable() {
144174
$user = $this->createConfiguredMock(IUser::class, [
145175
'getEmailAddress' => 'bruce.wayne@batman.com'

0 commit comments

Comments
 (0)