summaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/tests
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2020-08-09 16:36:19 +0200
committerDaniel Kesselberg <mail@danielkesselberg.de>2020-08-09 18:38:19 +0200
commitc19bdb05e8cf24317d6ea3a58951a4e0102b2e70 (patch)
tree7b417e7328f479973615da2a8e2f9f203acb7cbc /apps/provisioning_api/tests
parent3db61c43abf5b034e7850f87b122524ab24aeb66 (diff)
downloadnextcloud-server-c19bdb05e8cf24317d6ea3a58951a4e0102b2e70.tar.gz
nextcloud-server-c19bdb05e8cf24317d6ea3a58951a4e0102b2e70.zip
Generate password on addUser by password_policy app
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'apps/provisioning_api/tests')
-rw-r--r--apps/provisioning_api/tests/Controller/UsersControllerTest.php51
1 files changed, 50 insertions, 1 deletions
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
index 152a6526653..ceb84cbed4e 100644
--- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
@@ -48,6 +48,7 @@ use OCA\Provisioning_API\FederatedShareProviderFactory;
use OCA\Settings\Mailer\NewUserMailHelper;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\DataResponse;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IL10N;
@@ -58,6 +59,7 @@ use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Mail\IEMailTemplate;
+use OCP\Security\Events\GenerateSecurePasswordEvent;
use OCP\Security\ISecureRandom;
use OCP\UserInterface;
use PHPUnit\Framework\MockObject\MockObject;
@@ -94,6 +96,8 @@ class UsersControllerTest extends TestCase {
private $secureRandom;
/** @var RemoteWipe|MockObject */
private $remoteWipe;
+ /** @var IEventDispatcher */
+ private $eventDispatcher;
protected function setUp(): void {
parent::setUp();
@@ -111,6 +115,7 @@ class UsersControllerTest extends TestCase {
$this->federatedShareProviderFactory = $this->createMock(FederatedShareProviderFactory::class);
$this->secureRandom = $this->createMock(ISecureRandom::class);
$this->remoteWipe = $this->createMock(RemoteWipe::class);
+ $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->api = $this->getMockBuilder(UsersController::class)
->setConstructorArgs([
@@ -128,6 +133,7 @@ class UsersControllerTest extends TestCase {
$this->federatedShareProviderFactory,
$this->secureRandom,
$this->remoteWipe,
+ $this->eventDispatcher,
])
->setMethods(['fillStorageInfo'])
->getMock();
@@ -389,7 +395,8 @@ class UsersControllerTest extends TestCase {
$this->newUserMailHelper,
$this->federatedShareProviderFactory,
$this->secureRandom,
- $this->remoteWipe
+ $this->remoteWipe,
+ $this->eventDispatcher,
])
->setMethods(['editUser'])
->getMock();
@@ -486,6 +493,46 @@ class UsersControllerTest extends TestCase {
));
}
+ public function testAddUserSuccessfulGeneratePassword() {
+ $this->userManager
+ ->expects($this->once())
+ ->method('userExists')
+ ->with('NewUser')
+ ->willReturn(false);
+ $this->userManager
+ ->expects($this->once())
+ ->method('createUser');
+ $this->logger
+ ->expects($this->once())
+ ->method('info')
+ ->with('Successful addUser call with userid: NewUser', ['app' => 'ocs_api']);
+ $loggedInUser = $this->getMockBuilder(IUser::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $loggedInUser
+ ->expects($this->once())
+ ->method('getUID')
+ ->willReturn('adminUser');
+ $this->userSession
+ ->expects($this->once())
+ ->method('getUser')
+ ->willReturn($loggedInUser);
+ $this->groupManager
+ ->expects($this->once())
+ ->method('isAdmin')
+ ->with('adminUser')
+ ->willReturn(true);
+ $this->eventDispatcher
+ ->expects($this->once())
+ ->method('dispatchTyped')
+ ->with(new GenerateSecurePasswordEvent());
+
+ $this->assertTrue(key_exists(
+ 'id',
+ $this->api->addUser('NewUser', '', '', 'foo@bar')->getData()
+ ));
+ }
+
public function testAddUserFailedToGenerateUserID() {
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
@@ -3126,6 +3173,7 @@ class UsersControllerTest extends TestCase {
$this->federatedShareProviderFactory,
$this->secureRandom,
$this->remoteWipe,
+ $this->eventDispatcher,
])
->setMethods(['getUserData'])
->getMock();
@@ -3190,6 +3238,7 @@ class UsersControllerTest extends TestCase {
$this->federatedShareProviderFactory,
$this->secureRandom,
$this->remoteWipe,
+ $this->eventDispatcher,
])
->setMethods(['getUserData'])
->getMock();