Skip to content

Commit

Permalink
Merge pull request #170 from villermen/fix/csrf-name-override
Browse files Browse the repository at this point in the history
Allow override of CSRF name
  • Loading branch information
froschdesign authored Jun 16, 2022
2 parents d854a56 + ea4b81d commit bfc12a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Element/Csrf.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function getCsrfValidator(): CsrfValidator
{
if (null === $this->csrfValidator) {
$csrfOptions = $this->getCsrfValidatorOptions();
$csrfOptions = array_merge($csrfOptions, ['name' => $this->getName()]);
$csrfOptions = array_merge(['name' => $this->getName()], $csrfOptions);
$this->setCsrfValidator(new CsrfValidator($csrfOptions));
assert(null !== $this->csrfValidator);
}
Expand Down
14 changes: 14 additions & 0 deletions test/Element/CsrfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,18 @@ public function testSetOptionsTraversable(): void
$this->assertEquals(777, $validator->getTimeOut());
$this->assertEquals('MySalt', $validator->getSalt());
}

public function testNameOverride(): void
{
$element = new CsrfElement('foo');
$element->setOptions([
'csrf_options' => [
'name' => 'bar',
],
]);
$validator = $element->getCsrfValidator();
$this->assertEquals('foo', $element->getName());
$this->assertEquals('bar', $validator->getName());
$this->assertEquals('Laminas_Validator_Csrf_salt_bar', $validator->getSessionName());
}
}

0 comments on commit bfc12a8

Please sign in to comment.