Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions Service/ReplayRequestSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@
class ReplayRequestSignature
{
public function __construct(
private string $secret,
private ?CsrfTokenManagerInterface $csrfTokenManager = null
private string $secret
) {
}

public function generate(string $token, int $callIndex): string
{
$tokenId = $this->buildTokenId($token, $callIndex);

if ($this->csrfTokenManager) {
return $this->csrfTokenManager->getToken($tokenId)->getValue();
}

return hash_hmac('sha256', $tokenId, $this->secret);
}

Expand All @@ -32,10 +27,6 @@ public function isValid(string $token, int $callIndex, ?string $submittedToken):

$tokenId = $this->buildTokenId($token, $callIndex);

if ($this->csrfTokenManager) {
return $this->csrfTokenManager->isTokenValid(new CsrfToken($tokenId, $submittedToken));
}

return hash_equals($this->generate($token, $callIndex), $submittedToken);
}

Expand Down
3 changes: 1 addition & 2 deletions Twig/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class Extension extends AbstractExtension
public function __construct(
protected LoaderInterface $loader,
private ?ReplayRequestSignature $replayRequestSignature = null
)
{
) {
}

public function getName(): string
Expand Down
31 changes: 14 additions & 17 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
colors="true"
processIsolation="false"
convertWarningsToExceptions="false"
stopOnFailure="false"
Expand All @@ -10,25 +12,20 @@
<directory>./Tests</directory>
</testsuite>
</testsuites>
<coverage>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">.</directory>
<directory suffix=".php">./Http</directory>
<directory suffix=".php">./Service</directory>
</include>
<exclude>
<directory>./vendor</directory>
<directory>./Tests</directory>
</exclude>
<report>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory>./Http</directory>
<directory>./Service</directory>
<exclude>
<directory>./vendor</directory>
<directory>./Tests</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<php>
<env name="HTTP_BIN_URL" value="https://httpbin.org"/>
</php>
</phpunit>
</phpunit>
Loading