-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12416 from owncloud/app-info-xml-parser-2
App info xml parser 2
- Loading branch information
Showing
9 changed files
with
223 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* @author Thomas Müller | ||
* @copyright 2014 Thomas Müller deepdiver@owncloud.com | ||
* | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. | ||
* See the COPYING-README file. | ||
*/ | ||
|
||
namespace OC\App; | ||
|
||
use OCP\IURLGenerator; | ||
|
||
class InfoParser { | ||
/** | ||
* @var \OC\HTTPHelper | ||
*/ | ||
private $httpHelper; | ||
|
||
/** | ||
* @var IURLGenerator | ||
*/ | ||
private $urlGenerator; | ||
|
||
/** | ||
* @param \OC\HTTPHelper $httpHelper | ||
* @param IURLGenerator $urlGenerator | ||
*/ | ||
public function __construct(\OC\HTTPHelper $httpHelper, IURLGenerator $urlGenerator) { | ||
$this->httpHelper = $httpHelper; | ||
$this->urlGenerator = $urlGenerator; | ||
} | ||
|
||
/** | ||
* @param string $file the xml file to be loaded | ||
* @return null|array where null is an indicator for an error | ||
*/ | ||
public function parse($file) { | ||
if (!file_exists($file)) { | ||
return null; | ||
} | ||
|
||
$loadEntities = libxml_disable_entity_loader(false); | ||
$xml = @simplexml_load_file($file); | ||
libxml_disable_entity_loader($loadEntities); | ||
if ($xml == false) { | ||
return null; | ||
} | ||
$array = json_decode(json_encode((array)$xml), TRUE); | ||
if (is_null($array)) { | ||
return null; | ||
} | ||
if (!array_key_exists('info', $array)) { | ||
$array['info'] = array(); | ||
} | ||
if (!array_key_exists('remote', $array)) { | ||
$array['remote'] = array(); | ||
} | ||
if (!array_key_exists('public', $array)) { | ||
$array['public'] = array(); | ||
} | ||
|
||
if (array_key_exists('documentation', $array)) { | ||
foreach ($array['documentation'] as $key => $url) { | ||
// If it is not an absolute URL we assume it is a key | ||
// i.e. admin-ldap will get converted to go.php?to=admin-ldap | ||
if (!$this->httpHelper->isHTTPURL($url)) { | ||
$url = $this->urlGenerator->linkToDocs($url); | ||
} | ||
|
||
$array['documentation'][$key] = $url; | ||
} | ||
} | ||
if (array_key_exists('types', $array)) { | ||
foreach ($array['types'] as $type => $v) { | ||
unset($array['types'][$type]); | ||
$array['types'][] = $type; | ||
} | ||
} | ||
|
||
return $array; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"info": [], | ||
"remote": [], | ||
"public": [], | ||
"id": "files_encryption", | ||
"name": "Server-side Encryption", | ||
"description": "\n\tThis application encrypts all files accessed by ownCloud at rest, wherever they are stored. As an example, with this application enabled, external cloud based Amazon S3 storage will be encrypted, protecting this data on storage outside of the control of the Admin. When this application is enabled for the first time, all files are encrypted as users log in and are prompted for their password. The recommended recovery key option enables recovery of files in case the key is lost. \n\tNote that this app encrypts all files that are touched by ownCloud, so external storage providers and applications such as SharePoint will see new files encrypted when they are accessed. Encryption is based on AES 128 or 256 bit keys. More information is available in the Encryption documentation \n\t", | ||
"licence": "AGPL", | ||
"author": "Sam Tuke, Bjoern Schiessle, Florin Peter", | ||
"requiremin": "4", | ||
"shipped": "true", | ||
"documentation": { | ||
"user": "https://docs.example.com/server/go.php?to=user-encryption", | ||
"admin": "https://docs.example.com/server/go.php?to=admin-encryption" | ||
}, | ||
"rememberlogin": "false", | ||
"types": ["filesystem"], | ||
"ocsid": "166047" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0"?> | ||
<info | ||
<id>files_encryption</id> | ||
<name>Server-side Encryption</name> | ||
<description> | ||
This application encrypts all files accessed by ownCloud at rest, wherever they are stored. As an example, with this application enabled, external cloud based Amazon S3 storage will be encrypted, protecting this data on storage outside of the control of the Admin. When this application is enabled for the first time, all files are encrypted as users log in and are prompted for their password. The recommended recovery key option enables recovery of files in case the key is lost. | ||
Note that this app encrypts all files that are touched by ownCloud, so external storage providers and applications such as SharePoint will see new files encrypted when they are accessed. Encryption is based on AES 128 or 256 bit keys. More information is available in the Encryption documentation | ||
</description> | ||
<licence>AGPL</licence> | ||
<author>Sam Tuke, Bjoern Schiessle, Florin Peter</author> | ||
<requiremin>4</requiremin> | ||
<shipped>true</shipped> | ||
<documentation> | ||
<user>user-encryption</user> | ||
<admin>admin-encryption</admin> | ||
</documentation> | ||
<rememberlogin>false</rememberlogin> | ||
<types> | ||
<filesystem/> | ||
</types> | ||
<ocsid>166047</ocsid> | ||
</info> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0"?> | ||
<info> | ||
<id>files_encryption</id> | ||
<name>Server-side Encryption</name> | ||
<description> | ||
This application encrypts all files accessed by ownCloud at rest, wherever they are stored. As an example, with this application enabled, external cloud based Amazon S3 storage will be encrypted, protecting this data on storage outside of the control of the Admin. When this application is enabled for the first time, all files are encrypted as users log in and are prompted for their password. The recommended recovery key option enables recovery of files in case the key is lost. | ||
Note that this app encrypts all files that are touched by ownCloud, so external storage providers and applications such as SharePoint will see new files encrypted when they are accessed. Encryption is based on AES 128 or 256 bit keys. More information is available in the Encryption documentation | ||
</description> | ||
<licence>AGPL</licence> | ||
<author>Sam Tuke, Bjoern Schiessle, Florin Peter</author> | ||
<requiremin>4</requiremin> | ||
<shipped>true</shipped> | ||
<documentation> | ||
<user>user-encryption</user> | ||
<admin>admin-encryption</admin> | ||
</documentation> | ||
<rememberlogin>false</rememberlogin> | ||
<types> | ||
<filesystem/> | ||
</types> | ||
<ocsid>166047</ocsid> | ||
</info> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/** | ||
* @author Thomas Müller | ||
* @copyright 2014 Thomas Müller deepdiver@owncloud.com | ||
* later. | ||
* See the COPYING-README file. | ||
*/ | ||
|
||
namespace Test\App; | ||
|
||
use OC; | ||
|
||
class InfoParser extends \PHPUnit_Framework_TestCase { | ||
|
||
/** | ||
* @var \OC\App\InfoParser | ||
*/ | ||
private $parser; | ||
|
||
public function setUp() { | ||
$config = $this->getMockBuilder('\OC\AllConfig') | ||
->disableOriginalConstructor()->getMock(); | ||
$httpHelper = $this->getMockBuilder('\OC\HTTPHelper') | ||
->setConstructorArgs(array($config)) | ||
->setMethods(array('getHeaders')) | ||
->getMock(); | ||
$urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
//linkToDocs | ||
$urlGenerator->expects($this->any()) | ||
->method('linkToDocs') | ||
->will($this->returnCallback(function ($url) { | ||
return "https://docs.example.com/server/go.php?to=$url"; | ||
})); | ||
|
||
$this->parser = new \OC\App\InfoParser($httpHelper, $urlGenerator); | ||
} | ||
|
||
public function testParsingValidXml() { | ||
$expectedData = json_decode(file_get_contents(OC::$SERVERROOT.'/tests/data/app/expected-info.json'), true); | ||
$data = $this->parser->parse(OC::$SERVERROOT.'/tests/data/app/valid-info.xml'); | ||
|
||
$this->assertEquals($expectedData, $data); | ||
} | ||
|
||
public function testParsingInvalidXml() { | ||
$data = $this->parser->parse(OC::$SERVERROOT.'/tests/data/app/invalid-info.xml'); | ||
$this->assertNull($data); | ||
} | ||
} |