summaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/tests
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2019-06-14 17:07:40 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2019-06-19 17:02:28 +0200
commit5b754a6353d31f0548860f1b17b7c9db0f2ee791 (patch)
tree0be6f0dc16dab6157703a23408a55e84675d3063 /apps/provisioning_api/tests
parentb25838e1572bddb55f512a3137b3651f9fa9d578 (diff)
downloadnextcloud-server-5b754a6353d31f0548860f1b17b7c9db0f2ee791.tar.gz
nextcloud-server-5b754a6353d31f0548860f1b17b7c9db0f2ee791.zip
extends Provisioning API with optional userid and required email
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/provisioning_api/tests')
-rw-r--r--apps/provisioning_api/tests/Controller/UsersControllerTest.php159
1 files changed, 155 insertions, 4 deletions
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
index 7a7f0144524..b064f019f09 100644
--- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
@@ -356,7 +356,10 @@ class UsersControllerTest extends TestCase {
->with('adminUser')
->willReturn(true);
- $this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser')->getData());
+ $this->assertTrue(key_exists(
+ 'UserID',
+ $this->api->addUser('NewUser', 'PasswordOfTheNewUser')->getData()
+ ));
}
public function testAddUserSuccessfulWithDisplayName() {
@@ -413,7 +416,149 @@ class UsersControllerTest extends TestCase {
->method('editUser')
->with('NewUser', 'display', 'DisplayNameOfTheNewUser');
- $this->assertEquals([], $api->addUser('NewUser', 'PasswordOfTheNewUser', 'DisplayNameOfTheNewUser')->getData());
+ $this->assertTrue(key_exists(
+ 'UserID',
+ $api->addUser('NewUser', 'PasswordOfTheNewUser', 'DisplayNameOfTheNewUser')->getData()
+ ));
+ }
+
+ public function testAddUserSuccessfulGenerateUserID() {
+ $this->config
+ ->expects($this->any())
+ ->method('getAppValue')
+ ->willReturnCallback(function($appid, $key, $default) {
+ if($key === 'newUser.generateUserID') {
+ return true;
+ }
+ return null;
+ });
+ $this->userManager
+ ->expects($this->any())
+ ->method('userExists')
+ ->with($this->anything())
+ ->will($this->returnValue(false));
+ $this->userManager
+ ->expects($this->once())
+ ->method('createUser')
+ ->with($this->anything(), 'PasswordOfTheNewUser');
+ $this->logger
+ ->expects($this->once())
+ ->method('info')
+ ->with($this->stringStartsWith('Successful addUser call with userid: '), ['app' => 'ocs_api']);
+ $loggedInUser = $this->getMockBuilder(IUser::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $loggedInUser
+ ->expects($this->once())
+ ->method('getUID')
+ ->will($this->returnValue('adminUser'));
+ $this->userSession
+ ->expects($this->once())
+ ->method('getUser')
+ ->will($this->returnValue($loggedInUser));
+ $this->groupManager
+ ->expects($this->once())
+ ->method('isAdmin')
+ ->with('adminUser')
+ ->willReturn(true);
+ $this->secureRandom->expects($this->any())
+ ->method('generate')
+ ->with(10)
+ ->willReturnCallback(function() { return (string)rand(1000000000, 9999999999); });
+
+ $this->assertTrue(key_exists(
+ 'UserID',
+ $this->api->addUser('', 'PasswordOfTheNewUser')->getData()
+ ));
+ }
+
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSException
+ * @expectedExceptionCode 111
+ * @expectedExceptionMessage Could not create non-existing user id
+ */
+ public function testAddUserFailedToGenerateUserID() {
+ $this->config
+ ->expects($this->any())
+ ->method('getAppValue')
+ ->willReturnCallback(function($appid, $key, $default) {
+ if($key === 'newUser.generateUserID') {
+ return true;
+ }
+ return null;
+ });
+ $this->userManager
+ ->expects($this->any())
+ ->method('userExists')
+ ->with($this->anything())
+ ->will($this->returnValue(true));
+ $this->userManager
+ ->expects($this->never())
+ ->method('createUser');
+ $loggedInUser = $this->getMockBuilder(IUser::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $loggedInUser
+ ->expects($this->once())
+ ->method('getUID')
+ ->will($this->returnValue('adminUser'));
+ $this->userSession
+ ->expects($this->once())
+ ->method('getUser')
+ ->will($this->returnValue($loggedInUser));
+ $this->groupManager
+ ->expects($this->once())
+ ->method('isAdmin')
+ ->with('adminUser')
+ ->willReturn(true);
+
+ $this->api->addUser('', 'PasswordOfTheNewUser')->getData();
+ }
+
+ /**
+ * @expectedException \OCP\AppFramework\OCS\OCSException
+ * @expectedExceptionCode 110
+ * @expectedExceptionMessage Required email address was not provided
+ */
+ public function testAddUserEmailRequired() {
+ $this->config
+ ->expects($this->any())
+ ->method('getAppValue')
+ ->willReturnCallback(function($appid, $key, $default) {
+ if($key === 'newUser.requireEmail') {
+ return true;
+ }
+ return null;
+ });
+ $this->userManager
+ ->expects($this->once())
+ ->method('userExists')
+ ->with('NewUser')
+ ->will($this->returnValue(false));
+ $this->userManager
+ ->expects($this->never())
+ ->method('createUser');
+ $loggedInUser = $this->getMockBuilder(IUser::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $loggedInUser
+ ->expects($this->once())
+ ->method('getUID')
+ ->will($this->returnValue('adminUser'));
+ $this->userSession
+ ->expects($this->once())
+ ->method('getUser')
+ ->will($this->returnValue($loggedInUser));
+ $this->groupManager
+ ->expects($this->once())
+ ->method('isAdmin')
+ ->with('adminUser')
+ ->willReturn(true);
+
+ $this->assertTrue(key_exists(
+ 'UserID',
+ $this->api->addUser('NewUser', 'PasswordOfTheNewUser')->getData()
+ ));
}
public function testAddUserExistingGroup() {
@@ -471,7 +616,10 @@ class UsersControllerTest extends TestCase {
['Added userid NewUser to group ExistingGroup', ['app' => 'ocs_api']]
);
- $this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData());
+ $this->assertTrue(key_exists(
+ 'UserID',
+ $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData()
+ ));
}
/**
@@ -689,7 +837,10 @@ class UsersControllerTest extends TestCase {
)
->willReturn(true);
- $this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup1', 'ExistingGroup2'])->getData());
+ $this->assertTrue(key_exists(
+ 'UserID',
+ $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup1', 'ExistingGroup2'])->getData()
+ ));
}
/**