Failed Conditions
Push — ng ( 17df75...6face8 )
by Florent
04:09
created

aClientSendAnIssuerDiscoveryRequestWithAValidResourceParameterBasedOnAnEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
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\IssuerDiscovery;
15
16
use OAuth2Framework\Component\IssuerDiscoveryEndpoint\IssuerDiscoveryEndpoint;
17
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
18
19
/**
20
 * @group Bundle
21
 * @group Functional
22
 * @group Grant
23
 * @group IssuerDiscovery
24
 */
25
class IssuerDiscoveryEndpointTest extends WebTestCase
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function setUp()
31
    {
32
        if (!class_exists(IssuerDiscoveryEndpoint::class)) {
33
            $this->markTestSkipped('The component "oauth2-framework/issuer-discovery-endpoint" is not installed.');
34
        }
35
    }
36
37
    /**
38
     * @test
39
     */
40
    public function aClientSendAnIssuerDiscoveryRequestWithoutRelParameter()
41
    {
42
        $client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]);
43
        $client->request('GET', '/.well-known/webfinger', [], [], ['HTTPS' => 'on'], null);
44
        $response = $client->getResponse();
45
        self::assertEquals(400, $response->getStatusCode());
46
        self::assertEquals('{"error":"invalid_request","error_description":"The parameter \"rel\" is mandatory."}', $response->getContent());
47
    }
48
49
    /**
50
     * @test
51
     */
52
    public function aClientSendAnIssuerDiscoveryRequestWithAnInvalidRelParameter()
53
    {
54
        $client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]);
55
        $client->request('GET', '/.well-known/webfinger', ['rel' => 'foo.bar'], [], ['HTTPS' => 'on'], null);
56
        $response = $client->getResponse();
57
        self::assertEquals(400, $response->getStatusCode());
58
        self::assertEquals('{"error":"invalid_request","error_description":"Unsupported \"rel\" parameter value."}', $response->getContent());
59
    }
60
61
    /**
62
     * @test
63
     */
64
    public function aClientSendAnIssuerDiscoveryRequestWithoutResourceParameter()
65
    {
66
        $client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]);
67
        $client->request('GET', '/.well-known/webfinger', ['rel' => 'http://openid.net/specs/connect/1.0/issuer'], [], ['HTTPS' => 'on'], null);
68
        $response = $client->getResponse();
69
        self::assertEquals(400, $response->getStatusCode());
70
        self::assertEquals('{"error":"invalid_request","error_description":"The parameter \"resource\" is mandatory."}', $response->getContent());
71
    }
72
73
    /**
74
     * @test
75
     */
76
    public function aClientSendAnIssuerDiscoveryRequestWithAnInvalidResourceParameterBasedOnAnXRI()
77
    {
78
        $client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]);
79
        $client->request('GET', '/.well-known/webfinger', ['rel' => 'http://openid.net/specs/connect/1.0/issuer', 'resource' => '@foo'], [], ['HTTPS' => 'on'], null);
80
        $response = $client->getResponse();
81
        self::assertEquals(400, $response->getStatusCode());
82
        self::assertEquals('{"error":"invalid_request","error_description":"The resource identified with \"@foo\" does not exist or is not supported by this server."}', $response->getContent());
83
    }
84
85
    /**
86
     * @test
87
     */
88
    public function aClientSendAnIssuerDiscoveryRequestWithAnInvalidResourceParameterBasedOnAnAccount()
89
    {
90
        $client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]);
91
        $client->request('GET', '/.well-known/webfinger', ['rel' => 'http://openid.net/specs/connect/1.0/issuer', 'resource' => 'acct:[email protected]'], [], ['HTTPS' => 'on'], null);
92
        $response = $client->getResponse();
93
        self::assertEquals(400, $response->getStatusCode());
94
        self::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());
95
    }
96
97
    /**
98
     * @test
99
     */
100
    public function aClientSendAnIssuerDiscoveryRequestWithAnInvalidResourceParameterBasedOnAnEmail()
101
    {
102
        $client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]);
103
        $client->request('GET', '/.well-known/webfinger', ['rel' => 'http://openid.net/specs/connect/1.0/issuer', 'resource' => '[email protected]'], [], ['HTTPS' => 'on'], null);
104
        $response = $client->getResponse();
105
        self::assertEquals(400, $response->getStatusCode());
106
        self::assertEquals('{"error":"invalid_request","error_description":"The resource identified with \"[email protected]\" does not exist or is not supported by this server."}', $response->getContent());
107
    }
108
109
    /**
110
     * @test
111
     */
112
    public function aClientSendAnIssuerDiscoveryRequestWithAnInvalidResourceParameterBasedOnAnUrl()
113
    {
114
        $client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]);
115
        $client->request('GET', '/.well-known/webfinger', ['rel' => 'http://openid.net/specs/connect/1.0/issuer', 'resource' => 'https://example.com:8080/+john'], [], ['HTTPS' => 'on'], null);
116
        $response = $client->getResponse();
117
        self::assertEquals(400, $response->getStatusCode());
118
        self::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());
119
    }
120
121
    /**
122
     * @test
123
     */
124
    public function aClientSendAnIssuerDiscoveryRequestWithAValidResourceParameterBasedOnAnAccount()
125
    {
126
        $client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]);
127
        $client->request('GET', '/.well-known/webfinger', ['rel' => 'http://openid.net/specs/connect/1.0/issuer', 'resource' => 'acct:[email protected]:443'], [], ['HTTPS' => 'on'], null);
128
        $response = $client->getResponse();
129
        self::assertEquals(200, $response->getStatusCode());
130
        self::assertEquals('{"subject":"acct:[email protected]:443","links":[{"rel":"http://openid.net/specs/connect/1.0/issuer","href":"https://server.example.com"}]}', $response->getContent());
131
    }
132
133
    /**
134
     * @test
135
     */
136
    public function aClientSendAnIssuerDiscoveryRequestWithAValidResourceParameterBasedOnAnUrl()
137
    {
138
        $client = static::createClient([], ['HTTP_HOST' => 'my-service.com', 'HTTP_PORT' => 443]);
139
        $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);
140
        $response = $client->getResponse();
141
        self::assertEquals(200, $response->getStatusCode());
142
        self::assertEquals('{"subject":"https://my-service.com:443/+john","links":[{"rel":"http://openid.net/specs/connect/1.0/issuer","href":"https://server.example.com"}]}', $response->getContent());
143
    }
144
}
145