public function testAddUserAsSubAdminExistingGroups() { $_POST['userid'] = 'NewUser'; $_POST['password'] = '******'; $_POST['groups'] = ['ExistingGroup1', 'ExistingGroup2']; $this->userManager->expects($this->once())->method('userExists')->with('NewUser')->willReturn(false); $loggedInUser = $this->getMock('\\OCP\\IUser'); $loggedInUser->expects($this->once())->method('getUID')->will($this->returnValue('subAdminUser')); $this->userSession->expects($this->once())->method('getUser')->will($this->returnValue($loggedInUser)); $this->groupManager->expects($this->once())->method('isAdmin')->with('subAdminUser')->willReturn(false); $this->groupManager->expects($this->exactly(2))->method('groupExists')->withConsecutive(['ExistingGroup1'], ['ExistingGroup2'])->willReturn(true); $user = $this->getMock('\\OCP\\IUser'); $this->userManager->expects($this->once())->method('createUser')->with('NewUser', 'PasswordOfTheNewUser')->willReturn($user); $existingGroup1 = $this->getMock('\\OCP\\IGroup'); $existingGroup2 = $this->getMock('\\OCP\\IGroup'); $existingGroup1->expects($this->once())->method('addUser')->with($user); $existingGroup2->expects($this->once())->method('addUser')->with($user); $this->groupManager->expects($this->exactly(4))->method('get')->withConsecutive(['ExistingGroup1'], ['ExistingGroup2'], ['ExistingGroup1'], ['ExistingGroup2'])->will($this->returnValueMap([['ExistingGroup1', $existingGroup1], ['ExistingGroup2', $existingGroup2]])); $this->logger->expects($this->exactly(3))->method('info')->withConsecutive(['Successful addUser call with userid: NewUser', ['app' => 'ocs_api']], ['Added userid NewUser to group ExistingGroup1', ['app' => 'ocs_api']], ['Added userid NewUser to group ExistingGroup2', ['app' => 'ocs_api']]); $subAdminManager = $this->getMockBuilder('\\OC\\Subadmin')->disableOriginalConstructor()->getMock(); $this->groupManager->expects($this->once())->method('getSubAdmin')->willReturn($subAdminManager); $subAdminManager->expects($this->once())->method('isSubAdmin')->with($loggedInUser)->willReturn(true); $subAdminManager->expects($this->exactly(2))->method('isSubAdminOfGroup')->withConsecutive([$loggedInUser, $existingGroup1], [$loggedInUser, $existingGroup2])->wilLReturn(true); $expected = new \OC_OCS_Result(null, 100); $this->assertEquals($expected, $this->api->addUser()); }
public function testAddUserUnsuccessful() { $_POST['userid'] = 'NewUser'; $_POST['password'] = '******'; $this->userManager->expects($this->once())->method('userExists')->with('NewUser')->will($this->returnValue(false)); $this->userManager->expects($this->once())->method('createUser')->with('NewUser', 'PasswordOfTheNewUser')->will($this->throwException(new \Exception('User backend not found.'))); $this->logger->expects($this->once())->method('error')->with('Failed addUser attempt with exception: User backend not found.', ['app' => 'ocs_api']); $expected = new \OC_OCS_Result(null, 101, 'Bad request'); $this->assertEquals($expected, $this->api->addUser()); }
public function testGetApplicationDownloadParseError() { $this->config->expects($this->at(0))->method('getSystemValue')->with('appstoreenabled', true)->will($this->returnValue(true)); $this->config->expects($this->at(1))->method('getSystemValue')->with('appstoreurl', 'https://api.owncloud.com/v1')->will($this->returnValue('https://api.owncloud.com/v1')); $response = $this->getMock('\\OCP\\Http\\Client\\IResponse'); $response->expects($this->once())->method('getBody')->will($this->returnValue('MyInvalidXml')); $client = $this->getMock('\\OCP\\Http\\Client\\IClient'); $client->expects($this->once())->method('get')->with('https://api.owncloud.com/v1/content/download/MyId/1', ['timeout' => 5, 'query' => ['version' => '8x1x0x7']])->will($this->returnValue($response)); $this->clientService->expects($this->once())->method('newClient')->will($this->returnValue($client)); $this->logger->expects($this->once())->method('error')->with('Could not get application download URL, content was no valid XML', ['app' => 'core']); $this->assertNull($this->ocsClient->getApplicationDownload('MyId', [8, 1, 0, 7])); }
public function testGetCipherWithInvalidCipher() { $this->config->expects($this->once())->method('getSystemValue')->with($this->equalTo('cipher'), $this->equalTo('AES-256-CTR'))->willReturn('Not-Existing-Cipher'); $this->logger->expects($this->once())->method('warning')->with('Unsupported cipher (Not-Existing-Cipher) defined in config.php supported. Falling back to AES-256-CTR'); $this->assertSame('AES-256-CTR', $this->crypt->getCipher()); }