Merge branch 'tests'

This commit is contained in:
brantje 2017-01-04 12:14:52 +01:00
commit 74b7fe4f07
No known key found for this signature in database
GPG key ID: 5FF1D117F918687F
7 changed files with 290 additions and 36 deletions

View file

@ -40,15 +40,17 @@ class InternalController extends ApiController {
*/
public function remind($credential_id) {
$credential = $this->credentialService->getCredentialById($credential_id, $this->userId);
$credential->setExpireTime(time() + (24 * 60 * 60));
$this->credentialService->upd($credential);
if($credential) {
$credential->setExpireTime(time() + (24 * 60 * 60));
$this->credentialService->upd($credential);
$manager = \OC::$server->getNotificationManager();
$notification = $manager->createNotification();
$notification->setApp('passman')
->setObject('credential', $credential_id)
->setUser($this->userId);
$manager->markProcessed($notification);
$manager = \OC::$server->getNotificationManager();
$notification = $manager->createNotification();
$notification->setApp('passman')
->setObject('credential', $credential_id)
->setUser($this->userId);
$manager->markProcessed($notification);
}
}
/**
@ -57,15 +59,17 @@ class InternalController extends ApiController {
public function read($credential_id) {
$credential = $this->credentialService->getCredentialById($credential_id, $this->userId);
$credential->setExpireTime(0);
$this->credentialService->upd($credential);
if($credential) {
$credential->setExpireTime(0);
$this->credentialService->upd($credential);
$manager = \OC::$server->getNotificationManager();
$notification = $manager->createNotification();
$notification->setApp('passman')
->setObject('credential', $credential_id)
->setUser($this->userId);
$manager->markProcessed($notification);
$manager = \OC::$server->getNotificationManager();
$notification = $manager->createNotification();
$notification->setApp('passman')
->setObject('credential', $credential_id)
->setUser($this->userId);
$manager->markProcessed($notification);
}
}
/**

View file

@ -50,19 +50,20 @@ class VaultController extends ApiController {
$vaults = $this->vaultService->getByUser($this->userId);
$protected_credential_fields = array('getDescription', 'getEmail', 'getUsername', 'getPassword');
foreach ($vaults as $vault) {
$credential = $this->credentialService->getRandomCredentialByVaultId($vault->getId(), $this->userId);
$secret_field = $protected_credential_fields[array_rand($protected_credential_fields)];
array_push($result, array(
'vault_id' => $vault->getId(),
'guid' => $vault->getGuid(),
'name' => $vault->getName(),
'created' => $vault->getCreated(),
'public_sharing_key' => $vault->getPublicSharingKey(),
'last_access' => $vault->getlastAccess(),
'challenge_password' => $credential->{$secret_field}()
));
if ($vaults) {
foreach ($vaults as $vault) {
$credential = $this->credentialService->getRandomCredentialByVaultId($vault->getId(), $this->userId);
$secret_field = $protected_credential_fields[array_rand($protected_credential_fields)];
array_push($result, array(
'vault_id' => $vault->getId(),
'guid' => $vault->getGuid(),
'name' => $vault->getName(),
'created' => $vault->getCreated(),
'public_sharing_key' => $vault->getPublicSharingKey(),
'last_access' => $vault->getlastAccess(),
'challenge_password' => $credential->{$secret_field}()
));
}
}
return new JSONResponse($result);
@ -87,7 +88,7 @@ class VaultController extends ApiController {
try {
$vault = $this->vaultService->getByGuid($vault_guid, $this->userId);
} catch (\Exception $e) {
return new NotFoundJSONResponse();
return new NotFoundJSONResponse();
}
$result = array();
if ($vault) {
@ -119,10 +120,10 @@ class VaultController extends ApiController {
*/
public function update($vault_guid, $name, $vault_settings) {
$vault = $this->vaultService->getByGuid($vault_guid, $this->userId);
if ($name) {
if ($name && $vault) {
$vault->setName($name);
}
if ($vault_settings) {
if ($vault_settings && $vault) {
$vault->setVaultSettings($vault_settings);
}
$this->vaultService->updateVault($vault);
@ -137,10 +138,13 @@ class VaultController extends ApiController {
try {
$vault = $this->vaultService->getByGuid($vault_guid, $this->userId);
} catch (\Exception $e) {
// No need to catch the execption
}
if ($vault) {
$this->vaultService->updateSharingKeys($vault->getId(), $private_sharing_key, $public_sharing_key);
}
$this->vaultService->updateSharingKeys($vault->getId(), $private_sharing_key, $public_sharing_key);
return;
}

View file

@ -0,0 +1,99 @@
<?php
/**
* Nextcloud - passman
*
* @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com)
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Passman\Controller;
use OCA\Comments\Activity\Setting;
use OCA\Passman\Service\ActivityService;
use OCA\Passman\Service\CredentialService;
use OCA\Passman\Service\FileService;
use OCA\Passman\Service\NotificationService;
use OCA\Passman\Service\SettingsService;
use OCA\Passman\Service\ShareService;
use OCA\Passman\Service\VaultService;
use OCP\IGroupManager;
use OCP\IUserManager;
use PHPUnit_Framework_TestCase;
use OCP\AppFramework\Http\JSONResponse;
/**
* Class InternalControllerTest
*
* @package OCA\Passman\Controller
* @coversDefaultClass \OCA\Passman\Controller\FileController
*/
class FileControllerTest extends PHPUnit_Framework_TestCase {
private $controller;
private $userId = 'example';
private $credentialService;
private $vaultService;
private $groupManager;
private $userManager;
private $activityService;
private $shareService;
private $notificationService;
private $fileService;
private $settings;
public function setUp() {
$request = $this->getMockBuilder('OCP\IRequest')->getMock();
$this->fileService = $this->createMock(FileService::class);
$this->controller = new FileController(
'passman', $request, $this->userId, $this->fileService
);
}
/**
* @covers ::uploadFile
*/
public function testUploadFile() {
$result = $this->controller->uploadFile('000', '0.png', 'image/png', 3);
$this->assertTrue($result instanceof JSONResponse);
}
/**
* @covers ::getFile
*/
public function testGetFile() {
$result = $this->controller->getFile(null);
$this->assertTrue($result instanceof JSONResponse);
}
/**
* @covers ::deleteFile
*/
public function testDeleteFile() {
$result = $this->controller->deleteFile(null);
$this->assertTrue($result instanceof JSONResponse);
}
/**
* @covers ::updateFile
*/
public function testUpdateFile() {
$this->controller->updateFile('6AD30804-BFFC-4EFC-97F8-20A126FA1709', '0' , '0.jpg');
$this->assertTrue(true);
}
}

View file

@ -50,6 +50,21 @@ class InternalControllerTest extends PHPUnit_Framework_TestCase {
);
}
/**
* @covers ::remind
*/
public function testRemind() {
$this->controller->remind(null);
$this->assertTrue(true);
}
/**
* @covers ::read
*/
public function testRead() {
$this->controller->read(null);
$this->assertTrue(true);
}
/**
* @covers ::getAppVersion
*/
@ -65,4 +80,21 @@ class InternalControllerTest extends PHPUnit_Framework_TestCase {
$result = $this->controller->generatePerson();
$this->assertTrue($result instanceof JSONResponse);
}
/**
* @covers ::getSettings
*/
public function testGetSettings() {
$result = $this->controller->getSettings();
$this->assertTrue($result instanceof JSONResponse);
}
/**
* @covers ::saveSettings
*/
public function testSaveSettings() {
$result = $this->controller->saveSettings('test', 'test');
$this->assertTrue(true);
}
}

View file

@ -58,13 +58,20 @@ class SettingsControllerTest extends PHPUnit_Framework_TestCase {
$result = $this->controller->getForm();
$this->assertTrue($result instanceof TemplateResponse);
}
/**
* @covers ::getSection
*/
public function testGetSection() {
$result = $this->controller->getSection();
$this->assertTrue(is_string($result));
}
/**
* @covers ::getPriority
*/
public function testGetPriority() {
$result = $this->controller->getPriority();
$this->assertTrue($result === 0);
$this->assertTrue(is_numeric($result));
}
/**

View file

@ -0,0 +1,108 @@
<?php
/**
* Nextcloud - passman
*
* @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com)
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Passman\Controller;
use OCA\Passman\Service\CredentialService;
use OCA\Passman\Service\VaultService;
use PHPUnit_Framework_TestCase;
use OCP\AppFramework\Http\JSONResponse;
/**
* Class InternalControllerTest
*
* @package OCA\Passman\Controller
* @coversDefaultClass \OCA\Passman\Controller\VaultController
*/
class VaultControllerTest extends PHPUnit_Framework_TestCase {
private $controller;
private $userId = 'example';
private $credentialService;
private $vaultService;
public function setUp() {
$request = $this->getMockBuilder('OCP\IRequest')->getMock();
$this->vaultService = $this->createMock(VaultService::class);
$this->credentialService = $this->createMock(CredentialService::class);
$this->controller = new VaultController(
'passman', $request, $this->userId, $this->vaultService, $this->credentialService
);
}
/**
* @covers ::listVaults
*/
public function testListVaults() {
$result = $this->controller->listVaults();
$this->assertTrue($result instanceof JSONResponse);
}
/**
* @covers ::create
*/
public function testCreate() {
$result = $this->controller->create('My test vault');
$this->assertTrue($result instanceof JSONResponse);
}
/**
* @covers ::get
*/
public function testGet() {
$result = $this->controller->get('');
$this->assertTrue($result instanceof JSONResponse);
}
/**
* Just test the method
* @see http://stackoverflow.com/questions/27511593/how-to-phpunit-test-a-method-with-no-return-value
*
* @covers ::update
*/
public function testUpdate() {
$this->controller->update('6AD30804-BFFC-4EFC-97F8-20A126FA1709', 'testname' ,null);
$this->assertTrue(true);
}
/**
* Just test the method
* @see http://stackoverflow.com/questions/27511593/how-to-phpunit-test-a-method-with-no-return-value
*
* @covers ::updateSharingKeys
*/
public function testUpdateSharingKeys() {
$this->controller->updateSharingKeys('6AD30804-BFFC-4EFC-97F8-20A126FA1709', null ,null);
$this->assertTrue(true);
}
/**
* @covers ::delete
*/
public function testDelete() {
$result = $this->controller->delete('');
$this->assertTrue($result instanceof JSONResponse);
}
}

View file

@ -33,7 +33,7 @@ use OCA\Passman\Service\SettingsService;
* Class PageControllerTest
*
* @package OCA\Passman\Controller
* @coversDefaultClass \OCA\Passman\Service\SettingsServiceTest
* @coversDefaultClass \OCA\Passman\Service\SettingsService
*/
class SettingsServiceTest extends PHPUnit_Framework_TestCase {