Skip to content
Snippets Groups Projects
Unverified Commit 0eeef26a authored by Lukas Reschke's avatar Lukas Reschke
Browse files

Add tests for installer method

parent 1a676bac
No related branches found
No related tags found
No related merge requests found
...@@ -209,10 +209,7 @@ class Installer { ...@@ -209,10 +209,7 @@ class Installer {
sprintf( sprintf(
'App with id %s has a certificate not issued by a trusted Code Signing Authority', 'App with id %s has a certificate not issued by a trusted Code Signing Authority',
$appId $appId
), )
[
'app' => 'core',
]
); );
} }
...@@ -223,10 +220,7 @@ class Installer { ...@@ -223,10 +220,7 @@ class Installer {
sprintf( sprintf(
'App with id %s has a cert with no CN', 'App with id %s has a cert with no CN',
$appId $appId
), )
[
'app' => 'core',
]
); );
} }
if($certInfo['subject']['CN'] !== $appId) { if($certInfo['subject']['CN'] !== $appId) {
...@@ -235,10 +229,7 @@ class Installer { ...@@ -235,10 +229,7 @@ class Installer {
'App with id %s has a cert issued to %s', 'App with id %s has a cert issued to %s',
$appId, $appId,
$certInfo['subject']['CN'] $certInfo['subject']['CN']
), )
[
'app' => 'core',
]
); );
} }
...@@ -259,10 +250,22 @@ class Installer { ...@@ -259,10 +250,22 @@ class Installer {
if($archive) { if($archive) {
$archive->extract($extractDir); $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 // Check if appinfo/info.xml has the same app ID as well
$loadEntities = libxml_disable_entity_loader(false); $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); libxml_disable_entity_loader($loadEntities);
if((string)$xml->id !== $appId) { if((string)$xml->id !== $appId) {
throw new \Exception( throw new \Exception(
...@@ -270,10 +273,7 @@ class Installer { ...@@ -270,10 +273,7 @@ class Installer {
'App for id %s has a wrong app ID in info.xml: %s', 'App for id %s has a wrong app ID in info.xml: %s',
$appId, $appId,
(string)$xml->id (string)$xml->id
), )
[
'app' => 'core',
]
); );
} }
...@@ -282,21 +282,19 @@ class Installer { ...@@ -282,21 +282,19 @@ class Installer {
OC_Helper::rmdirr($baseDir); OC_Helper::rmdirr($baseDir);
// Move to app folder // Move to app folder
if(@mkdir($baseDir)) { if(@mkdir($baseDir)) {
$extractDir .= '/' . $appId; $extractDir .= '/' . $folders[0];
OC_Helper::copyr($extractDir, $baseDir); OC_Helper::copyr($extractDir, $baseDir);
} }
OC_Helper::copyr($extractDir, $baseDir); OC_Helper::copyr($extractDir, $baseDir);
OC_Helper::rmdirr($extractDir); OC_Helper::rmdirr($extractDir);
return;
} else { } else {
throw new \Exception( throw new \Exception(
sprintf( sprintf(
'Could not extract app with ID %s to %s', 'Could not extract app with ID %s to %s',
$appId, $appId,
$extractDir $extractDir
), )
[
'app' => 'core',
]
); );
} }
} else { } else {
...@@ -305,14 +303,18 @@ class Installer { ...@@ -305,14 +303,18 @@ class Installer {
sprintf( sprintf(
'App with id %s has invalid signature', 'App with id %s has invalid signature',
$appId $appId
), )
[
'app' => 'core',
]
); );
} }
} }
} }
throw new \Exception(
sprintf(
'Could not download app %s',
$appId
)
);
} }
/** /**
......
File added
File added
...@@ -88,4 +88,12 @@ class VersionParserTest extends TestCase { ...@@ -88,4 +88,12 @@ class VersionParserTest extends TestCase {
public function testGetVersionException() { public function testGetVersionException() {
$this->versionParser->getVersion('BogusVersion'); $this->versionParser->getVersion('BogusVersion');
} }
/**
* @expectedException \Exception
* @expectedExceptionMessage Version cannot be parsed: >=8.2 <=9.1a
*/
public function testGetVersionExceptionWithMultiple() {
$this->versionParser->getVersion('>=8.2 <=9.1a');
}
} }
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment