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\None; |
21
|
|
|
use PHPUnit\Framework\TestCase; |
22
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
23
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
24
|
|
|
use Psr\Http\Message\StreamInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @group TokenEndpoint |
28
|
|
|
* @group ClientAuthentication |
29
|
|
|
*/ |
30
|
|
|
final class NoneAuthenticationMethodTest extends TestCase |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @test |
34
|
|
|
*/ |
35
|
|
|
public function genericCalls() |
36
|
|
|
{ |
37
|
|
|
$method = new None(); |
38
|
|
|
|
39
|
|
|
self::assertEquals([], $method->getSchemesParameters()); |
40
|
|
|
self::assertEquals(['none'], $method->getSupportedMethods()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @test |
45
|
|
|
*/ |
46
|
|
|
public function theClientIdCannotBeFoundInTheRequest() |
47
|
|
|
{ |
48
|
|
|
$method = new None(); |
49
|
|
|
$request = $this->buildRequest([]); |
50
|
|
|
|
51
|
|
|
$clientId = $method->findClientIdAndCredentials($request->reveal(), $credentials); |
52
|
|
|
self::assertNull($clientId); |
53
|
|
|
self::assertNull($credentials); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @test |
58
|
|
|
*/ |
59
|
|
|
public function theClientIdHasBeenFoundInTheRequest() |
60
|
|
|
{ |
61
|
|
|
$method = new None(); |
62
|
|
|
$request = $this->buildRequest(['client_id' => 'CLIENT_ID']); |
63
|
|
|
|
64
|
|
|
$clientId = $method->findClientIdAndCredentials($request->reveal(), $credentials); |
65
|
|
|
self::assertInstanceOf(ClientId::class, $clientId); |
66
|
|
|
self::assertNull($credentials); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @test |
71
|
|
|
*/ |
72
|
|
|
public function theClientIsAuthenticated() |
73
|
|
|
{ |
74
|
|
|
$method = new None(); |
75
|
|
|
$request = $this->prophesize(ServerRequestInterface::class); |
76
|
|
|
$client = Client::createEmpty(); |
77
|
|
|
$client = $client->create( |
78
|
|
|
ClientId::create('CLIENT_ID'), |
79
|
|
|
DataBag::create([]), |
80
|
|
|
UserAccountId::create('USER_ACCOUNT_ID') |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
self::assertTrue($method->isClientAuthenticated($client, null, $request->reveal())); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @test |
88
|
|
|
*/ |
89
|
|
|
public function theClientConfigurationCanBeChecked() |
90
|
|
|
{ |
91
|
|
|
$method = new None(); |
92
|
|
|
$parameters = DataBag::create([]); |
93
|
|
|
$validatedParameters = DataBag::create([]); |
94
|
|
|
|
95
|
|
|
self::assertSame($validatedParameters, $method->checkClientConfiguration($parameters, $validatedParameters)); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
private function buildRequest(array $data): ObjectProphecy |
99
|
|
|
{ |
100
|
|
|
$body = $this->prophesize(StreamInterface::class); |
101
|
|
|
$body->getContents()->willReturn(http_build_query($data)); |
102
|
|
|
$request = $this->prophesize(ServerRequestInterface::class); |
103
|
|
|
$request->hasHeader('Content-Type')->willReturn(true); |
104
|
|
|
$request->getHeader('Content-Type')->willReturn(['application/x-www-form-urlencoded']); |
105
|
|
|
$request->getBody()->willReturn($body->reveal()); |
106
|
|
|
$request->getParsedBody()->willReturn([]); |
107
|
|
|
|
108
|
|
|
return $request; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|