Skip to content

Commit 528e66d

Browse files
Fix automatic provisioning (for new users)
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent f38a81b commit 528e66d

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

lib/Http/Middleware/ProvisioningMiddleware.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ public function beforeController($controller, $methodName) {
6565
// Nothing to update
6666
return;
6767
}
68+
$config = $this->provisioningManager->getConfig();
69+
if ($config === null || !$config->isActive()) {
70+
return;
71+
}
6872
try {
73+
$this->provisioningManager->provisionSingleUser($config, $user);
6974
$this->provisioningManager->updatePassword(
7075
$user,
7176
$this->credentialStore->getLoginCredentials()->getPassword()

tests/Unit/Http/Middleware/ProvisioningMiddlewareTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use ChristophWurst\Nextcloud\Testing\TestCase;
2727
use OCA\Mail\Controller\PageController;
2828
use OCA\Mail\Http\Middleware\ProvisioningMiddleware;
29+
use OCA\Mail\Service\Provisioning\Config;
2930
use OCA\Mail\Service\Provisioning\Manager;
3031
use OCP\Authentication\Exceptions\CredentialsUnavailableException;
3132
use OCP\Authentication\Exceptions\PasswordUnavailableException;
@@ -86,6 +87,13 @@ public function testBeforeControllerNoCredentialsAvailable() {
8687
$this->userSession->expects($this->once())
8788
->method('getUser')
8889
->willReturn($user);
90+
$config = $this->createMock(Config::class);
91+
$this->provisioningManager->expects($this->once())
92+
->method('getConfig')
93+
->willReturn($config);
94+
$config->expects($this->once())
95+
->method('isActive')
96+
->willReturn(true);
8997
$this->credentialStore->expects($this->once())
9098
->method('getLoginCredentials')
9199
->willThrowException($this->createMock(CredentialsUnavailableException::class));
@@ -103,6 +111,13 @@ public function testBeforeControllerNoPasswordAvailable() {
103111
$this->userSession->expects($this->once())
104112
->method('getUser')
105113
->willReturn($user);
114+
$config = $this->createMock(Config::class);
115+
$this->provisioningManager->expects($this->once())
116+
->method('getConfig')
117+
->willReturn($config);
118+
$config->expects($this->once())
119+
->method('isActive')
120+
->willReturn(true);
106121
$credentials = $this->createMock(ICredentials::class);
107122
$this->credentialStore->expects($this->once())
108123
->method('getLoginCredentials')
@@ -119,11 +134,60 @@ public function testBeforeControllerNoPasswordAvailable() {
119134
);
120135
}
121136

137+
public function testBeforeControllerNoConfigAvailable() {
138+
$user = $this->createMock(IUser::class);
139+
$this->userSession->expects($this->once())
140+
->method('getUser')
141+
->willReturn($user);
142+
$this->provisioningManager->expects($this->once())
143+
->method('getConfig')
144+
->willReturn(null);
145+
$this->credentialStore->expects($this->never())
146+
->method('getLoginCredentials');
147+
$this->provisioningManager->expects($this->never())
148+
->method('updatePassword');
149+
150+
$this->middleware->beforeController(
151+
$this->createMock(PageController::class),
152+
'index'
153+
);
154+
}
155+
156+
public function testBeforeControllerNotActive() {
157+
$user = $this->createMock(IUser::class);
158+
$this->userSession->expects($this->once())
159+
->method('getUser')
160+
->willReturn($user);
161+
$config = $this->createMock(Config::class);
162+
$this->provisioningManager->expects($this->once())
163+
->method('getConfig')
164+
->willReturn($config);
165+
$config->expects($this->once())
166+
->method('isActive')
167+
->willReturn(false);
168+
$this->credentialStore->expects($this->never())
169+
->method('getLoginCredentials');
170+
$this->provisioningManager->expects($this->never())
171+
->method('updatePassword');
172+
173+
$this->middleware->beforeController(
174+
$this->createMock(PageController::class),
175+
'index'
176+
);
177+
}
178+
122179
public function testBeforeController() {
123180
$user = $this->createMock(IUser::class);
124181
$this->userSession->expects($this->once())
125182
->method('getUser')
126183
->willReturn($user);
184+
$config = $this->createMock(Config::class);
185+
$this->provisioningManager->expects($this->once())
186+
->method('getConfig')
187+
->willReturn($config);
188+
$config->expects($this->once())
189+
->method('isActive')
190+
->willReturn(true);
127191
$credentials = $this->createMock(ICredentials::class);
128192
$this->credentialStore->expects($this->once())
129193
->method('getLoginCredentials')

0 commit comments

Comments
 (0)