diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-10-31 19:39:35 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-10-31 19:39:35 +0100 |
commit | 0eeef26a8e2515b802015fe09bef7909aa183491 (patch) | |
tree | 697508eff89756ad0581e8e83e112775ad709b09 /lib/private/Installer.php | |
parent | 1a676bacb4176016c468f3fcb2388b93a73c8c6b (diff) | |
download | nextcloud-server-0eeef26a8e2515b802015fe09bef7909aa183491.tar.gz nextcloud-server-0eeef26a8e2515b802015fe09bef7909aa183491.zip |
Add tests for installer method
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'lib/private/Installer.php')
-rw-r--r-- | lib/private/Installer.php | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/lib/private/Installer.php b/lib/private/Installer.php index 120992d3e63..2366b762654 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -209,10 +209,7 @@ class Installer { sprintf( 'App with id %s has a certificate not issued by a trusted Code Signing Authority', $appId - ), - [ - 'app' => 'core', - ] + ) ); } @@ -223,10 +220,7 @@ class Installer { sprintf( 'App with id %s has a cert with no CN', $appId - ), - [ - 'app' => 'core', - ] + ) ); } if($certInfo['subject']['CN'] !== $appId) { @@ -235,10 +229,7 @@ class Installer { 'App with id %s has a cert issued to %s', $appId, $certInfo['subject']['CN'] - ), - [ - 'app' => 'core', - ] + ) ); } @@ -259,10 +250,22 @@ class Installer { if($archive) { $archive->extract($extractDir); + $allFiles = scandir($extractDir); + $folders = array_diff($allFiles, ['.', '..']); + $folders = array_values($folders); + + if(count($folders) > 1) { + throw new \Exception( + sprintf( + 'Extracted app %s has more than 1 folder', + $appId + ) + ); + } // Check if appinfo/info.xml has the same app ID as well $loadEntities = libxml_disable_entity_loader(false); - $xml = simplexml_load_file($extractDir . '/' . $appId . '/appinfo/info.xml'); + $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); libxml_disable_entity_loader($loadEntities); if((string)$xml->id !== $appId) { throw new \Exception( @@ -270,10 +273,7 @@ class Installer { 'App for id %s has a wrong app ID in info.xml: %s', $appId, (string)$xml->id - ), - [ - 'app' => 'core', - ] + ) ); } @@ -282,21 +282,19 @@ class Installer { OC_Helper::rmdirr($baseDir); // Move to app folder if(@mkdir($baseDir)) { - $extractDir .= '/' . $appId; + $extractDir .= '/' . $folders[0]; OC_Helper::copyr($extractDir, $baseDir); } OC_Helper::copyr($extractDir, $baseDir); OC_Helper::rmdirr($extractDir); + return; } else { throw new \Exception( sprintf( 'Could not extract app with ID %s to %s', $appId, $extractDir - ), - [ - 'app' => 'core', - ] + ) ); } } else { @@ -305,14 +303,18 @@ class Installer { sprintf( 'App with id %s has invalid signature', $appId - ), - [ - 'app' => 'core', - ] + ) ); } } } + + throw new \Exception( + sprintf( + 'Could not download app %s', + $appId + ) + ); } /** |