summaryrefslogtreecommitdiffstats
path: root/apps/encryption/tests/lib/KeyManagerTest.php
blob: 260e69a73bfcc399d53ae6e0febed847cb6412a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?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;

	public function setUp() {
		parent::setUp();
		$keyStorageMock = $this->getMock('OCP\Encryption\IKeyStorage');
		$cryptMock = $this->getMockBuilder('OCA\Encryption\Crypt')
			->disableOriginalConstructor()
			->getMock();
		$configMock = $this->getMock('OCP\IConfig');
		$userMock = $this->getMock('OCP\IUser');
		$userMock->expects($this->once())
			->method('getUID')
			->will($this->returnValue('admin'));
		$this->userId = 'admin';
		$this->instance = new KeyManager($keyStorageMock, $cryptMock, $configMock, $userMock);

		$this->dummyKeys = ['public' => 'randomweakpublickeyhere',
			'private' => 'randomweakprivatekeyhere'];
	}

	/**
	 * @expectedException OC\Encryption\Exceptions\PrivateKeyMissingException
	 */
	public function testGetPrivateKey() {
		$this->assertFalse($this->instance->getPrivateKey($this->userId));
	}

	/**
	 * @expectedException OC\Encryption\Exceptions\PublicKeyMissingException
	 */
	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'));
	}

	public function testSetPublicKey() {

		$this->assertTrue($this->instance->setPublicKey($this->userId, $this->dummyKeys['public']));
	}

	public function testSetPrivateKey() {
		$this->assertTrue($this->instance->setPrivateKey($this->userId, $this->dummyKeys['private']));
	}

	public function testUserHasKeys() {
		$this->assertFalse($this->instance->userHasKeys($this->userId));
	}


}