-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from GoogleChromeLabs/ineffective-config
Ineffective config
- Loading branch information
Showing
3 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Ise\WebSecurityBundle\Options; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class ContextChecker | ||
{ | ||
private $insecureMessage = "Warning: request from %s is an insecure context. %s policy may not be active as it requires a secure context."; | ||
private $logger; | ||
public function __construct(LoggerInterface $logger) | ||
{ | ||
$this->logger = $logger; | ||
} | ||
|
||
public function checkSecure(Request $request, String $policy) | ||
{ | ||
if (!$request->isSecure()) { | ||
$insecureLog = sprintf($this->insecureMessage, $request->getUri(), $policy); | ||
$this->logger->error($insecureLog); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Ise\WebSecurityBundle\Tests; | ||
|
||
use Ise\WebSecurityBundle\Options\ContextChecker; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Log\Logger; | ||
|
||
class IseWebSecurityContextCheckerTest extends TestCase | ||
{ | ||
public function testSecureContext() | ||
{ | ||
$logger = $this->getMockBuilder(Logger::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$context = new ContextChecker($logger); | ||
|
||
$request = Request::create('https://127.0.0.1'); | ||
|
||
$context->checkSecure($request, 'COOP'); | ||
$logger->expects($this->never()) | ||
->method('error'); | ||
} | ||
} |