|
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\ClientAuthentication\Tests; |
|
15
|
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Core\Client\Client; |
|
17
|
|
|
use OAuth2Framework\Component\Core\Client\ClientId; |
|
18
|
|
|
use OAuth2Framework\Component\Core\DataBag\DataBag; |
|
19
|
|
|
use OAuth2Framework\Component\Core\UserAccount\UserAccountId; |
|
20
|
|
|
use OAuth2Framework\Component\ClientAuthentication\ClientSecretPost; |
|
21
|
|
|
use PHPUnit\Framework\TestCase; |
|
22
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @group TokenEndpoint |
|
26
|
|
|
* @group ClientAuthentication |
|
27
|
|
|
*/ |
|
28
|
|
|
class ClientSecretPostAuthenticationMethodTest extends TestCase |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @test |
|
32
|
|
|
*/ |
|
33
|
|
|
public function genericCalls() |
|
34
|
|
|
{ |
|
35
|
|
|
$method = new ClientSecretPost(); |
|
36
|
|
|
|
|
37
|
|
|
self::assertEquals([], $method->getSchemesParameters()); |
|
38
|
|
|
self::assertEquals(['client_secret_post'], $method->getSupportedMethods()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @test |
|
43
|
|
|
*/ |
|
44
|
|
|
public function theClientIdCannotBeFoundInTheRequest() |
|
45
|
|
|
{ |
|
46
|
|
|
$method = new ClientSecretPost(); |
|
47
|
|
|
$request = $this->prophesize(ServerRequestInterface::class); |
|
48
|
|
|
$request->getParsedBody()->willReturn([]); |
|
49
|
|
|
|
|
50
|
|
|
$clientId = $method->findClientIdAndCredentials($request->reveal(), $credentials); |
|
51
|
|
|
self::assertNull($clientId); |
|
52
|
|
|
self::assertNull($credentials); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @test |
|
57
|
|
|
*/ |
|
58
|
|
|
public function theClientIdHasBeenFoundInTheRequestButNoClientSecret() |
|
59
|
|
|
{ |
|
60
|
|
|
$method = new ClientSecretPost(); |
|
61
|
|
|
$request = $this->prophesize(ServerRequestInterface::class); |
|
62
|
|
|
$request->getParsedBody()->willReturn(['client_id' => 'CLIENT_ID']); |
|
63
|
|
|
|
|
64
|
|
|
$clientId = $method->findClientIdAndCredentials($request->reveal(), $credentials); |
|
65
|
|
|
self::assertNull($clientId); |
|
66
|
|
|
self::assertNull($credentials); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @test |
|
71
|
|
|
*/ |
|
72
|
|
|
public function theClientIdAndClientSecretHaveBeenFoundInTheRequest() |
|
73
|
|
|
{ |
|
74
|
|
|
$method = new ClientSecretPost(); |
|
75
|
|
|
$request = $this->prophesize(ServerRequestInterface::class); |
|
76
|
|
|
$request->getParsedBody()->willReturn([ |
|
77
|
|
|
'client_id' => 'CLIENT_ID', |
|
78
|
|
|
'client_secret' => 'CLIENT_SECRET', |
|
79
|
|
|
]); |
|
80
|
|
|
|
|
81
|
|
|
$clientId = $method->findClientIdAndCredentials($request->reveal(), $credentials); |
|
82
|
|
|
self::assertInstanceOf(ClientId::class, $clientId); |
|
83
|
|
|
self::assertEquals('CLIENT_SECRET', $credentials); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @test |
|
88
|
|
|
*/ |
|
89
|
|
|
public function theClientIsAuthenticated() |
|
90
|
|
|
{ |
|
91
|
|
|
$method = new ClientSecretPost(); |
|
92
|
|
|
$request = $this->prophesize(ServerRequestInterface::class); |
|
93
|
|
|
$request->getParsedBody()->willReturn([ |
|
94
|
|
|
'client_id' => 'CLIENT_ID', |
|
95
|
|
|
'client_secret' => 'CLIENT_SECRET', |
|
96
|
|
|
]); |
|
97
|
|
|
$client = Client::createEmpty(); |
|
98
|
|
|
$client = $client->create( |
|
99
|
|
|
ClientId::create('CLIENT_ID'), |
|
100
|
|
|
DataBag::create([ |
|
101
|
|
|
'client_secret' => 'CLIENT_SECRET', |
|
102
|
|
|
]), |
|
103
|
|
|
UserAccountId::create('USER_ACCOUNT_ID') |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
|
|
self::assertTrue($method->isClientAuthenticated($client, 'CLIENT_SECRET', $request->reveal())); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @test |
|
111
|
|
|
*/ |
|
112
|
|
|
public function theClientConfigurationCanBeChecked() |
|
113
|
|
|
{ |
|
114
|
|
|
$method = new ClientSecretPost(); |
|
115
|
|
|
$validatedParameters = $method->checkClientConfiguration(DataBag::create([]), DataBag::create([])); |
|
116
|
|
|
|
|
117
|
|
|
self::assertTrue($validatedParameters->has('client_secret')); |
|
118
|
|
|
self::assertTrue($validatedParameters->has('client_secret_expires_at')); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|