Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use named constructor for lcobucci/jwt Ecdsa signers #827

Merged
merged 1 commit into from
Jan 20, 2021
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
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>