Failed Conditions
Push — master ( b8d841...bc596e )
by Florent
28:20
created

WebFingerEndpointTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 86
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A aClientSendAnWebFingerRequestWithoutResourceParameter() 0 8 1
A aClientSendAnWebFingerRequestWithAnInvalidResourceParameterBasedOnAnXRI() 0 8 1
A aClientSendAnWebFingerRequestWithAnInvalidResourceParameterBasedOnAnAccount() 0 8 1
A aClientSendAnWebFingerRequestWithAnInvalidResourceParameterBasedOnAnEmail() 0 8 1
A aClientSendAnWebFingerRequestWithAnInvalidResourceParameterBasedOnAnUrl() 0 8 1
A aClientSendAnWebFingerRequestWithAValidResourceParameterBasedOnAnAccount() 0 8 1
A aClientSendAnWebFingerRequestWithAValidResourceParameterBasedOnAnUrl() 0 8 1
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