From 4c04e1609f336e34d93c42778338e64754e42c87 Mon Sep 17 00:00:00 2001 From: "Paragon Initiative Enterprises, LLC" Date: Mon, 24 Jul 2017 16:01:12 -0400 Subject: [PATCH] Add unit tests. --- src/CSPBuilder.php | 4 ++-- test/BasicTest.php | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/CSPBuilder.php b/src/CSPBuilder.php index 146d343..9cf60b5 100644 --- a/src/CSPBuilder.php +++ b/src/CSPBuilder.php @@ -447,9 +447,9 @@ public function saveSnippet( /** * Send the compiled CSP as a header() * - * @param boolean $legacy Send legacy headers? + * @param bool $legacy Send legacy headers? * - * @return boolean + * @return bool * @throws \Exception */ public function sendCSPHeader(bool $legacy = true): bool diff --git a/test/BasicTest.php b/test/BasicTest.php index a491404..ca830ae 100644 --- a/test/BasicTest.php +++ b/test/BasicTest.php @@ -118,7 +118,7 @@ public function testSourceHttpsConversion() } /** - * @covers \ParagonIE\CSPBuilder\CSPBuilder + * @covers CSPBuilder::disableHttpsTransformOnHttpsConnections() */ public function testUpgradeInsecureBeatsDisableHttpsConversionFlag() { @@ -131,6 +131,30 @@ public function testUpgradeInsecureBeatsDisableHttpsConversionFlag() $this->assertNotContains('http://example.com', $compiled); } + /** + * @covers CSPBuilder::setDataAllowed() + */ + public function testAllowDataUris() + { + $csp = new CSPBuilder(); + $csp->setDataAllowed('img-src', true); + $compiled = $csp->compile(); + + $this->assertContains("data:", $compiled); + } + + /** + * @covers CSPBuilder::setSelfAllowed() + */ + public function testAllowSelfUris() + { + $csp = new CSPBuilder(); + $csp->setSelfAllowed('img-src', true); + $compiled = $csp->compile(); + + $this->assertContains("'self'", $compiled); + } + /* public function testInjectCSPHeaderWithoutLegacy() {