Beispiel #1
0
 /**
  * @medium
  */
 function testDeclineServer2ServerShare()
 {
     self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
     // save file with content
     $cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);
     // test that data was successfully written
     $this->assertInternalType('int', $cryptedFile);
     // get the file info from previous created file
     $fileInfo = $this->view->getFileInfo('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
     // share the file
     $token = \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, '', \OCP\Constants::PERMISSION_ALL);
     $this->assertTrue(is_string($token));
     $publicShareKeyId = \OC::$server->getConfig()->getAppValue('files_encryption', 'publicShareKeyId');
     // check if share key for public exists
     $this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . $publicShareKeyId . '.shareKey'));
     // manipulate share
     $query = \OC::$server->getDatabaseConnection()->prepare('UPDATE `*PREFIX*share` SET `share_type` = ?, `share_with` = ? WHERE `token`=?');
     $this->assertTrue($query->execute(array(\OCP\Share::SHARE_TYPE_REMOTE, 'foo@bar', $token)));
     // check if share key not exists
     $this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . $publicShareKeyId . '.shareKey'));
     $query = \OC::$server->getDatabaseConnection()->prepare('SELECT * FROM `*PREFIX*share` WHERE `token`=?');
     $query->execute(array($token));
     $share = $query->fetch();
     $_POST['token'] = $token;
     $s2s = new \OCA\Files_Sharing\API\Server2Server();
     $s2s->declineShare(array('id' => $share['id']));
     $this->assertFalse($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . $publicShareKeyId . '.shareKey'));
 }
Beispiel #2
0
 /**
  * @medium
  */
 function testDeclineServer2ServerShare()
 {
     $config = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock();
     $certificateManager = $this->getMock('\\OCP\\ICertificateManager');
     $httpHelperMock = $this->getMockBuilder('\\OC\\HTTPHelper')->setConstructorArgs(array($config, $certificateManager))->getMock();
     $httpHelperMock->expects($this->once())->method('post')->with($this->anything())->will($this->returnValue(true));
     self::loginHelper(self::TEST_ENCRYPTION_SHARE_USER1);
     // save file with content
     $cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort);
     // test that data was successfully written
     $this->assertTrue(is_int($cryptedFile));
     // get the file info from previous created file
     $fileInfo = $this->view->getFileInfo('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
     // share the file
     $token = \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_LINK, '', \OCP\Constants::PERMISSION_ALL);
     $this->assertTrue(is_string($token));
     $publicShareKeyId = \OC::$server->getConfig()->getAppValue('files_encryption', 'publicShareKeyId');
     // check if share key for public exists
     $this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . $publicShareKeyId . '.shareKey'));
     // manipulate share
     $query = \OC::$server->getDatabaseConnection()->prepare('UPDATE `*PREFIX*share` SET `share_type` = ?, `share_with` = ? WHERE `token`=?');
     $this->assertTrue($query->execute(array(\OCP\Share::SHARE_TYPE_REMOTE, 'foo@bar', $token)));
     // check if share key not exists
     $this->assertTrue($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . $publicShareKeyId . '.shareKey'));
     $query = \OC::$server->getDatabaseConnection()->prepare('SELECT * FROM `*PREFIX*share` WHERE `token`=?');
     $query->execute(array($token));
     $share = $query->fetch();
     $this->registerHttpHelper($httpHelperMock);
     $_POST['token'] = $token;
     $s2s = new \OCA\Files_Sharing\API\Server2Server();
     $s2s->declineShare(array('id' => $share['id']));
     $this->restoreHttpHelper();
     $this->assertFalse($this->view->file_exists('/' . self::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/keys/' . $this->filename . '/' . $publicShareKeyId . '.shareKey'));
 }