]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Emit notice if XXE can't be tested and skip test
authorSteve Clay <steve@mrclay.org>
Wed, 31 Jul 2013 17:34:55 +0000 (13:34 -0400)
committerPaweł Sroka <srokap@gmail.com>
Mon, 4 Nov 2013 02:34:21 +0000 (03:34 +0100)
engine/tests/regression/trac_bugs.php

index ea39253df1bdad356ddcff05d7453fa0ef33bbfc..6892756617b50551e3957fce734d524381661e96 100644 (file)
@@ -377,6 +377,7 @@ class ElggCoreRegressionBugsTest extends ElggCoreUnitTest {
        public function test_ElggXMLElement_does_not_load_external_entities() {
                $elLast = libxml_disable_entity_loader(false);
 
+               // build payload that should trigger loading of external entity
                $payload = file_get_contents(dirname(dirname(__FILE__)) . '/test_files/xxe/request.xml');
                $path = realpath(dirname(dirname(__FILE__)) . '/test_files/xxe/external_entity.txt');
                $path = str_replace('\\', '/', $path);
@@ -384,16 +385,20 @@ class ElggCoreRegressionBugsTest extends ElggCoreUnitTest {
                        $path = '/' . $path;
                }
                $path = 'file://' . $path;
-               $payload = sprintf($payload, $path);\r
+               $payload = sprintf($payload, $path);
 
-               $el = new ElggXMLElement($payload);
-               $chidren = $el->getChildren();
-               $content = $chidren[0]->getContent();
-               $this->assertNoPattern('/secret/', $content);
-
-               //make sure the test is valid
+               // make sure we can actually this in this environment
                $element = new SimpleXMLElement($payload);
-               $this->assertPattern('/secret/', (string)$element->methodName);
+               $can_load_entity = preg_match('/secret/', (string)$element->methodName);
+
+               $this->skipUnless($can_load_entity, "XXE vulnerability cannot be tested on this system");
+
+               if ($can_load_entity) {
+                       $el = new ElggXMLElement($payload);
+                       $chidren = $el->getChildren();
+                       $content = $chidren[0]->getContent();
+                       $this->assertNoPattern('/secret/', $content);
+               }
 
                libxml_disable_entity_loader($elLast);
        }