Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
fix(agent): update checks for XML format on enrollment
Browse files Browse the repository at this point in the history
Signed-off-by: Domingo Oropeza <doropeza@teclib.com>
  • Loading branch information
DIOHz0r committed Jun 5, 2018
1 parent 30f2c37 commit 6e95d99
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
3 changes: 1 addition & 2 deletions inc/agent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1129,8 +1129,7 @@ protected function enrollByInvitationToken($input) {
return false;
}

// @see fusioninventory/inc/communication.class.php
$parsedXml = @simplexml_load_string($inventory, 'SimpleXMLElement', LIBXML_NOCDATA);
$parsedXml = PluginFlyvemdmCommon::parseXML($inventory);
if (!$parsedXml) {
$event = __('Inventory XML is not well formed', 'flyvemdm');
$this->filterMessages($event);
Expand Down
20 changes: 20 additions & 0 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,24 @@ public static function endsWith($haystack, $needle) {
$needle, $temp) !== false);
}

/**
* Check XML format using part of the logic from FusionInventory
*
* @see PluginFusioninventoryCommunication::handleOCSCommunication()
*
* @param mixed $xml
* @return SimpleXMLElement|boolean
*/
public static function parseXML($xml) {
if (($pxml = @simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA))) {
return $pxml;
}
if (($pxml = @simplexml_load_string(utf8_encode($xml), 'SimpleXMLElement', LIBXML_NOCDATA))) {
return $pxml;
}

$xml = preg_replace('/<FOLDER>.*?<\/SOURCE>/', '', $xml);
$pxml = @simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
return $pxml;
}
}
40 changes: 40 additions & 0 deletions tests/src/Flyvemdm/Tests/CommonTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,46 @@ public static function AgentXmlInventory($serial, $macAddress = '', $deviceId =
<HEALTH>Good</HEALTH>
<STATUS>Not charging</STATUS>
</BATTERIES>
<SOFTWARES>
<NAME><![CDATA[Bluetooth Pairing Utility]]></NAME>
<COMMENTS>com.symbol.btapp</COMMENTS>
<VERSION>3.10</VERSION>
<FILESIZE>0</FILESIZE>
<FROM>Android</FROM>
<INSTALLDATE>1519977807000</INSTALLDATE>
</SOFTWARES>
<SOFTWARES>
<NAME><![CDATA[com.android.cts.priv.ctsshim]]></NAME>
<COMMENTS>com.android.cts.priv.ctsshim</COMMENTS>
<VERSION>7.0-2996264</VERSION>
<FILESIZE>0</FILESIZE>
<FROM>Android</FROM>
<INSTALLDATE>1519977807000</INSTALLDATE>
</SOFTWARES>
<SOFTWARES>
<NAME><![CDATA[YouTube]]></NAME>
<COMMENTS>com.google.android.youtube</COMMENTS>
<VERSION>12.43.52</VERSION>
<FILESIZE>0</FILESIZE>
<FROM>Android</FROM>
<INSTALLDATE>1519977807000</INSTALLDATE>
</SOFTWARES>
<SOFTWARES>
<NAME><![CDATA[SampleExtAuthService]]></NAME>
<COMMENTS>com.qualcomm.qti.auth.sampleextauthservice</COMMENTS>
<VERSION>1.0</VERSION>
<FILESIZE>0</FILESIZE>
<FROM>Android</FROM>
<INSTALLDATE>1519977807000</INSTALLDATE>
</SOFTWARES>
<SOFTWARES>
<NAME><![CDATA[Kingdoms &amp; Lords]]></NAME>
<COMMENTS>com.gameloft.android.GloftKLMF</COMMENTS>
<VERSION>1.0.0</VERSION>
<FILESIZE>0</FILESIZE>
<FROM>Android</FROM>
<INSTALLDATE>1519977807000</INSTALLDATE>
</SOFTWARES>
</CONTENT>
</REQUEST>";
return base64_encode($xml);
Expand Down
12 changes: 12 additions & 0 deletions tests/suite-unit/PluginFlyvemdmCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
namespace tests\units;

use atoum;
use Flyvemdm\Tests\CommonTestCase;

class PluginFlyvemdmCommon extends atoum {

Expand Down Expand Up @@ -67,4 +68,15 @@ public function testGenerateUUID() {
->matches('/\w{8}-\w{4}-4\w{3}-[8,9,A,B]\w{3}-\w{12}/i');
}

/**
* @tags testParseXML
*/
public function testParseXML() {
$class = $this->testedClass->getClass();
$this->boolean($class::parseXML(''))->isFalse();
$xml = base64_decode(CommonTestCase::AgentXmlInventory(uniqid('sn')));
$this->object($class::parseXML(iconv("UTF-8", "ISO-8859-1",
$xml)))->isInstanceOf('\SimpleXMLElement');
$this->object($class::parseXML($xml))->isInstanceOf('\SimpleXMLElement');
}
}

0 comments on commit 6e95d99

Please sign in to comment.