1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* The MIT License (MIT) |
7
|
|
|
* |
8
|
|
|
* Copyright (c) 2014-2018 Spomky-Labs |
9
|
|
|
* |
10
|
|
|
* This software may be modified and distributed under the terms |
11
|
|
|
* of the MIT license. See the LICENSE file for details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace OAuth2Framework\Component\Server\TokenEndpoint\Tests; |
15
|
|
|
|
16
|
|
|
use Interop\Http\Server\RequestHandlerInterface; |
17
|
|
|
use OAuth2Framework\Component\Server\Core\Client\ClientRepository; |
18
|
|
|
use OAuth2Framework\Component\Server\TokenEndpoint\AuthenticationMethod\AuthenticationMethod; |
19
|
|
|
use OAuth2Framework\Component\Server\TokenEndpoint\AuthenticationMethod\AuthenticationMethodManager; |
20
|
|
|
use OAuth2Framework\Component\Server\TokenEndpoint\ClientAuthenticationMiddleware; |
21
|
|
|
use PHPUnit\Framework\TestCase; |
22
|
|
|
use Prophecy\Argument; |
23
|
|
|
use Psr\Http\Message\ResponseInterface; |
24
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @group TokenEndpoint |
28
|
|
|
* @group ClientAuthenticationMiddleware |
29
|
|
|
*/ |
30
|
|
|
final class ClientAuthenticationMiddlewareTest extends TestCase |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @test |
34
|
|
|
*/ |
35
|
|
|
public function noClientIsFoundInTheRequest() |
36
|
|
|
{ |
37
|
|
|
$response = $this->prophesize(ResponseInterface::class); |
38
|
|
|
$request = $this->prophesize(ServerRequestInterface::class); |
39
|
|
|
$handler = $this->prophesize(RequestHandlerInterface::class); |
40
|
|
|
$clientRepository = $this->prophesize(ClientRepository::class); |
41
|
|
|
$handler->handle(Argument::type(ServerRequestInterface::class)) |
42
|
|
|
->shouldBeCalled() |
43
|
|
|
->willReturn($response->reveal()) |
44
|
|
|
; |
45
|
|
|
|
46
|
|
|
$this->getClientAuthenticationMiddleware($clientRepository->reveal())->process($request->reveal(), $handler->reveal()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param ClientRepository $clientRepository |
51
|
|
|
* |
52
|
|
|
* @return ClientAuthenticationMiddleware |
53
|
|
|
*/ |
54
|
|
|
private function getClientAuthenticationMiddleware(ClientRepository $clientRepository): ClientAuthenticationMiddleware |
55
|
|
|
{ |
56
|
|
|
$authenticationMethodManager = new AuthenticationMethodManager(); |
57
|
|
|
|
58
|
|
|
$clientAuthenticationMiddleware = new ClientAuthenticationMiddleware( |
59
|
|
|
$clientRepository, |
60
|
|
|
$authenticationMethodManager |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
return $clientAuthenticationMiddleware; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|