mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-22 13:09:44 +05:30
Add code challenge verifier tests
This commit is contained in:
parent
fcd6eb8a3c
commit
1ddc27e792
24
tests/CodeChallengeVerifiers/PlainVerifier.php
Normal file
24
tests/CodeChallengeVerifiers/PlainVerifier.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace LeagueTests\CodeChallengeVerifiers;
|
||||
|
||||
use League\OAuth2\Server\CodeChallengeVerifiers\PlainVerifier;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class PlainVerifierTest extends TestCase
|
||||
{
|
||||
public function testGetMethod()
|
||||
{
|
||||
$verifier = new PlainVerifier();
|
||||
|
||||
$this->assertEquals('plain', $verifier->getMethod());
|
||||
}
|
||||
|
||||
public function testVerifyCodeChallenge()
|
||||
{
|
||||
$verifier = new PlainVerifier();
|
||||
|
||||
$this->assertTrue($verifier->verifyCodeChallenge('foo', 'foo');
|
||||
$this->assertFalse($verifier->verifyCodeChallenge('foo', 'bar');
|
||||
}
|
||||
}
|
37
tests/CodeChallengeVerifiers/S256Verifier.php
Normal file
37
tests/CodeChallengeVerifiers/S256Verifier.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace LeagueTests\CodeChallengeVerifiers;
|
||||
|
||||
use League\OAuth2\Server\CodeChallengeVerifiers\S256Verifier;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class S256Verifier extends TestCase
|
||||
{
|
||||
public function testGetMethod()
|
||||
{
|
||||
$verifier = new S256Verifier();
|
||||
|
||||
$this->assertEquals('S256', $verifier->getMethod());
|
||||
}
|
||||
|
||||
public function testVerifyCodeChallengeSucceeds()
|
||||
{
|
||||
$codeChallenge = $this->createCodeChallenge('foo');
|
||||
$verifier = new S256Verifier();
|
||||
|
||||
$this->assertTrue($verifier->verifyCodeChallenge('foo', $codeChallenge));
|
||||
}
|
||||
|
||||
public function testVerifyCodeChallengeFails()
|
||||
{
|
||||
$codeChallenge = $this->createCodeChallenge('bar');
|
||||
$verifier = new S256Verifier();
|
||||
|
||||
$this->assertFalse($verifier->verifyCodeChallenge('foo', $codeChallenge));
|
||||
}
|
||||
|
||||
private function createCodeChallenge($codeVerifier)
|
||||
{
|
||||
return strtr(rtrim(base64_encode(hash('sha256', $codeVerifier, true)), '='), '+/', '-_');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user