|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the login-cidadao project or it's bundles. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Guilherme Donato <guilhermednt on github> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace LoginCidadao\OpenIDBundle\Tests\Entity; |
|
12
|
|
|
|
|
13
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
14
|
|
|
use LoginCidadao\CoreBundle\Entity\Person; |
|
15
|
|
|
use LoginCidadao\OAuthBundle\Entity\Client; |
|
16
|
|
|
use LoginCidadao\OpenIDBundle\Entity\ClientMetadata; |
|
17
|
|
|
|
|
18
|
|
|
class ClientMetadataTest extends \PHPUnit_Framework_TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function testEntity() |
|
21
|
|
|
{ |
|
22
|
|
|
$client = new Client(); |
|
23
|
|
|
$client->getOwners()->add((new Person())->setEmail('[email protected]')); |
|
24
|
|
|
|
|
25
|
|
|
/** @var ClientMetadata $metadata */ |
|
26
|
|
|
$metadata = (new ClientMetadata()) |
|
27
|
|
|
->setId($id = 'my id') |
|
28
|
|
|
->setResponseTypes(null) |
|
29
|
|
|
->setApplicationType(null) |
|
30
|
|
|
->setGrantTypes(null) |
|
31
|
|
|
->setSubjectType(null) |
|
32
|
|
|
->setClientId($clientId = 'the.client.id') |
|
33
|
|
|
->setClientSecret($clientSecret = 'super secret') |
|
34
|
|
|
->setClient($client) |
|
35
|
|
|
->setRedirectUris($uris = ['https://example.com/']) |
|
36
|
|
|
->setContacts($contacts = ['[email protected]']) |
|
37
|
|
|
->setLogoUri($logoUri = 'https://example.com/mylogo.png') |
|
38
|
|
|
->setClientUri($clientUri = 'https://example.com') |
|
39
|
|
|
->setPolicyUri($policyUri = 'https://example.com/policy') |
|
40
|
|
|
->setTosUri($tosUri = 'https://example.com/tos') |
|
41
|
|
|
->setJwksUri($jwksUri = 'https://example.com/jwks') |
|
42
|
|
|
->setJwks($jwks = 'something') |
|
43
|
|
|
->setSectorIdentifierUri($sectorIdentifierUri = 'https://example.com/sector') |
|
44
|
|
|
->setIdTokenEncryptedResponseAlg('ALG') |
|
45
|
|
|
->setIdTokenEncryptedResponseEnc('ENC') |
|
46
|
|
|
->setUserinfoSignedResponseAlg('ALG') |
|
47
|
|
|
->setUserinfoEncryptedResponseAlg('ALG') |
|
48
|
|
|
->setUserinfoEncryptedResponseEnc('ENC') |
|
49
|
|
|
->setRequestObjectSigningAlg('ALG') |
|
50
|
|
|
->setRequestObjectEncryptionAlg('ALG') |
|
51
|
|
|
->setRequestObjectEncryptionEnc('ENC') |
|
52
|
|
|
->setTokenEndpointAuthSigningAlg('ALG') |
|
53
|
|
|
->setDefaultMaxAge(12345) |
|
54
|
|
|
->setDefaultAcrValues([]) |
|
55
|
|
|
->setInitiateLoginUri($loginUri = 'https://example.com/login') |
|
56
|
|
|
->setRegistrationAccessToken($regAccessToken = 'accessToken') |
|
57
|
|
|
->setPostLogoutRedirectUris($uris) |
|
58
|
|
|
->setRequestUris($uris); |
|
59
|
|
|
$metadata->checkDefaults(); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertSame($clientId, $metadata->getClientId()); |
|
62
|
|
|
$this->assertSame($clientSecret, $metadata->getClientSecret()); |
|
63
|
|
|
$this->assertSame($client, $metadata->getClient()); |
|
64
|
|
|
$this->assertSame($uris, $metadata->getRedirectUris()); |
|
65
|
|
|
$this->assertContains('[email protected]', $metadata->getContacts()); |
|
66
|
|
|
$this->assertSame($logoUri, $metadata->getLogoUri()); |
|
67
|
|
|
$this->assertSame($clientUri, $metadata->getClientUri()); |
|
68
|
|
|
$this->assertSame($policyUri, $metadata->getPolicyUri()); |
|
69
|
|
|
$this->assertSame($tosUri, $metadata->getTosUri()); |
|
70
|
|
|
$this->assertSame($jwksUri, $metadata->getJwksUri()); |
|
71
|
|
|
$this->assertSame($jwks, $metadata->getJwks()); |
|
72
|
|
|
$this->assertSame($sectorIdentifierUri, $metadata->getSectorIdentifierUri()); |
|
73
|
|
|
$this->assertSame(12345, $metadata->getDefaultMaxAge()); |
|
74
|
|
|
$this->assertSame($loginUri, $metadata->getInitiateLoginUri()); |
|
75
|
|
|
$this->assertSame($regAccessToken, $metadata->getRegistrationAccessToken()); |
|
76
|
|
|
$this->assertSame($uris, $metadata->getPostLogoutRedirectUris()); |
|
77
|
|
|
$this->assertSame('pairwise', $metadata->getSubjectType()); |
|
78
|
|
|
$this->assertSame('example.com', $metadata->getSectorIdentifier()); |
|
79
|
|
|
$this->assertSame('ALG', $metadata->getIdTokenEncryptedResponseAlg()); |
|
80
|
|
|
$this->assertSame('ENC', $metadata->getIdTokenEncryptedResponseEnc()); |
|
81
|
|
|
$this->assertSame('ALG', $metadata->getUserinfoSignedResponseAlg()); |
|
82
|
|
|
$this->assertSame('ALG', $metadata->getUserinfoEncryptedResponseAlg()); |
|
83
|
|
|
$this->assertSame('ENC', $metadata->getUserinfoEncryptedResponseEnc()); |
|
84
|
|
|
$this->assertSame('ALG', $metadata->getRequestObjectSigningAlg()); |
|
85
|
|
|
$this->assertSame('ALG', $metadata->getRequestObjectEncryptionAlg()); |
|
86
|
|
|
$this->assertSame('ENC', $metadata->getRequestObjectEncryptionEnc()); |
|
87
|
|
|
$this->assertSame('ALG', $metadata->getTokenEndpointAuthSigningAlg()); |
|
88
|
|
|
$this->assertEmpty($metadata->getDefaultAcrValues()); |
|
89
|
|
|
$this->assertSame($uris, $metadata->getRequestUris()); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function testSmarterMethods() |
|
93
|
|
|
{ |
|
94
|
|
|
$client = new Client(); |
|
95
|
|
|
$client->setId(123); |
|
96
|
|
|
$client->setRandomId('random'); |
|
97
|
|
|
$client->setSecret('my little secret'); |
|
98
|
|
|
$metadata = (new ClientMetadata()) |
|
99
|
|
|
->setClient($client) |
|
100
|
|
|
->setRedirectUris(['https://example.com']); |
|
101
|
|
|
|
|
102
|
|
|
$this->assertSame($client->getClientId(), $metadata->getClientId()); |
|
103
|
|
|
$this->assertSame($client->getClientSecret(), $metadata->getClientSecret()); |
|
104
|
|
|
$this->assertSame('example.com', $metadata->getSectorIdentifier()); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function testCreateFromClient() |
|
108
|
|
|
{ |
|
109
|
|
|
$client = new Client(); |
|
110
|
|
|
$client->setAllowedScopes(['grant1']); |
|
111
|
|
|
$client->setSiteUrl('https://example.com'); |
|
112
|
|
|
$client->setTermsOfUseUrl('https://example.com'); |
|
113
|
|
|
$client->setName('My Client'); |
|
114
|
|
|
$client->setRedirectUris(['https://example.com']); |
|
115
|
|
|
$client->setId('123'); |
|
116
|
|
|
$client->setRandomId('random_part'); |
|
117
|
|
|
$client->setSecret('my very secret key'); |
|
118
|
|
|
|
|
119
|
|
|
$metadata = (new ClientMetadata()) |
|
120
|
|
|
->fromClient($client); |
|
121
|
|
|
|
|
122
|
|
|
$this->assertSame($client->getAllowedGrantTypes(), $metadata->getGrantTypes()); |
|
123
|
|
|
$this->assertSame($client->getSiteUrl(), $metadata->getClientUri()); |
|
124
|
|
|
$this->assertSame($client->getTermsOfUseUrl(), $metadata->getTosUri()); |
|
125
|
|
|
$this->assertSame($client->getName(), $metadata->getClientName()); |
|
126
|
|
|
$this->assertSame($client->getRedirectUris(), $metadata->getRedirectUris()); |
|
127
|
|
|
$this->assertSame($client->getPublicId(), $metadata->getClientId()); |
|
128
|
|
|
$this->assertSame($client->getSecret(), $metadata->getClientSecret()); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function testToClient() |
|
132
|
|
|
{ |
|
133
|
|
|
$uri = 'https://example.com'; |
|
134
|
|
|
|
|
135
|
|
|
$metadata = (new ClientMetadata()) |
|
136
|
|
|
->setClientUri($uri) |
|
137
|
|
|
->setTosUri($uri) |
|
138
|
|
|
->setClientName('My Client') |
|
139
|
|
|
->setRedirectUris([$uri]); |
|
140
|
|
|
$metadata->checkDefaults(); |
|
141
|
|
|
|
|
142
|
|
|
$client = $metadata->toClient(); |
|
143
|
|
|
$this->assertSame($metadata->getGrantTypes(), $client->getAllowedGrantTypes()); |
|
144
|
|
|
$this->assertSame($metadata->getClientUri(), $client->getLandingPageUrl()); |
|
145
|
|
|
$this->assertSame($metadata->getClientUri(), $client->getSiteUrl()); |
|
146
|
|
|
$this->assertSame($metadata->getTosUri(), $client->getTermsOfUseUrl()); |
|
147
|
|
|
$this->assertSame('My Client', $client->getName()); |
|
148
|
|
|
$this->assertSame($metadata->getRedirectUris(), $client->getRedirectUris()); |
|
149
|
|
|
$this->assertFalse($client->isVisible()); |
|
150
|
|
|
$this->assertFalse($client->isPublished()); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function testUriCanonicalizer() |
|
154
|
|
|
{ |
|
155
|
|
|
$uri1 = 'https://example.com'; |
|
156
|
|
|
$uri2 = 'https://example.com/'; |
|
157
|
|
|
|
|
158
|
|
|
$this->assertSame('https://example.com/', ClientMetadata::canonicalizeUri($uri1)); |
|
159
|
|
|
$this->assertSame('https://example.com/', ClientMetadata::canonicalizeUri($uri2)); |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|