diff options
author | Clark Tomlinson <fallen013@gmail.com> | 2015-03-30 17:01:50 -0400 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-07 13:30:28 +0200 |
commit | e6dc6944c2cd92617818a2fd029ecdb1de5ab663 (patch) | |
tree | 3f370c438fd6d175c8ec988ad6596f697c2e1b84 /apps/encryption/tests | |
parent | 1b42b492dce562596b8b57a11546728f697c4f38 (diff) | |
download | nextcloud-server-e6dc6944c2cd92617818a2fd029ecdb1de5ab663.tar.gz nextcloud-server-e6dc6944c2cd92617818a2fd029ecdb1de5ab663.zip |
moving methods to their final places
and updating test some.
Diffstat (limited to 'apps/encryption/tests')
-rw-r--r-- | apps/encryption/tests/lib/KeyManagerTest.php | 88 |
1 files changed, 80 insertions, 8 deletions
diff --git a/apps/encryption/tests/lib/KeyManagerTest.php b/apps/encryption/tests/lib/KeyManagerTest.php index ed6048d7642..510ab179888 100644 --- a/apps/encryption/tests/lib/KeyManagerTest.php +++ b/apps/encryption/tests/lib/KeyManagerTest.php @@ -10,26 +10,64 @@ namespace OCA\Encryption\Tests; +use OC\Files\View; use OCA\Encryption\KeyManager; use Test\TestCase; class KeyManagerTest extends TestCase { /** + * @var bool + */ + private static $trashbinState; + /** * @var KeyManager */ private $instance; /** - * @var + * @var string */ - private $userId; + private static $testUser = 'test-keyManager-user.dot'; /** * @var */ private $dummyKeys; + /** + * @var string + */ + private $userId; + /** + * @var string + */ + private $userPassword; + /** + * @var \OC\Files\View + */ + private $view; + /** + * @var string + */ + private $dataDir; /** * */ + public static function setUpBeforeClass() { + parent::setUpBeforeClass(); + + // Remember files_trashbin state + self::$trashbinState = \OC_App::isEnabled('files_trashbin'); + + // We dont want tests with app files_trashbin enabled + \OC_App::disable('files_trashbin'); + + $userManager = \OC::$server->getUserManager(); + $userManager->createUser(self::$testUser, + self::$testUser); + + // Create test user + parent::loginAsUser(self::$testUser); + } + public function setUp() { parent::setUp(); $keyStorageMock = $this->getMock('OCP\Encryption\Keys\IStorage'); @@ -47,18 +85,52 @@ class KeyManagerTest extends TestCase { ->will($this->returnValue('admin')); $sessionMock = $this->getMock('OCP\ISession'); $logMock = $this->getMock('OCP\ILogger'); - $this->userId = 'admin'; + $recoveryMock = $this->getMockBuilder('OCA\Encryption\Recovery') + ->disableOriginalConstructor() + ->getMock(); + $this->instance = new KeyManager($keyStorageMock, $cryptMock, $configMock, $userMock, $sessionMock, - $logMock); + $logMock, + $recoveryMock); + + self::loginAsUser(self::$testUser); + $this->userId = self::$testUser; + $this->userPassword = self::$testUser; + $this->view = new View('/'); + + $this->dummyKeys = [ + 'privateKey' => 'superinsecureprivatekey', + 'publicKey' => 'superinsecurepublickey' + ]; - $this->dummyKeys = ['public' => 'randomweakpublickeyhere', - 'private' => 'randomweakprivatekeyhere']; + + $userManager = \OC::$server->getUserManager(); + + $userHome = $userManager->get($this->userId)->getHome(); + + $this->dataDir = str_replace('/' . $this->userId, '', $userHome); + } + + protected function tearDown() { + parent::tearDown(); + $this->view->deleteAll('/' . self::$testUser . '/files_encryption/keys'); + } + + public static function tearDownAfterClass() { + parent::tearDownAfterClass(); + // Cleanup Test user + \OC::$server->getUserManager()->get(self::$testUser)->delete(); + // Reset app files_trashbin + if (self::$trashbinState) { + \OC_App::enable('files_trashbin'); + } } + /** * @expectedException \OC\Encryption\Exceptions\PrivateKeyMissingException */ @@ -93,7 +165,7 @@ class KeyManagerTest extends TestCase { public function testSetPublicKey() { $this->assertTrue($this->instance->setPublicKey($this->userId, - $this->dummyKeys['public'])); + $this->dummyKeys['publicKey'])); } /** @@ -101,7 +173,7 @@ class KeyManagerTest extends TestCase { */ public function testSetPrivateKey() { $this->assertTrue($this->instance->setPrivateKey($this->userId, - $this->dummyKeys['private'])); + $this->dummyKeys['privateKey'])); } /** |