public function testManagerIsEnabled() { $config = $this->getMock('\\OCP\\IConfig'); $config->expects($this->any())->method('getSystemValue')->willReturn(true); $config->expects($this->any())->method('getAppValue')->willReturn('yes'); $m = new Manager($config); $this->assertTrue($m->isEnabled()); }
/** * inform encryption module that a file was renamed, * e.g. to update the encryption keys * * @param array $params */ public function postRename($params) { $source = $params['oldpath']; $target = $params['newpath']; if ($this->encryptionManager->isEnabled() && dirname($source) !== dirname($target)) { list($owner, $ownerPath) = $this->getOwnerPath($target); $absPath = '/' . $owner . '/files/' . $ownerPath; $this->update($absPath); } }
/** * see http://php.net/manual/en/function.fopen.php * * @param string $path * @param string $mode * @return resource */ public function fopen($path, $mode) { $encryptionEnabled = $this->encryptionManager->isEnabled(); $shouldEncrypt = false; $encryptionModule = null; $header = $this->getHeader($path); $fullPath = $this->getFullPath($path); $encryptionModuleId = $this->util->getEncryptionModuleId($header); $size = $unencryptedSize = 0; $targetExists = $this->file_exists($path); $targetIsEncrypted = false; if ($targetExists) { // in case the file exists we require the explicit module as // specified in the file header - otherwise we need to fail hard to // prevent data loss on client side if (!empty($encryptionModuleId)) { $targetIsEncrypted = true; $encryptionModule = $this->encryptionManager->getEncryptionModule($encryptionModuleId); } $size = $this->storage->filesize($path); $unencryptedSize = $this->filesize($path); } try { if ($mode === 'w' || $mode === 'w+' || $mode === 'wb' || $mode === 'wb+') { if (!empty($encryptionModuleId)) { $encryptionModule = $this->encryptionManager->getEncryptionModule($encryptionModuleId); $shouldEncrypt = $encryptionModule->shouldEncrypt($fullPath); } elseif ($encryptionEnabled) { $encryptionModule = $this->encryptionManager->getDefaultEncryptionModule(); $shouldEncrypt = $encryptionModule->shouldEncrypt($fullPath); } } else { // only get encryption module if we found one in the header if (!empty($encryptionModuleId)) { $encryptionModule = $this->encryptionManager->getEncryptionModule($encryptionModuleId); $shouldEncrypt = true; } } } catch (ModuleDoesNotExistsException $e) { $this->logger->warning('Encryption module "' . $encryptionModuleId . '" not found, file will be stored unencrypted (' . $e->getMessage() . ')'); } // encryption disabled on write of new file and write to existing unencrypted file -> don't encrypt if (!$encryptionEnabled || !$this->mount->getOption('encrypt', true)) { if (!$targetExists || !$targetIsEncrypted) { $shouldEncrypt = false; } } if ($shouldEncrypt === true && !$this->util->isExcluded($fullPath) && $encryptionModule !== null) { $source = $this->storage->fopen($path, $mode); $handle = \OC\Files\Stream\Encryption::wrap($source, $path, $fullPath, $header, $this->uid, $encryptionModule, $this->storage, $this, $this->util, $this->fileHelper, $mode, $size, $unencryptedSize); return $handle; } else { return $this->storage->fopen($path, $mode); } }
public function testManagerIsEnabled() { $this->config->expects($this->any())->method('getSystemValue')->willReturn(true); $this->config->expects($this->any())->method('getAppValue')->willReturn('yes'); $this->assertTrue($this->manager->isEnabled()); }