diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-12-19 15:35:31 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-12-19 15:35:31 +0100 |
commit | 3eb3e437c8a0520192ec7c1018d4d1c55e780dc0 (patch) | |
tree | f436ecbdddcd9924277f0ecca24a140be289bc78 /lib/private | |
parent | e536313451d071aa9693411b3964ef26ce75c904 (diff) | |
download | nextcloud-server-3eb3e437c8a0520192ec7c1018d4d1c55e780dc0.tar.gz nextcloud-server-3eb3e437c8a0520192ec7c1018d4d1c55e780dc0.zip |
Add proper tests
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/IntegrityCheck/Checker.php | 30 | ||||
-rw-r--r-- | lib/private/IntegrityCheck/Helpers/FileAccessHelper.php | 8 |
2 files changed, 18 insertions, 20 deletions
diff --git a/lib/private/IntegrityCheck/Checker.php b/lib/private/IntegrityCheck/Checker.php index a3d9d906d8d..4588c006da6 100644 --- a/lib/private/IntegrityCheck/Checker.php +++ b/lib/private/IntegrityCheck/Checker.php @@ -272,19 +272,18 @@ class Checker { X509 $certificate, RSA $privateKey) { $appInfoDir = $path . '/appinfo'; - $this->fileAccessHelper->assertDirectoryExists($path); - $this->fileAccessHelper->assertDirectoryExists($appInfoDir); - - $iterator = $this->getFolderIterator($path); - $hashes = $this->generateHashes($iterator, $path); - $signature = $this->createSignatureData($hashes, $certificate, $privateKey); try { - $this->fileAccessHelper->file_put_contents( - $appInfoDir . '/signature.json', + $this->fileAccessHelper->assertDirectoryExists($appInfoDir); + + $iterator = $this->getFolderIterator($path); + $hashes = $this->generateHashes($iterator, $path); + $signature = $this->createSignatureData($hashes, $certificate, $privateKey); + $this->fileAccessHelper->file_put_contents( + $appInfoDir . '/signature.json', json_encode($signature, JSON_PRETTY_PRINT) ); } catch (\Exception $e){ - if (!$this->fileAccessHelper->is_writeable($appInfoDir)){ + if (!$this->fileAccessHelper->is_writable($appInfoDir)) { throw new \Exception($appInfoDir . ' is not writable'); } throw $e; @@ -303,19 +302,18 @@ class Checker { RSA $rsa, $path) { $coreDir = $path . '/core'; - $this->fileAccessHelper->assertDirectoryExists($path); - $this->fileAccessHelper->assertDirectoryExists($coreDir); - - $iterator = $this->getFolderIterator($path, $path); - $hashes = $this->generateHashes($iterator, $path); - $signatureData = $this->createSignatureData($hashes, $certificate, $rsa); try { + + $this->fileAccessHelper->assertDirectoryExists($coreDir); + $iterator = $this->getFolderIterator($path, $path); + $hashes = $this->generateHashes($iterator, $path); + $signatureData = $this->createSignatureData($hashes, $certificate, $rsa); $this->fileAccessHelper->file_put_contents( $coreDir . '/signature.json', json_encode($signatureData, JSON_PRETTY_PRINT) ); } catch (\Exception $e){ - if (!$this->fileAccessHelper->is_writeable($coreDir)){ + if (!$this->fileAccessHelper->is_writable($coreDir)) { throw new \Exception($coreDir . ' is not writable'); } throw $e; diff --git a/lib/private/IntegrityCheck/Helpers/FileAccessHelper.php b/lib/private/IntegrityCheck/Helpers/FileAccessHelper.php index c3193457890..a7e378c165e 100644 --- a/lib/private/IntegrityCheck/Helpers/FileAccessHelper.php +++ b/lib/private/IntegrityCheck/Helpers/FileAccessHelper.php @@ -58,7 +58,7 @@ class FileAccessHelper { * @throws \Exception */ public function file_put_contents($filename, $data) { - $bytesWritten = file_put_contents($filename, $data); + $bytesWritten = @file_put_contents($filename, $data); if ($bytesWritten === false || $bytesWritten !== strlen($data)){ throw new \Exception('Failed to write into ' . $filename); } @@ -69,15 +69,15 @@ class FileAccessHelper { * @param string $path * @return bool */ - public function is_writeable($path){ - return is_writeable($path); + public function is_writable($path) { + return is_writable($path); } /** * @param string $path * @throws \Exception */ - public function assertDirectoryExists($path){ + public function assertDirectoryExists($path) { if (!is_dir($path)) { throw new \Exception('Directory ' . $path . ' does not exist.'); } |