Skip to content

Commit

Permalink
Fix unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Nov 1, 2016
1 parent fea77a6 commit 61006a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"keywords": [
"content-security-policy",
"csp",
"http",
"headers",
"security",
"xss"
],
"license": "MIT",
Expand Down Expand Up @@ -31,6 +34,7 @@
"paragonie/constant_time_encoding": "^2.0"
},
"require-dev": {
"psr/http-message": "^1",
"phpunit/phpunit": "4.*|5.*"
},
"suggest": {
Expand Down
13 changes: 7 additions & 6 deletions src/CSPBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,25 +219,26 @@ public function enableOldBrowserSupport(): self
*/
public static function fromFile(string $filename = ''): self
{
if (!file_exists($filename)) {
if (!\file_exists($filename)) {
throw new \Exception($filename.' does not exist');
}
$json = \file_get_contents($filename);
$array = \json_decode($json, true);
return new CSPBuilder($array);
return self::fromData(
\file_get_contents($filename)
);
}

/**
* Factory method - create a new CSPBuilder object from a JSON data
*
* @param string $data
* @return CSPBuilder
* @throws \Exception
*/
public static function fromData($data = ''): self
{
$array = \json_decode($data, true);

if(!is_array($array)) {
if(!\is_array($array)) {
throw new \Exception('Is not array valid');
}

Expand Down Expand Up @@ -348,7 +349,7 @@ public function nonce(string $directive = 'script-src', string $nonce = ''): str
{
$ruleKeys = \array_keys($this->policies);
if (!\in_array($directive, $ruleKeys)) {
return null;
return '';
}

if (empty($nonce)) {
Expand Down

0 comments on commit 61006a0

Please sign in to comment.