mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
Merge remote-tracking branch 'upstream/8.0.0' into access-token-jwt
This commit is contained in:
67
tests/Exception/OAuthServerExceptionTest.php
Normal file
67
tests/Exception/OAuthServerExceptionTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace LeagueTests\Exception;
|
||||
|
||||
use League\OAuth2\Server\Exception\OAuthServerException;
|
||||
use League\OAuth2\Server\Grant\AbstractGrant;
|
||||
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\ServerRequest;
|
||||
|
||||
class OAuthServerExceptionTest extends TestCase
|
||||
{
|
||||
public function testInvalidClientExceptionSetsAuthenticateHeader()
|
||||
{
|
||||
$serverRequest = (new ServerRequest())
|
||||
->withParsedBody([
|
||||
'client_id' => 'foo',
|
||||
])
|
||||
->withAddedHeader('Authorization', 'Basic fakeauthdetails');
|
||||
|
||||
try {
|
||||
$this->issueInvalidClientException($serverRequest);
|
||||
} catch (OAuthServerException $e) {
|
||||
$response = $e->generateHttpResponse(new Response());
|
||||
|
||||
$this->assertTrue($response->hasHeader('WWW-Authenticate'));
|
||||
}
|
||||
}
|
||||
|
||||
public function testInvalidClientExceptionOmitsAuthenticateHeader()
|
||||
{
|
||||
$serverRequest = (new ServerRequest())
|
||||
->withParsedBody([
|
||||
'client_id' => 'foo',
|
||||
]);
|
||||
|
||||
try {
|
||||
$this->issueInvalidClientException($serverRequest);
|
||||
} catch (OAuthServerException $e) {
|
||||
$response = $e->generateHttpResponse(new Response());
|
||||
|
||||
$this->assertFalse($response->hasHeader('WWW-Authenticate'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue an invalid client exception
|
||||
*
|
||||
* @throws OAuthServerException
|
||||
*/
|
||||
private function issueInvalidClientException($serverRequest)
|
||||
{
|
||||
$clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();
|
||||
$clientRepositoryMock->method('getClientEntity')->willReturn(false);
|
||||
|
||||
$grantMock = $this->getMockForAbstractClass(AbstractGrant::class);
|
||||
$grantMock->setClientRepository($clientRepositoryMock);
|
||||
|
||||
$abstractGrantReflection = new \ReflectionClass($grantMock);
|
||||
|
||||
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient');
|
||||
$validateClientMethod->setAccessible(true);
|
||||
|
||||
$validateClientMethod->invoke($grantMock, $serverRequest);
|
||||
}
|
||||
}
|
@@ -122,7 +122,7 @@ class AbstractGrantTest extends TestCase
|
||||
$validateClientMethod = $abstractGrantReflection->getMethod('validateClient');
|
||||
$validateClientMethod->setAccessible(true);
|
||||
|
||||
$result = $validateClientMethod->invoke($grantMock, $serverRequest, true, true);
|
||||
$result = $validateClientMethod->invoke($grantMock, $serverRequest);
|
||||
$this->assertEquals($client, $result);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user