Skip to content
Merged
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
Fix automatic provisioning (for new users)
Signed-off-by: Christoph Wurst <[email protected]>
  • Loading branch information
ChristophWurst committed Jan 27, 2020
commit 528e66d1d7d117de953cf3d4e9995644e7fbd420
5 changes: 5 additions & 0 deletions lib/Http/Middleware/ProvisioningMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ public function beforeController($controller, $methodName) {
// Nothing to update
return;
}
$config = $this->provisioningManager->getConfig();
if ($config === null || !$config->isActive()) {
return;
}
try {
$this->provisioningManager->provisionSingleUser($config, $user);
$this->provisioningManager->updatePassword(
$user,
$this->credentialStore->getLoginCredentials()->getPassword()
Expand Down
64 changes: 64 additions & 0 deletions tests/Unit/Http/Middleware/ProvisioningMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use ChristophWurst\Nextcloud\Testing\TestCase;
use OCA\Mail\Controller\PageController;
use OCA\Mail\Http\Middleware\ProvisioningMiddleware;
use OCA\Mail\Service\Provisioning\Config;
use OCA\Mail\Service\Provisioning\Manager;
use OCP\Authentication\Exceptions\CredentialsUnavailableException;
use OCP\Authentication\Exceptions\PasswordUnavailableException;
Expand Down Expand Up @@ -86,6 +87,13 @@ public function testBeforeControllerNoCredentialsAvailable() {
$this->userSession->expects($this->once())
->method('getUser')
->willReturn($user);
$config = $this->createMock(Config::class);
$this->provisioningManager->expects($this->once())
->method('getConfig')
->willReturn($config);
$config->expects($this->once())
->method('isActive')
->willReturn(true);
$this->credentialStore->expects($this->once())
->method('getLoginCredentials')
->willThrowException($this->createMock(CredentialsUnavailableException::class));
Expand All @@ -103,6 +111,13 @@ public function testBeforeControllerNoPasswordAvailable() {
$this->userSession->expects($this->once())
->method('getUser')
->willReturn($user);
$config = $this->createMock(Config::class);
$this->provisioningManager->expects($this->once())
->method('getConfig')
->willReturn($config);
$config->expects($this->once())
->method('isActive')
->willReturn(true);
$credentials = $this->createMock(ICredentials::class);
$this->credentialStore->expects($this->once())
->method('getLoginCredentials')
Expand All @@ -119,11 +134,60 @@ public function testBeforeControllerNoPasswordAvailable() {
);
}

public function testBeforeControllerNoConfigAvailable() {
$user = $this->createMock(IUser::class);
$this->userSession->expects($this->once())
->method('getUser')
->willReturn($user);
$this->provisioningManager->expects($this->once())
->method('getConfig')
->willReturn(null);
$this->credentialStore->expects($this->never())
->method('getLoginCredentials');
$this->provisioningManager->expects($this->never())
->method('updatePassword');

$this->middleware->beforeController(
$this->createMock(PageController::class),
'index'
);
}

public function testBeforeControllerNotActive() {
$user = $this->createMock(IUser::class);
$this->userSession->expects($this->once())
->method('getUser')
->willReturn($user);
$config = $this->createMock(Config::class);
$this->provisioningManager->expects($this->once())
->method('getConfig')
->willReturn($config);
$config->expects($this->once())
->method('isActive')
->willReturn(false);
$this->credentialStore->expects($this->never())
->method('getLoginCredentials');
$this->provisioningManager->expects($this->never())
->method('updatePassword');

$this->middleware->beforeController(
$this->createMock(PageController::class),
'index'
);
}

public function testBeforeController() {
$user = $this->createMock(IUser::class);
$this->userSession->expects($this->once())
->method('getUser')
->willReturn($user);
$config = $this->createMock(Config::class);
$this->provisioningManager->expects($this->once())
->method('getConfig')
->willReturn($config);
$config->expects($this->once())
->method('isActive')
->willReturn(true);
$credentials = $this->createMock(ICredentials::class);
$this->credentialStore->expects($this->once())
->method('getLoginCredentials')
Expand Down