diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-12-19 15:44:11 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-01-27 16:54:13 +0300 |
commit | 528e66d1d7d117de953cf3d4e9995644e7fbd420 (patch) | |
tree | 76a38363bfa2406389564b23f0a44b7cb5d4e5f8 /tests | |
parent | f38a81be60420f69a52ba89ccdd993c0c8c1d3b4 (diff) |
Fix automatic provisioning (for new users)
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Unit/Http/Middleware/ProvisioningMiddlewareTest.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/Unit/Http/Middleware/ProvisioningMiddlewareTest.php b/tests/Unit/Http/Middleware/ProvisioningMiddlewareTest.php index 1fac60021..3f42fe201 100644 --- a/tests/Unit/Http/Middleware/ProvisioningMiddlewareTest.php +++ b/tests/Unit/Http/Middleware/ProvisioningMiddlewareTest.php @@ -26,6 +26,7 @@ namespace OCA\Mail\Tests\Unit\Http\Middleware; 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; @@ -86,6 +87,13 @@ class ProvisioningMiddlewareTest extends TestCase { $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)); @@ -103,6 +111,13 @@ class ProvisioningMiddlewareTest extends TestCase { $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') @@ -119,11 +134,60 @@ class ProvisioningMiddlewareTest extends TestCase { ); } + 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') |