Skip to content

Commit

Permalink
Use named constructor for lcobucci/jwt Ecdsa signers
Browse files Browse the repository at this point in the history
  • Loading branch information
chalasr committed Jan 20, 2021
1 parent f6c0d9a commit 82b64a2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Services/JWSProvider/LcobucciJWSProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ private function getSignerForAlgorithm($signatureAlgorithm)

$signerClass = $signerMap[$signatureAlgorithm];

if (is_subclass_of($signerClass, Signer\Ecdsa::class) && method_exists($signerClass, 'create')) {
return $signerClass::create();
}

return new $signerClass();
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Services/JWSProvider/AbstractJWSProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function testCreateWithExtraStandardClaims()
$this->assertNotEmpty($created->getToken());
}

private function getKeyLoaderMock()
protected function getKeyLoaderMock()
{
return $this
->getMockBuilder(static::$keyLoaderClass)
Expand Down
22 changes: 22 additions & 0 deletions Tests/Services/JWSProvider/LcobucciJWSProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Lexik\Bundle\JWTAuthenticationBundle\Services\JWSProvider\LcobucciJWSProvider;
use Lexik\Bundle\JWTAuthenticationBundle\Services\KeyLoader\RawKeyLoader;
use Lexik\Bundle\JWTAuthenticationBundle\Signature\CreatedJWS;

/**
* Tests the LcobucciJWSProvider.
Expand All @@ -14,4 +15,25 @@ final class LcobucciJWSProviderTest extends AbstractJWSProviderTest
{
protected static $providerClass = LcobucciJWSProvider::class;
protected static $keyLoaderClass = RawKeyLoader::class;

public function testCreateWithEcdsa()
{
$keyLoaderMock = $this->getKeyLoaderMock();
$keyLoaderMock
->expects($this->once())
->method('loadKey')
->with('private')
->willReturn(self::$privateKey);
$keyLoaderMock
->expects($this->once())
->method('getPassphrase')
->willReturn('foobar');

$payload = ['username' => 'chalasr'];
$jwsProvider = new LcobucciJWSProvider($keyLoaderMock, 'openssl', 'EC512', 3600, 0);

$this->assertInstanceOf(CreatedJWS::class, $created = $jwsProvider->create($payload));

return $created->getToken();
}
}
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@
</exclude>
</whitelist>
</filter>

<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"></env>
</php>
</phpunit>

0 comments on commit 82b64a2

Please sign in to comment.