From e3d9a037f6e41d08872c8c64a24c0b5257d5eae9 Mon Sep 17 00:00:00 2001
From: Jim Parry
Date: Fri, 15 Mar 2019 23:32:34 -0700
Subject: [PATCH 1/6] Added tests in ContentSecurityPolicyTest
---
.../system/HTTP/ContentSecurityPolicyTest.php | 33 +++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/tests/system/HTTP/ContentSecurityPolicyTest.php b/tests/system/HTTP/ContentSecurityPolicyTest.php
index 958bfa5f45..3e93b49172 100644
--- a/tests/system/HTTP/ContentSecurityPolicyTest.php
+++ b/tests/system/HTTP/ContentSecurityPolicyTest.php
@@ -39,6 +39,7 @@ class ContentSecurityPolicyTest extends \CIUnitTestCase
}
//--------------------------------------------------------------------
+
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
@@ -52,6 +53,7 @@ class ContentSecurityPolicyTest extends \CIUnitTestCase
}
//--------------------------------------------------------------------
+
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
@@ -66,6 +68,7 @@ class ContentSecurityPolicyTest extends \CIUnitTestCase
}
//--------------------------------------------------------------------
+
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
@@ -86,6 +89,7 @@ class ContentSecurityPolicyTest extends \CIUnitTestCase
}
//--------------------------------------------------------------------
+
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
@@ -306,6 +310,7 @@ class ContentSecurityPolicyTest extends \CIUnitTestCase
}
//--------------------------------------------------------------------
+
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
@@ -457,4 +462,32 @@ class ContentSecurityPolicyTest extends \CIUnitTestCase
$this->assertContains('nonce-', $result);
}
+ //--------------------------------------------------------------------
+
+ /**
+ * @runInSeparateProcess
+ * @preserveGlobalState disabled
+ */
+ public function testHeaderWrongCaseNotFound()
+ {
+ $this->prepare();
+ $result = $this->work();
+
+ $result = $this->getHeaderEmitted('content-security-policy');
+ $this->assertNull($result);
+ }
+
+ /**
+ * @runInSeparateProcess
+ * @preserveGlobalState disabled
+ */
+ public function testHeaderIgnoreCase()
+ {
+ $this->prepare();
+ $result = $this->work();
+
+ $result = $this->getHeaderEmitted('content-security-policy', true);
+ $this->assertContains("base-uri 'self';", $result);
+ }
+
}
From 14e1451aa949d67f3d68cdbbcafce11cd97e8c0a Mon Sep 17 00:00:00 2001
From: Jim Parry
Date: Sun, 17 Mar 2019 00:37:29 -0700
Subject: [PATCH 2/6] Fix & test Test\DOMParser
---
system/Test/DOMParser.php | 9 +++--
tests/system/Test/DOMParserTest.php | 53 +++++++++++++++++++++++++++--
2 files changed, 58 insertions(+), 4 deletions(-)
diff --git a/system/Test/DOMParser.php b/system/Test/DOMParser.php
index 55bd10eff9..41dfacd19a 100644
--- a/system/Test/DOMParser.php
+++ b/system/Test/DOMParser.php
@@ -47,7 +47,10 @@ class DOMParser
{
if (! extension_loaded('DOM'))
{
+ // always there in travis-ci
+ // @codeCoverageIgnoreStart
throw new \BadMethodCallException('DOM extension is required, but not currently loaded.');
+ // @codeCoverageIgnoreEnd
}
$this->dom = new \DOMDocument('1.0', 'utf-8');
@@ -78,8 +81,10 @@ class DOMParser
//turning off some errors
libxml_use_internal_errors(true);
- if (! $this->dom->loadHTML($content))
+ $this->dom->loadHTML($content);
+ if (sizeof(libxml_get_errors()) > 0)
{
+ libxml_clear_errors();
throw new \BadMethodCallException('Invalid HTML');
}
@@ -248,7 +253,7 @@ class DOMParser
{
foreach ($selector['attr'] as $key => $value)
{
- $path .= "[{$key}={$value}]";
+ $path .= "[@{$key}=\"{$value}\"]";
}
}
diff --git a/tests/system/Test/DOMParserTest.php b/tests/system/Test/DOMParserTest.php
index 8bd9b1479b..93ea627533 100644
--- a/tests/system/Test/DOMParserTest.php
+++ b/tests/system/Test/DOMParserTest.php
@@ -1,7 +1,9 @@
-Hello
';
$expected = '' . "\n"
- . 'Hello
';
+ . 'Hello
';
$this->assertEquals($expected . "\n", $dom->withString($html)->getBody());
}
@@ -74,6 +76,16 @@ class DOMParserTest extends CIUnitTestCase
$this->assertTrue($dom->see('Hello World'));
}
+ public function testBadHTML()
+ {
+ $dom = new DOMParser();
+
+ $html = 'Hello World
George