KeyManagerTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Clark Tomlinson <fallen013@gmail.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\Encryption\Tests;
  27. use OCA\Encryption\KeyManager;
  28. use OCA\Encryption\Session;
  29. use OCP\Encryption\Keys\IStorage;
  30. use OCP\IConfig;
  31. use OCP\ILogger;
  32. use OCP\IUserSession;
  33. use Test\TestCase;
  34. class KeyManagerTest extends TestCase {
  35. /**
  36. * @var KeyManager
  37. */
  38. private $instance;
  39. /**
  40. * @var string
  41. */
  42. private $userId;
  43. /** @var string */
  44. private $systemKeyId;
  45. /** @var \OCP\Encryption\Keys\IStorage|\PHPUnit_Framework_MockObject_MockObject */
  46. private $keyStorageMock;
  47. /** @var \OCA\Encryption\Crypto\Crypt|\PHPUnit_Framework_MockObject_MockObject */
  48. private $cryptMock;
  49. /** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject */
  50. private $userMock;
  51. /** @var \OCA\Encryption\Session|\PHPUnit_Framework_MockObject_MockObject */
  52. private $sessionMock;
  53. /** @var \OCP\ILogger|\PHPUnit_Framework_MockObject_MockObject */
  54. private $logMock;
  55. /** @var \OCA\Encryption\Util|\PHPUnit_Framework_MockObject_MockObject */
  56. private $utilMock;
  57. /** @var \OCP\IConfig|\PHPUnit_Framework_MockObject_MockObject */
  58. private $configMock;
  59. public function setUp() {
  60. parent::setUp();
  61. $this->userId = 'user1';
  62. $this->systemKeyId = 'systemKeyId';
  63. $this->keyStorageMock = $this->createMock(IStorage::class);
  64. $this->cryptMock = $this->getMockBuilder('OCA\Encryption\Crypto\Crypt')
  65. ->disableOriginalConstructor()
  66. ->getMock();
  67. $this->configMock = $this->createMock(IConfig::class);
  68. $this->configMock->expects($this->any())
  69. ->method('getAppValue')
  70. ->willReturn($this->systemKeyId);
  71. $this->userMock = $this->createMock(IUserSession::class);
  72. $this->sessionMock = $this->getMockBuilder('OCA\Encryption\Session')
  73. ->disableOriginalConstructor()
  74. ->getMock();
  75. $this->logMock = $this->createMock(ILogger::class);
  76. $this->utilMock = $this->getMockBuilder('OCA\Encryption\Util')
  77. ->disableOriginalConstructor()
  78. ->getMock();
  79. $this->instance = new KeyManager(
  80. $this->keyStorageMock,
  81. $this->cryptMock,
  82. $this->configMock,
  83. $this->userMock,
  84. $this->sessionMock,
  85. $this->logMock,
  86. $this->utilMock);
  87. }
  88. public function testDeleteShareKey() {
  89. $this->keyStorageMock->expects($this->any())
  90. ->method('deleteFileKey')
  91. ->with($this->equalTo('/path'), $this->equalTo('keyId.shareKey'))
  92. ->willReturn(true);
  93. $this->assertTrue(
  94. $this->instance->deleteShareKey('/path', 'keyId')
  95. );
  96. }
  97. public function testGetPrivateKey() {
  98. $this->keyStorageMock->expects($this->any())
  99. ->method('getUserKey')
  100. ->with($this->equalTo($this->userId), $this->equalTo('privateKey'))
  101. ->willReturn('privateKey');
  102. $this->assertSame('privateKey',
  103. $this->instance->getPrivateKey($this->userId)
  104. );
  105. }
  106. public function testGetPublicKey() {
  107. $this->keyStorageMock->expects($this->any())
  108. ->method('getUserKey')
  109. ->with($this->equalTo($this->userId), $this->equalTo('publicKey'))
  110. ->willReturn('publicKey');
  111. $this->assertSame('publicKey',
  112. $this->instance->getPublicKey($this->userId)
  113. );
  114. }
  115. public function testRecoveryKeyExists() {
  116. $this->keyStorageMock->expects($this->any())
  117. ->method('getSystemUserKey')
  118. ->with($this->equalTo($this->systemKeyId . '.publicKey'))
  119. ->willReturn('recoveryKey');
  120. $this->assertTrue($this->instance->recoveryKeyExists());
  121. }
  122. public function testCheckRecoveryKeyPassword() {
  123. $this->keyStorageMock->expects($this->any())
  124. ->method('getSystemUserKey')
  125. ->with($this->equalTo($this->systemKeyId . '.privateKey'))
  126. ->willReturn('recoveryKey');
  127. $this->cryptMock->expects($this->any())
  128. ->method('decryptPrivateKey')
  129. ->with($this->equalTo('recoveryKey'), $this->equalTo('pass'))
  130. ->willReturn('decryptedRecoveryKey');
  131. $this->assertTrue($this->instance->checkRecoveryPassword('pass'));
  132. }
  133. public function testSetPublicKey() {
  134. $this->keyStorageMock->expects($this->any())
  135. ->method('setUserKey')
  136. ->with(
  137. $this->equalTo($this->userId),
  138. $this->equalTo('publicKey'),
  139. $this->equalTo('key'))
  140. ->willReturn(true);
  141. $this->assertTrue(
  142. $this->instance->setPublicKey($this->userId, 'key')
  143. );
  144. }
  145. public function testSetPrivateKey() {
  146. $this->keyStorageMock->expects($this->any())
  147. ->method('setUserKey')
  148. ->with(
  149. $this->equalTo($this->userId),
  150. $this->equalTo('privateKey'),
  151. $this->equalTo('key'))
  152. ->willReturn(true);
  153. $this->assertTrue(
  154. $this->instance->setPrivateKey($this->userId, 'key')
  155. );
  156. }
  157. /**
  158. * @dataProvider dataTestUserHasKeys
  159. */
  160. public function testUserHasKeys($key, $expected) {
  161. $this->keyStorageMock->expects($this->exactly(2))
  162. ->method('getUserKey')
  163. ->with($this->equalTo($this->userId), $this->anything())
  164. ->willReturn($key);
  165. $this->assertSame($expected,
  166. $this->instance->userHasKeys($this->userId)
  167. );
  168. }
  169. public function dataTestUserHasKeys() {
  170. return [
  171. ['key', true],
  172. ['', false]
  173. ];
  174. }
  175. /**
  176. * @expectedException \OCA\Encryption\Exceptions\PrivateKeyMissingException
  177. */
  178. public function testUserHasKeysMissingPrivateKey() {
  179. $this->keyStorageMock->expects($this->exactly(2))
  180. ->method('getUserKey')
  181. ->willReturnCallback(function ($uid, $keyID, $encryptionModuleId) {
  182. if ($keyID=== 'privateKey') {
  183. return '';
  184. }
  185. return 'key';
  186. });
  187. $this->instance->userHasKeys($this->userId);
  188. }
  189. /**
  190. * @expectedException \OCA\Encryption\Exceptions\PublicKeyMissingException
  191. */
  192. public function testUserHasKeysMissingPublicKey() {
  193. $this->keyStorageMock->expects($this->exactly(2))
  194. ->method('getUserKey')
  195. ->willReturnCallback(function ($uid, $keyID, $encryptionModuleId){
  196. if ($keyID === 'publicKey') {
  197. return '';
  198. }
  199. return 'key';
  200. });
  201. $this->instance->userHasKeys($this->userId);
  202. }
  203. /**
  204. * @dataProvider dataTestInit
  205. *
  206. * @param bool $useMasterKey
  207. */
  208. public function testInit($useMasterKey) {
  209. /** @var \OCA\Encryption\KeyManager|\PHPUnit_Framework_MockObject_MockObject $instance */
  210. $instance = $this->getMockBuilder('OCA\Encryption\KeyManager')
  211. ->setConstructorArgs(
  212. [
  213. $this->keyStorageMock,
  214. $this->cryptMock,
  215. $this->configMock,
  216. $this->userMock,
  217. $this->sessionMock,
  218. $this->logMock,
  219. $this->utilMock
  220. ]
  221. )->setMethods(['getMasterKeyId', 'getMasterKeyPassword', 'getSystemPrivateKey', 'getPrivateKey'])
  222. ->getMock();
  223. $this->utilMock->expects($this->once())->method('isMasterKeyEnabled')
  224. ->willReturn($useMasterKey);
  225. $this->sessionMock->expects($this->at(0))->method('setStatus')
  226. ->with(Session::INIT_EXECUTED);
  227. $instance->expects($this->any())->method('getMasterKeyId')->willReturn('masterKeyId');
  228. $instance->expects($this->any())->method('getMasterKeyPassword')->willReturn('masterKeyPassword');
  229. $instance->expects($this->any())->method('getSystemPrivateKey')->with('masterKeyId')->willReturn('privateMasterKey');
  230. $instance->expects($this->any())->method('getPrivateKey')->with($this->userId)->willReturn('privateUserKey');
  231. if($useMasterKey) {
  232. $this->cryptMock->expects($this->once())->method('decryptPrivateKey')
  233. ->with('privateMasterKey', 'masterKeyPassword', 'masterKeyId')
  234. ->willReturn('key');
  235. } else {
  236. $this->cryptMock->expects($this->once())->method('decryptPrivateKey')
  237. ->with('privateUserKey', 'pass', $this->userId)
  238. ->willReturn('key');
  239. }
  240. $this->sessionMock->expects($this->once())->method('setPrivateKey')
  241. ->with('key');
  242. $this->assertTrue($instance->init($this->userId, 'pass'));
  243. }
  244. public function dataTestInit() {
  245. return [
  246. [true],
  247. [false]
  248. ];
  249. }
  250. public function testSetRecoveryKey() {
  251. $this->keyStorageMock->expects($this->exactly(2))
  252. ->method('setSystemUserKey')
  253. ->willReturn(true);
  254. $this->cryptMock->expects($this->any())
  255. ->method('encryptPrivateKey')
  256. ->with($this->equalTo('privateKey'), $this->equalTo('pass'))
  257. ->willReturn('decryptedPrivateKey');
  258. $this->assertTrue(
  259. $this->instance->setRecoveryKey('pass',
  260. array('publicKey' => 'publicKey', 'privateKey' => 'privateKey'))
  261. );
  262. }
  263. public function testSetSystemPrivateKey() {
  264. $this->keyStorageMock->expects($this->exactly(1))
  265. ->method('setSystemUserKey')
  266. ->with($this->equalTo('keyId.privateKey'), $this->equalTo('key'))
  267. ->willReturn(true);
  268. $this->assertTrue(
  269. $this->instance->setSystemPrivateKey('keyId', 'key')
  270. );
  271. }
  272. public function testGetSystemPrivateKey() {
  273. $this->keyStorageMock->expects($this->exactly(1))
  274. ->method('getSystemUserKey')
  275. ->with($this->equalTo('keyId.privateKey'))
  276. ->willReturn('systemPrivateKey');
  277. $this->assertSame('systemPrivateKey',
  278. $this->instance->getSystemPrivateKey('keyId')
  279. );
  280. }
  281. public function testGetEncryptedFileKey() {
  282. $this->keyStorageMock->expects($this->once())
  283. ->method('getFileKey')
  284. ->with('/', 'fileKey')
  285. ->willReturn(true);
  286. $this->assertTrue($this->instance->getEncryptedFileKey('/'));
  287. }
  288. /**
  289. * @dataProvider dataTestGetFileKey
  290. *
  291. * @param $uid
  292. * @param $isMasterKeyEnabled
  293. * @param $privateKey
  294. * @param $expected
  295. */
  296. public function testGetFileKey($uid, $isMasterKeyEnabled, $privateKey, $expected) {
  297. $path = '/foo.txt';
  298. if ($isMasterKeyEnabled) {
  299. $expectedUid = 'masterKeyId';
  300. } else {
  301. $expectedUid = $uid;
  302. }
  303. $this->invokePrivate($this->instance, 'masterKeyId', ['masterKeyId']);
  304. $this->keyStorageMock->expects($this->at(0))
  305. ->method('getFileKey')
  306. ->with($path, 'fileKey', 'OC_DEFAULT_MODULE')
  307. ->willReturn(true);
  308. $this->keyStorageMock->expects($this->at(1))
  309. ->method('getFileKey')
  310. ->with($path, $expectedUid . '.shareKey', 'OC_DEFAULT_MODULE')
  311. ->willReturn(true);
  312. if (is_null($uid)) {
  313. $this->keyStorageMock->expects($this->once())
  314. ->method('getSystemUserKey')
  315. ->willReturn(true);
  316. $this->cryptMock->expects($this->once())
  317. ->method('decryptPrivateKey')
  318. ->willReturn($privateKey);
  319. } else {
  320. $this->keyStorageMock->expects($this->never())
  321. ->method('getSystemUserKey');
  322. $this->utilMock->expects($this->once())->method('isMasterKeyEnabled')
  323. ->willReturn($isMasterKeyEnabled);
  324. $this->sessionMock->expects($this->once())->method('getPrivateKey')->willReturn($privateKey);
  325. }
  326. if($privateKey) {
  327. $this->cryptMock->expects($this->once())
  328. ->method('multiKeyDecrypt')
  329. ->willReturn(true);
  330. } else {
  331. $this->cryptMock->expects($this->never())
  332. ->method('multiKeyDecrypt');
  333. }
  334. $this->assertSame($expected,
  335. $this->instance->getFileKey($path, $uid)
  336. );
  337. }
  338. public function dataTestGetFileKey() {
  339. return [
  340. ['user1', false, 'privateKey', true],
  341. ['user1', false, false, ''],
  342. ['user1', true, 'privateKey', true],
  343. ['user1', true, false, ''],
  344. ['', false, 'privateKey', true],
  345. ['', false, false, ''],
  346. ['', true, 'privateKey', true],
  347. ['', true, false, '']
  348. ];
  349. }
  350. public function testDeletePrivateKey() {
  351. $this->keyStorageMock->expects($this->once())
  352. ->method('deleteUserKey')
  353. ->with('user1', 'privateKey')
  354. ->willReturn(true);
  355. $this->assertTrue(self::invokePrivate($this->instance,
  356. 'deletePrivateKey',
  357. [$this->userId]));
  358. }
  359. public function testDeleteAllFileKeys() {
  360. $this->keyStorageMock->expects($this->once())
  361. ->method('deleteAllFileKeys')
  362. ->willReturn(true);
  363. $this->assertTrue($this->instance->deleteAllFileKeys('/'));
  364. }
  365. /**
  366. * test add public share key and or recovery key to the list of public keys
  367. *
  368. * @dataProvider dataTestAddSystemKeys
  369. *
  370. * @param array $accessList
  371. * @param array $publicKeys
  372. * @param string $uid
  373. * @param array $expectedKeys
  374. */
  375. public function testAddSystemKeys($accessList, $publicKeys, $uid, $expectedKeys) {
  376. $publicShareKeyId = 'publicShareKey';
  377. $recoveryKeyId = 'recoveryKey';
  378. $this->keyStorageMock->expects($this->any())
  379. ->method('getSystemUserKey')
  380. ->willReturnCallback(function($keyId, $encryptionModuleId) {
  381. return $keyId;
  382. });
  383. $this->utilMock->expects($this->any())
  384. ->method('isRecoveryEnabledForUser')
  385. ->willReturnCallback(function($uid) {
  386. if ($uid === 'user1') {
  387. return true;
  388. }
  389. return false;
  390. });
  391. // set key IDs
  392. self::invokePrivate($this->instance, 'publicShareKeyId', [$publicShareKeyId]);
  393. self::invokePrivate($this->instance, 'recoveryKeyId', [$recoveryKeyId]);
  394. $result = $this->instance->addSystemKeys($accessList, $publicKeys, $uid);
  395. foreach ($expectedKeys as $expected) {
  396. $this->assertArrayHasKey($expected, $result);
  397. }
  398. $this->assertSameSize($expectedKeys, $result);
  399. }
  400. /**
  401. * data provider for testAddSystemKeys()
  402. *
  403. * @return array
  404. */
  405. public function dataTestAddSystemKeys() {
  406. return array(
  407. array(['public' => true],[], 'user1', ['publicShareKey', 'recoveryKey']),
  408. array(['public' => false], [], 'user1', ['recoveryKey']),
  409. array(['public' => true],[], 'user2', ['publicShareKey']),
  410. array(['public' => false], [], 'user2', []),
  411. );
  412. }
  413. public function testGetMasterKeyId() {
  414. $this->assertSame('systemKeyId', $this->instance->getMasterKeyId());
  415. }
  416. public function testGetPublicMasterKey() {
  417. $this->keyStorageMock->expects($this->once())->method('getSystemUserKey')
  418. ->with('systemKeyId.publicKey', \OCA\Encryption\Crypto\Encryption::ID)
  419. ->willReturn(true);
  420. $this->assertTrue(
  421. $this->instance->getPublicMasterKey()
  422. );
  423. }
  424. public function testGetMasterKeyPassword() {
  425. $this->configMock->expects($this->once())->method('getSystemValue')->with('secret')
  426. ->willReturn('password');
  427. $this->assertSame('password',
  428. $this->invokePrivate($this->instance, 'getMasterKeyPassword', [])
  429. );
  430. }
  431. /**
  432. * @expectedException \Exception
  433. */
  434. public function testGetMasterKeyPasswordException() {
  435. $this->configMock->expects($this->once())->method('getSystemValue')->with('secret')
  436. ->willReturn('');
  437. $this->invokePrivate($this->instance, 'getMasterKeyPassword', []);
  438. }
  439. /**
  440. * @dataProvider dataTestValidateMasterKey
  441. *
  442. * @param $masterKey
  443. */
  444. public function testValidateMasterKey($masterKey) {
  445. /** @var \OCA\Encryption\KeyManager | \PHPUnit_Framework_MockObject_MockObject $instance */
  446. $instance = $this->getMockBuilder('OCA\Encryption\KeyManager')
  447. ->setConstructorArgs(
  448. [
  449. $this->keyStorageMock,
  450. $this->cryptMock,
  451. $this->configMock,
  452. $this->userMock,
  453. $this->sessionMock,
  454. $this->logMock,
  455. $this->utilMock
  456. ]
  457. )->setMethods(['getPublicMasterKey', 'setSystemPrivateKey', 'getMasterKeyPassword'])
  458. ->getMock();
  459. $instance->expects($this->once())->method('getPublicMasterKey')
  460. ->willReturn($masterKey);
  461. $instance->expects($this->any())->method('getMasterKeyPassword')->willReturn('masterKeyPassword');
  462. $this->cryptMock->expects($this->any())->method('generateHeader')->willReturn('header');
  463. if(empty($masterKey)) {
  464. $this->cryptMock->expects($this->once())->method('createKeyPair')
  465. ->willReturn(['publicKey' => 'public', 'privateKey' => 'private']);
  466. $this->keyStorageMock->expects($this->once())->method('setSystemUserKey')
  467. ->with('systemKeyId.publicKey', 'public', \OCA\Encryption\Crypto\Encryption::ID);
  468. $this->cryptMock->expects($this->once())->method('encryptPrivateKey')
  469. ->with('private', 'masterKeyPassword', 'systemKeyId')
  470. ->willReturn('EncryptedKey');
  471. $instance->expects($this->once())->method('setSystemPrivateKey')
  472. ->with('systemKeyId', 'headerEncryptedKey');
  473. } else {
  474. $this->cryptMock->expects($this->never())->method('createKeyPair');
  475. $this->keyStorageMock->expects($this->never())->method('setSystemUserKey');
  476. $this->cryptMock->expects($this->never())->method('encryptPrivateKey');
  477. $instance->expects($this->never())->method('setSystemPrivateKey');
  478. }
  479. $instance->validateMasterKey();
  480. }
  481. public function dataTestValidateMasterKey() {
  482. return [
  483. ['masterKey'],
  484. ['']
  485. ];
  486. }
  487. public function testGetVersionWithoutFileInfo() {
  488. $view = $this->getMockBuilder('\\OC\\Files\\View')
  489. ->disableOriginalConstructor()->getMock();
  490. $view->expects($this->once())
  491. ->method('getFileInfo')
  492. ->with('/admin/files/myfile.txt')
  493. ->willReturn(false);
  494. /** @var \OC\Files\View $view */
  495. $this->assertSame(0, $this->instance->getVersion('/admin/files/myfile.txt', $view));
  496. }
  497. public function testGetVersionWithFileInfo() {
  498. $view = $this->getMockBuilder('\\OC\\Files\\View')
  499. ->disableOriginalConstructor()->getMock();
  500. $fileInfo = $this->getMockBuilder('\\OC\\Files\\FileInfo')
  501. ->disableOriginalConstructor()->getMock();
  502. $fileInfo->expects($this->once())
  503. ->method('getEncryptedVersion')
  504. ->willReturn(1337);
  505. $view->expects($this->once())
  506. ->method('getFileInfo')
  507. ->with('/admin/files/myfile.txt')
  508. ->willReturn($fileInfo);
  509. /** @var \OC\Files\View $view */
  510. $this->assertSame(1337, $this->instance->getVersion('/admin/files/myfile.txt', $view));
  511. }
  512. public function testSetVersionWithFileInfo() {
  513. $view = $this->getMockBuilder('\\OC\\Files\\View')
  514. ->disableOriginalConstructor()->getMock();
  515. $cache = $this->getMockBuilder('\\OCP\\Files\\Cache\\ICache')
  516. ->disableOriginalConstructor()->getMock();
  517. $cache->expects($this->once())
  518. ->method('update')
  519. ->with(123, ['encrypted' => 5, 'encryptedVersion' => 5]);
  520. $storage = $this->getMockBuilder('\\OCP\\Files\\Storage')
  521. ->disableOriginalConstructor()->getMock();
  522. $storage->expects($this->once())
  523. ->method('getCache')
  524. ->willReturn($cache);
  525. $fileInfo = $this->getMockBuilder('\\OC\\Files\\FileInfo')
  526. ->disableOriginalConstructor()->getMock();
  527. $fileInfo->expects($this->once())
  528. ->method('getStorage')
  529. ->willReturn($storage);
  530. $fileInfo->expects($this->once())
  531. ->method('getId')
  532. ->willReturn(123);
  533. $view->expects($this->once())
  534. ->method('getFileInfo')
  535. ->with('/admin/files/myfile.txt')
  536. ->willReturn($fileInfo);
  537. /** @var \OC\Files\View $view */
  538. $this->instance->setVersion('/admin/files/myfile.txt', 5, $view);
  539. }
  540. public function testSetVersionWithoutFileInfo() {
  541. $view = $this->getMockBuilder('\\OC\\Files\\View')
  542. ->disableOriginalConstructor()->getMock();
  543. $view->expects($this->once())
  544. ->method('getFileInfo')
  545. ->with('/admin/files/myfile.txt')
  546. ->willReturn(false);
  547. /** @var \OC\Files\View $view */
  548. $this->instance->setVersion('/admin/files/myfile.txt', 5, $view);
  549. }
  550. public function testBackupUserKeys() {
  551. $this->keyStorageMock->expects($this->once())->method('backupUserKeys')
  552. ->with('OC_DEFAULT_MODULE', 'test', 'user1');
  553. $this->instance->backupUserKeys('test', 'user1');
  554. }
  555. }