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\Bundle\Tests\Functional\ClientRegistration; |
15
|
|
|
|
16
|
|
|
use OAuth2Framework\Component\Core\Client\Client; |
17
|
|
|
use OAuth2Framework\Component\Core\Client\ClientId; |
18
|
|
|
use OAuth2Framework\Component\Core\Client\ClientRepository; |
19
|
|
|
use OAuth2Framework\Component\TokenRevocationEndpoint\TokenRevocationEndpoint; |
20
|
|
|
use Psr\Container\ContainerInterface; |
21
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @group Bundle |
25
|
|
|
* @group Functional |
26
|
|
|
* @group Grant |
27
|
|
|
* @group ClientRegistration |
28
|
|
|
*/ |
29
|
|
|
class ClientRegistrationEndpointTest extends WebTestCase |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
protected function setUp() |
35
|
|
|
{ |
36
|
|
|
if (!class_exists(TokenRevocationEndpoint::class)) { |
37
|
|
|
$this->markTestSkipped('The component "oauth2-framework/client-registration-endpoint" is not installed.'); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @test |
43
|
|
|
*/ |
44
|
|
|
public function theInitialAccessTokenExpired() |
45
|
|
|
{ |
46
|
|
|
$client = static::createClient(); |
47
|
|
|
$client->request('POST', '/client/management', [], [], ['HTTPS' => 'on', 'HTTP_AUTHORIZATION' => 'Bearer EXPIRED_INITIAL_ACCESS_TOKEN_ID'], null); |
48
|
|
|
$response = $client->getResponse(); |
49
|
|
|
self::assertEquals(400, $response->getStatusCode()); |
50
|
|
|
self::assertEquals('{"error":"invalid_request","error_description":"Initial Access Token expired."}', $response->getContent()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @test |
55
|
|
|
*/ |
56
|
|
|
public function theInitialAccessTokenIsMissing() |
57
|
|
|
{ |
58
|
|
|
$client = static::createClient(); |
59
|
|
|
$client->request('POST', '/client/management', [], [], ['HTTPS' => 'on'], null); |
60
|
|
|
$response = $client->getResponse(); |
61
|
|
|
self::assertEquals(400, $response->getStatusCode()); |
62
|
|
|
self::assertEquals('{"error":"invalid_request","error_description":"Initial Access Token is missing or invalid."}', $response->getContent()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @test |
67
|
|
|
*/ |
68
|
|
|
public function theInitialAccessTokenIsValidAndTheClientIsCreated() |
69
|
|
|
{ |
70
|
|
|
$client = static::createClient(); |
71
|
|
|
$client->request('POST', '/client/management', [], [], ['HTTPS' => 'on', 'HTTP_AUTHORIZATION' => 'Bearer VALID_INITIAL_ACCESS_TOKEN_ID'], null); |
72
|
|
|
$response = $client->getResponse(); |
73
|
|
|
self::assertEquals(201, $response->getStatusCode()); |
74
|
|
|
self::assertEquals('application/json; charset=UTF-8', $response->headers->get('content-type')); |
75
|
|
|
$content = json_decode($response->getContent(), true); |
76
|
|
|
self::assertInternalType('array', $content); |
77
|
|
|
self::assertArrayHasKey('client_id', $content); |
78
|
|
|
/** @var ContainerInterface $container */ |
79
|
|
|
$container = $client->getContainer(); |
80
|
|
|
/** @var ClientRepository $clientRepository */ |
81
|
|
|
$clientRepository = $container->get('MyClientRepository'); |
82
|
|
|
$client = $clientRepository->find(ClientId::create($content['client_id'])); |
83
|
|
|
self::assertInstanceOf(Client::class, $client); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|