2015-02-24 21:05:19 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Clark Tomlinson <fallen013@gmail.com>
|
|
|
|
* @since 3/5/15, 10:53 AM
|
|
|
|
* @link http:/www.clarkt.com
|
|
|
|
* @copyright Clark Tomlinson © 2015
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Encryption\Tests;
|
|
|
|
|
|
|
|
|
|
|
|
use OCA\Encryption\KeyManager;
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class KeyManagerTest extends TestCase {
|
|
|
|
/**
|
|
|
|
* @var KeyManager
|
|
|
|
*/
|
|
|
|
private $instance;
|
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
|
|
|
private $userId;
|
|
|
|
/**
|
|
|
|
* @var
|
|
|
|
*/
|
|
|
|
private $dummyKeys;
|
|
|
|
|
2015-03-25 00:29:10 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2015-02-24 21:05:19 +03:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2015-03-25 00:29:10 +03:00
|
|
|
$keyStorageMock = $this->getMock('OCP\Encryption\Keys\IStorage');
|
|
|
|
$keyStorageMock->method('getUserKey')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
$keyStorageMock->method('setUserKey')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
$cryptMock = $this->getMockBuilder('OCA\Encryption\Crypto\Crypt')
|
2015-02-24 21:05:19 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$configMock = $this->getMock('OCP\IConfig');
|
2015-03-25 00:29:10 +03:00
|
|
|
$userMock = $this->getMock('OCP\IUserSession');
|
|
|
|
$userMock
|
2015-02-24 21:05:19 +03:00
|
|
|
->method('getUID')
|
|
|
|
->will($this->returnValue('admin'));
|
2015-03-27 03:35:36 +03:00
|
|
|
$sessionMock = $this->getMock('OCP\ISession');
|
2015-03-25 00:29:10 +03:00
|
|
|
$logMock = $this->getMock('OCP\ILogger');
|
2015-02-24 21:05:19 +03:00
|
|
|
$this->userId = 'admin';
|
2015-03-27 03:35:36 +03:00
|
|
|
$this->instance = new KeyManager($keyStorageMock,
|
|
|
|
$cryptMock,
|
|
|
|
$configMock,
|
|
|
|
$userMock,
|
|
|
|
$sessionMock,
|
|
|
|
$logMock);
|
2015-02-24 21:05:19 +03:00
|
|
|
|
|
|
|
$this->dummyKeys = ['public' => 'randomweakpublickeyhere',
|
|
|
|
'private' => 'randomweakprivatekeyhere'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-25 00:29:10 +03:00
|
|
|
* @expectedException \OC\Encryption\Exceptions\PrivateKeyMissingException
|
2015-02-24 21:05:19 +03:00
|
|
|
*/
|
|
|
|
public function testGetPrivateKey() {
|
|
|
|
$this->assertFalse($this->instance->getPrivateKey($this->userId));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-25 00:29:10 +03:00
|
|
|
* @expectedException \OC\Encryption\Exceptions\PublicKeyMissingException
|
2015-02-24 21:05:19 +03:00
|
|
|
*/
|
|
|
|
public function testGetPublicKey() {
|
|
|
|
$this->assertFalse($this->instance->getPublicKey($this->userId));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function testRecoveryKeyExists() {
|
|
|
|
$this->assertFalse($this->instance->recoveryKeyExists());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function testCheckRecoveryKeyPassword() {
|
|
|
|
$this->assertFalse($this->instance->checkRecoveryPassword('pass'));
|
|
|
|
}
|
|
|
|
|
2015-03-25 00:29:10 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2015-02-24 21:05:19 +03:00
|
|
|
public function testSetPublicKey() {
|
|
|
|
|
2015-03-27 03:35:36 +03:00
|
|
|
$this->assertTrue($this->instance->setPublicKey($this->userId,
|
|
|
|
$this->dummyKeys['public']));
|
2015-02-24 21:05:19 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 00:29:10 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2015-02-24 21:05:19 +03:00
|
|
|
public function testSetPrivateKey() {
|
2015-03-27 03:35:36 +03:00
|
|
|
$this->assertTrue($this->instance->setPrivateKey($this->userId,
|
|
|
|
$this->dummyKeys['private']));
|
2015-02-24 21:05:19 +03:00
|
|
|
}
|
|
|
|
|
2015-03-25 00:29:10 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2015-02-24 21:05:19 +03:00
|
|
|
public function testUserHasKeys() {
|
|
|
|
$this->assertFalse($this->instance->userHasKeys($this->userId));
|
|
|
|
}
|
|
|
|
|
2015-03-25 00:29:10 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function testInit() {
|
|
|
|
$this->assertFalse($this->instance->init($this->userId, 'pass'));
|
|
|
|
}
|
|
|
|
|
2015-02-24 21:05:19 +03:00
|
|
|
|
|
|
|
}
|