|
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\WebFingerBundle\Tests\Functional; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @group ServerBundle |
|
20
|
|
|
* @group Functional |
|
21
|
|
|
* @group Grant |
|
22
|
|
|
* @group WebFinger |
|
23
|
|
|
*/ |
|
24
|
|
|
class WebFingerEndpointTest extends WebTestCase |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @test |
|
28
|
|
|
*/ |
|
29
|
|
|
public function aClientSendAnWebFingerRequestWithoutResourceParameter() |
|
30
|
|
|
{ |
|
31
|
|
|
$client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]); |
|
32
|
|
|
$client->request('GET', '/.well-known/webfinger', ['rel' => 'http://openid.net/specs/connect/1.0/issuer'], [], ['HTTPS' => 'on'], null); |
|
33
|
|
|
$response = $client->getResponse(); |
|
34
|
|
|
static::assertEquals(400, $response->getStatusCode()); |
|
35
|
|
|
static::assertEquals('{"error":"invalid_request","error_description":"The parameter \"resource\" is mandatory."}', $response->getContent()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @test |
|
40
|
|
|
*/ |
|
41
|
|
|
public function aClientSendAnWebFingerRequestWithAnInvalidResourceParameterBasedOnAnXRI() |
|
42
|
|
|
{ |
|
43
|
|
|
$client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]); |
|
44
|
|
|
$client->request('GET', '/.well-known/webfinger', ['rel' => 'http://openid.net/specs/connect/1.0/issuer', 'resource' => '@foo'], [], ['HTTPS' => 'on'], null); |
|
45
|
|
|
$response = $client->getResponse(); |
|
46
|
|
|
static::assertEquals(400, $response->getStatusCode()); |
|
47
|
|
|
static::assertEquals('{"error":"invalid_request","error_description":"The resource identified with \"@foo\" does not exist or is not supported by this server."}', $response->getContent()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @test |
|
52
|
|
|
*/ |
|
53
|
|
|
public function aClientSendAnWebFingerRequestWithAnInvalidResourceParameterBasedOnAnAccount() |
|
54
|
|
|
{ |
|
55
|
|
|
$client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]); |
|
56
|
|
|
$client->request('GET', '/.well-known/webfinger', ['rel' => 'http://openid.net/specs/connect/1.0/issuer', 'resource' => 'acct:[email protected]'], [], ['HTTPS' => 'on'], null); |
|
57
|
|
|
$response = $client->getResponse(); |
|
58
|
|
|
static::assertEquals(400, $response->getStatusCode()); |
|
59
|
|
|
static::assertEquals('{"error":"invalid_request","error_description":"The resource identified with \"acct:[email protected]\" does not exist or is not supported by this server."}', $response->getContent()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @test |
|
64
|
|
|
*/ |
|
65
|
|
|
public function aClientSendAnWebFingerRequestWithAnInvalidResourceParameterBasedOnAnEmail() |
|
66
|
|
|
{ |
|
67
|
|
|
$client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]); |
|
68
|
|
|
$client->request('GET', '/.well-known/webfinger', ['rel' => 'http://openid.net/specs/connect/1.0/issuer', 'resource' => '[email protected]'], [], ['HTTPS' => 'on'], null); |
|
69
|
|
|
$response = $client->getResponse(); |
|
70
|
|
|
static::assertEquals(400, $response->getStatusCode()); |
|
71
|
|
|
static::assertEquals('{"error":"invalid_request","error_description":"The resource identified with \"[email protected]\" does not exist or is not supported by this server."}', $response->getContent()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @test |
|
76
|
|
|
*/ |
|
77
|
|
|
public function aClientSendAnWebFingerRequestWithAnInvalidResourceParameterBasedOnAnUrl() |
|
78
|
|
|
{ |
|
79
|
|
|
$client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]); |
|
80
|
|
|
$client->request('GET', '/.well-known/webfinger', ['rel' => 'http://openid.net/specs/connect/1.0/issuer', 'resource' => 'https://example.com:8080/+john'], [], ['HTTPS' => 'on'], null); |
|
81
|
|
|
$response = $client->getResponse(); |
|
82
|
|
|
static::assertEquals(400, $response->getStatusCode()); |
|
83
|
|
|
static::assertEquals('{"error":"invalid_request","error_description":"The resource identified with \"https://example.com:8080/+john\" does not exist or is not supported by this server."}', $response->getContent()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @test |
|
88
|
|
|
*/ |
|
89
|
|
|
public function aClientSendAnWebFingerRequestWithAValidResourceParameterBasedOnAnAccount() |
|
90
|
|
|
{ |
|
91
|
|
|
$client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]); |
|
92
|
|
|
$client->request('GET', '/.well-known/webfinger', ['rel' => 'http://openid.net/specs/connect/1.0/issuer', 'resource' => 'acct:[email protected]:443'], [], ['HTTPS' => 'on'], null); |
|
93
|
|
|
$response = $client->getResponse(); |
|
94
|
|
|
static::assertEquals(200, $response->getStatusCode()); |
|
95
|
|
|
static::assertEquals('{"subject":"john","aliases":["acct:[email protected]:443","https://my-service.com:443/+john"],"links":[{"rel":"http://openid.net/specs/connect/1.0/issuer","href":"https://server.example.com"}]}', $response->getContent()); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @test |
|
100
|
|
|
*/ |
|
101
|
|
|
public function aClientSendAnWebFingerRequestWithAValidResourceParameterBasedOnAnUrl() |
|
102
|
|
|
{ |
|
103
|
|
|
$client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]); |
|
104
|
|
|
$client->request('GET', '/.well-known/webfinger', ['rel' => 'http://openid.net/specs/connect/1.0/issuer', 'resource' => 'https://my-service.com:443/+john'], [], ['HTTPS' => 'on'], null); |
|
105
|
|
|
$response = $client->getResponse(); |
|
106
|
|
|
static::assertEquals(200, $response->getStatusCode()); |
|
107
|
|
|
static::assertEquals('{"subject":"john","aliases":["acct:[email protected]:443","https://my-service.com:443/+john"],"links":[{"rel":"http://openid.net/specs/connect/1.0/issuer","href":"https://server.example.com"}]}', $response->getContent()); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|