Skip to content

Commit

Permalink
Add unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Jul 24, 2017
1 parent 030691e commit 4c04e16
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/CSPBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 25 additions & 1 deletion test/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function testSourceHttpsConversion()
}

/**
* @covers \ParagonIE\CSPBuilder\CSPBuilder
* @covers CSPBuilder::disableHttpsTransformOnHttpsConnections()
*/
public function testUpgradeInsecureBeatsDisableHttpsConversionFlag()
{
Expand All @@ -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()
{
Expand Down

0 comments on commit 4c04e16

Please sign in to comment.