Failed Conditions
Pull Request — master (#18)
by Florent
04:44
created

noClientUpdatedEventShouldBeRecorded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 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\Component\Server\Tests\Context;
15
16
use Assert\Assertion;
17
use Behat\Behat\Context\Context;
18
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
19
use OAuth2Framework\Component\Server\Model\Client\Client;
20
use OAuth2Framework\Component\Server\Model\Client\ClientId;
21
use OAuth2Framework\Component\Server\Model\DataBag\DataBag;
22
use OAuth2Framework\Component\Server\Model\UserAccount\UserAccountId;
23
24
/**
25
 * Defines application features from the specific context.
26
 */
27
final class ClientContext implements Context
28
{
29
    /**
30
     * @var null|array
31
     */
32
    private $client = null;
33
34
    /**
35
     * @var ResponseContext
36
     */
37
    private $responseContext;
38
39
    /**
40
     * @var ApplicationContext
41
     */
42
    private $applicationContext;
43
44
    /**
45
     * @BeforeScenario
46
     *
47
     * @param BeforeScenarioScope $scope
48
     */
49
    public function gatherContexts(BeforeScenarioScope $scope)
50
    {
51
        $environment = $scope->getEnvironment();
52
53
        $this->responseContext = $environment->getContext(ResponseContext::class);
54
        $this->applicationContext = $environment->getContext(ApplicationContext::class);
55
    }
56
57
    /**
58
     * @Given a valid client registration request is received
59
     */
60
    public function aValidClientRegistrationRequestIsReceived()
61
    {
62
        $request = $this->applicationContext->getServerRequestFactory()->createServerRequest([]);
63
        $request = $request->withMethod('POST');
64
        $request = $request->withParsedBody([
65
            'redirect_uris'              => ['https://www.foo.com'],
66
            'token_endpoint_auth_method' => 'client_secret_basic',
67
        ]);
68
        $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
69
        $request = $request->withHeader('Authorization', 'Bearer INITIAL_ACCESS_TOKEN_VALID');
70
71
        $this->responseContext->setResponse($this->applicationContext->getApplication()->getClientRegistrationPipe()->dispatch($request));
72
    }
73
74
    /**
75
     * @Given a client registration request is received with an expired initial access token
76
     */
77
    public function aClientRegistrationRequestIsReceivedWithAnExpiredInitialAccessToken()
78
    {
79
        $request = $this->applicationContext->getServerRequestFactory()->createServerRequest([]);
80
        $request = $request->withMethod('POST');
81
        $request = $request->withParsedBody([
82
            'redirect_uris' => ['https://www.foo.com'],
83
        ]);
84
        $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
85
        $request = $request->withHeader('Authorization', 'Bearer INITIAL_ACCESS_TOKEN_EXPIRED');
86
87
        $this->responseContext->setResponse($this->applicationContext->getApplication()->getClientRegistrationPipe()->dispatch($request));
88
    }
89
90
    /**
91
     * @Given a client registration request is received with a revoked initial access token
92
     */
93
    public function aClientRegistrationRequestIsReceivedWithARevokedInitialAccessToken()
94
    {
95
        $request = $this->applicationContext->getServerRequestFactory()->createServerRequest([]);
96
        $request = $request->withMethod('POST');
97
        $request = $request->withParsedBody([
98
            'redirect_uris' => ['https://www.foo.com'],
99
        ]);
100
        $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
101
        $request = $request->withHeader('Authorization', 'Bearer INITIAL_ACCESS_TOKEN_REVOKED');
102
103
        $this->responseContext->setResponse($this->applicationContext->getApplication()->getClientRegistrationPipe()->dispatch($request));
104
    }
105
106
    /**
107
     * @Given a client registration request is received but not initial access token is set
108
     */
109
    public function aClientRegistrationRequestIsReceivedButNotInitialAccessTokenIsSet()
110
    {
111
        $request = $this->applicationContext->getServerRequestFactory()->createServerRequest([]);
112
        $request = $request->withMethod('POST');
113
        $request = $request->withParsedBody([
114
            'redirect_uris' => ['https://www.foo.com'],
115
        ]);
116
        $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
117
118
        $this->responseContext->setResponse($this->applicationContext->getApplication()->getClientRegistrationPipe()->dispatch($request));
119
    }
120
121
    /**
122
     * @Given a client registration request is received but an invalid initial access token is set
123
     */
124
    public function aClientRegistrationRequestIsReceivedButAnInvalidInitialAccessTokenIsSet()
125
    {
126
        $request = $this->applicationContext->getServerRequestFactory()->createServerRequest([]);
127
        $request = $request->withMethod('POST');
128
        $request = $request->withParsedBody([
129
            'redirect_uris' => ['https://www.foo.com'],
130
        ]);
131
        $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
132
        $request = $request->withHeader('Authorization', 'Bearer ***INVALID_INITIAL_ACCESS_TOKEN***');
133
134
        $this->responseContext->setResponse($this->applicationContext->getApplication()->getClientRegistrationPipe()->dispatch($request));
135
    }
136
137
    /**
138
     * @Given a valid client registration request with software statement is received
139
     */
140
    public function aValidClientRegistrationRequestWithSoftwareStatementIsReceived()
141
    {
142
        $request = $this->applicationContext->getServerRequestFactory()->createServerRequest([]);
143
        $request = $request->withMethod('POST');
144
        $request = $request->withParsedBody([
145
            'redirect_uris'              => ['https://www.foo.com'],
146
            'token_endpoint_auth_method' => 'client_secret_basic',
147
            'software_statement'         => $this->createSoftwareStatement(),
148
        ]);
149
        $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
150
        $request = $request->withHeader('Authorization', 'Bearer INITIAL_ACCESS_TOKEN_VALID');
151
152
        $this->responseContext->setResponse($this->applicationContext->getApplication()->getClientRegistrationPipe()->dispatch($request));
153
    }
154
155
    /**
156
     * @Given a valid client configuration GET request is received
157
     */
158
    public function aValidClientConfigurationGetRequestIsReceived()
159
    {
160
        $request = $this->applicationContext->getServerRequestFactory()->createServerRequest([]);
161
        $request = $request->withMethod('GET');
162
        $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
163
        $request = $request->withHeader('Authorization', 'Bearer JNWuIxHkTKtUmmtEpipDtPlTc3ordUNpSVVPLbQXKrFKyYVDR7N3k1ZzrHmPWXoibr2J2HrTSSozN6zIhHuypA');
164
        $client = Client::createEmpty();
165
        $client = $client->create(
166
            ClientId::create('79b407fb-acc0-4880-ab98-254062c214ce'),
167
            DataBag::createFromArray([
168
                'registration_access_token' => 'JNWuIxHkTKtUmmtEpipDtPlTc3ordUNpSVVPLbQXKrFKyYVDR7N3k1ZzrHmPWXoibr2J2HrTSSozN6zIhHuypA',
169
                'grant_types'               => [],
170
                'response_types'            => [],
171
                'redirect_uris'             => ['https://www.foo.com'],
172
                'software_statement'        => 'eyJhbGciOiJFUzI1NiJ9.eyJzb2Z0d2FyZV92ZXJzaW9uIjoiMS4wIiwic29mdHdhcmVfbmFtZSI6Ik15IGFwcGxpY2F0aW9uIiwic29mdHdhcmVfbmFtZSNlbiI6Ik15IGFwcGxpY2F0aW9uIiwic29mdHdhcmVfbmFtZSNmciI6Ik1vbiBhcHBsaWNhdGlvbiJ9.88m8-YyguCCx1QNChwfNnMZ9APKpNC--nnfB1rVBpAYyHLixtsyMuuI09svqxuiRfTxwgXuRUvsg_5RozmtusQ',
173
                'software_version'          => '1.0',
174
                'software_name'             => 'My application',
175
                'software_name#en'          => 'My application',
176
                'software_name#fr'          => 'Mon application',
177
                'registration_client_uri'   => 'https://www.config.example.com/client/79b407fb-acc0-4880-ab98-254062c214ce',
178
                'client_id_issued_at'       => 1482177703,
179
            ]),
180
            UserAccountId::create('john.1')
181
        );
182
        $request = $request->withAttribute('client', $client);
183
184
        $this->responseContext->setResponse($this->applicationContext->getApplication()->getClientConfigurationPipe()->dispatch($request));
185
    }
186
187
    /**
188
     * @Given a client configuration GET request is received but no Registration Token is set
189
     */
190
    public function aClientConfigurationGetRequestIsReceivedButNoRegistrationTokenIsSet()
191
    {
192
        $request = $this->applicationContext->getServerRequestFactory()->createServerRequest([]);
193
        $request = $request->withMethod('GET');
194
        $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
195
        $client = Client::createEmpty();
196
        $client = $client->create(
197
            ClientId::create('79b407fb-acc0-4880-ab98-254062c214ce'),
198
            DataBag::createFromArray([
199
                'registration_access_token' => 'JNWuIxHkTKtUmmtEpipDtPlTc3ordUNpSVVPLbQXKrFKyYVDR7N3k1ZzrHmPWXoibr2J2HrTSSozN6zIhHuypA',
200
                'grant_types'               => [],
201
                'response_types'            => [],
202
                'redirect_uris'             => ['https://www.foo.com'],
203
                'software_statement'        => 'eyJhbGciOiJFUzI1NiJ9.eyJzb2Z0d2FyZV92ZXJzaW9uIjoiMS4wIiwic29mdHdhcmVfbmFtZSI6Ik15IGFwcGxpY2F0aW9uIiwic29mdHdhcmVfbmFtZSNlbiI6Ik15IGFwcGxpY2F0aW9uIiwic29mdHdhcmVfbmFtZSNmciI6Ik1vbiBhcHBsaWNhdGlvbiJ9.88m8-YyguCCx1QNChwfNnMZ9APKpNC--nnfB1rVBpAYyHLixtsyMuuI09svqxuiRfTxwgXuRUvsg_5RozmtusQ',
204
                'software_version'          => '1.0',
205
                'software_name'             => 'My application',
206
                'software_name#en'          => 'My application',
207
                'software_name#fr'          => 'Mon application',
208
                'registration_client_uri'   => 'https://www.config.example.com/client/79b407fb-acc0-4880-ab98-254062c214ce',
209
                'client_id_issued_at'       => 1482177703,
210
            ]),
211
            UserAccountId::create('john.1')
212
        );
213
        $request = $request->withAttribute('client', $client);
214
215
        $this->responseContext->setResponse($this->applicationContext->getApplication()->getClientConfigurationPipe()->dispatch($request));
216
    }
217
218
    /**
219
     * @Given a client configuration GET request is received but the Registration Token is invalid
220
     */
221
    public function aClientConfigurationGetRequestIsReceivedButTheRegistrationTokenIsInvalid()
222
    {
223
        $request = $this->applicationContext->getServerRequestFactory()->createServerRequest([]);
224
        $request = $request->withMethod('GET');
225
        $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
226
        $request = $request->withHeader('Authorization', 'Bearer InvALID_ToKEn');
227
        $client = Client::createEmpty();
228
        $client = $client->create(
229
            ClientId::create('79b407fb-acc0-4880-ab98-254062c214ce'),
230
            DataBag::createFromArray([
231
                'registration_access_token' => 'JNWuIxHkTKtUmmtEpipDtPlTc3ordUNpSVVPLbQXKrFKyYVDR7N3k1ZzrHmPWXoibr2J2HrTSSozN6zIhHuypA',
232
                'grant_types'               => [],
233
                'response_types'            => [],
234
                'redirect_uris'             => ['https://www.foo.com'],
235
                'software_statement'        => 'eyJhbGciOiJFUzI1NiJ9.eyJzb2Z0d2FyZV92ZXJzaW9uIjoiMS4wIiwic29mdHdhcmVfbmFtZSI6Ik15IGFwcGxpY2F0aW9uIiwic29mdHdhcmVfbmFtZSNlbiI6Ik15IGFwcGxpY2F0aW9uIiwic29mdHdhcmVfbmFtZSNmciI6Ik1vbiBhcHBsaWNhdGlvbiJ9.88m8-YyguCCx1QNChwfNnMZ9APKpNC--nnfB1rVBpAYyHLixtsyMuuI09svqxuiRfTxwgXuRUvsg_5RozmtusQ',
236
                'software_version'          => '1.0',
237
                'software_name'             => 'My application',
238
                'software_name#en'          => 'My application',
239
                'software_name#fr'          => 'Mon application',
240
                'registration_client_uri'   => 'https://www.config.example.com/client/79b407fb-acc0-4880-ab98-254062c214ce',
241
                'client_id_issued_at'       => 1482177703,
242
            ]),
243
            UserAccountId::create('john.1')
244
        );
245
        $request = $request->withAttribute('client', $client);
246
247
        $this->responseContext->setResponse($this->applicationContext->getApplication()->getClientConfigurationPipe()->dispatch($request));
248
    }
249
250
    /**
251
     * @Given a valid client configuration DELETE request is received
252
     */
253
    public function aValidClientConfigurationDeleteRequestIsReceived()
254
    {
255
        $request = $this->applicationContext->getServerRequestFactory()->createServerRequest([]);
256
        $request = $request->withMethod('DELETE');
257
        $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
258
        $request = $request->withHeader('Authorization', 'Bearer JNWuIxHkTKtUmmtEpipDtPlTc3ordUNpSVVPLbQXKrFKyYVDR7N3k1ZzrHmPWXoibr2J2HrTSSozN6zIhHuypA');
259
        $client = $this->applicationContext->getApplication()->getClientRepository()->find(ClientId::create('79b407fb-acc0-4880-ab98-254062c214ce'));
260
        $request = $request->withAttribute('client', $client);
261
262
        $this->responseContext->setResponse($this->applicationContext->getApplication()->getClientConfigurationPipe()->dispatch($request));
263
    }
264
265
    /**
266
     * @Given a client configuration DELETE request is received but no Registration Token is set
267
     */
268
    public function aClientConfigurationDeleteRequestIsReceivedButNoRegistrationTokenIsSet()
269
    {
270
        $request = $this->applicationContext->getServerRequestFactory()->createServerRequest([]);
271
        $request = $request->withMethod('DELETE');
272
        $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
273
        $client = $this->applicationContext->getApplication()->getClientRepository()->find(ClientId::create('79b407fb-acc0-4880-ab98-254062c214ce'));
274
        $request = $request->withAttribute('client', $client);
275
276
        $this->responseContext->setResponse($this->applicationContext->getApplication()->getClientConfigurationPipe()->dispatch($request));
277
    }
278
279
    /**
280
     * @Given a client configuration PUT request is received but no Registration Token is set
281
     */
282
    public function aClientConfigurationPutRequestIsReceivedButNoRegistrationTokenIsSet()
283
    {
284
        $request = $this->applicationContext->getServerRequestFactory()->createServerRequest([]);
285
        $request = $request->withMethod('PUT');
286
        $request = $request->withParsedBody([
287
            'redirect_uris' => ['https://www.foo.com'],
288
        ]);
289
        $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
290
        $client = $this->applicationContext->getApplication()->getClientRepository()->find(ClientId::create('79b407fb-acc0-4880-ab98-254062c214ce'));
291
        $request = $request->withAttribute('client', $client);
292
293
        $this->responseContext->setResponse($this->applicationContext->getApplication()->getClientConfigurationPipe()->dispatch($request));
294
    }
295
296
    /**
297
     * @Given a valid client configuration PUT request is received
298
     */
299
    public function aValidClientConfigurationPutRequestIsReceived()
300
    {
301
        $request = $this->applicationContext->getServerRequestFactory()->createServerRequest([]);
302
        $request = $request->withMethod('PUT');
303
        $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
304
        $request = $request->withParsedBody([
305
            'redirect_uris'              => ['https://www.bar.com'],
306
            'token_endpoint_auth_method' => 'client_secret_basic',
307
        ]);
308
        $request = $request->withHeader('Authorization', 'Bearer JNWuIxHkTKtUmmtEpipDtPlTc3ordUNpSVVPLbQXKrFKyYVDR7N3k1ZzrHmPWXoibr2J2HrTSSozN6zIhHuypA');
309
        $client = $this->applicationContext->getApplication()->getClientRepository()->find(ClientId::create('79b407fb-acc0-4880-ab98-254062c214ce'));
310
        $request = $request->withAttribute('client', $client);
311
312
        $this->responseContext->setResponse($this->applicationContext->getApplication()->getClientConfigurationPipe()->dispatch($request));
313
    }
314
315
    /**
316
     * @Given the response contains the updated client
317
     */
318
    public function theResponseContainsTheUpdatedClient()
319
    {
320
        $response = (string) $this->responseContext->getResponse()->getBody()->getContents();
321
        $json = json_decode($response, true);
322
        Assertion::isArray($json);
323
        Assertion::keyExists($json, 'client_id');
324
        $this->client = $json;
325
    }
326
327
    /**
328
     * @Given a valid client configuration PUT request with software statement is received
329
     */
330
    public function aValidClientConfigurationPutRequestWithSoftwareStatementIsReceived()
331
    {
332
        $request = $this->applicationContext->getServerRequestFactory()->createServerRequest([]);
333
        $request = $request->withMethod('PUT');
334
        $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
335
        $request = $request->withParsedBody([
336
            'redirect_uris'              => ['https://www.bar.com'],
337
            'token_endpoint_auth_method' => 'client_secret_basic',
338
            'software_statement'         => $this->createSoftwareStatement(),
339
        ]);
340
        $request = $request->withHeader('Authorization', 'Bearer JNWuIxHkTKtUmmtEpipDtPlTc3ordUNpSVVPLbQXKrFKyYVDR7N3k1ZzrHmPWXoibr2J2HrTSSozN6zIhHuypA');
341
        $client = Client::createEmpty();
342
        $client = $client->create(
343
            ClientId::create('79b407fb-acc0-4880-ab98-254062c214ce'),
344
            DataBag::createFromArray([
345
                'registration_access_token' => 'JNWuIxHkTKtUmmtEpipDtPlTc3ordUNpSVVPLbQXKrFKyYVDR7N3k1ZzrHmPWXoibr2J2HrTSSozN6zIhHuypA',
346
                'grant_types'               => [],
347
                'response_types'            => [],
348
                'redirect_uris'             => ['https://www.foo.com'],
349
                'registration_client_uri'   => 'https://www.config.example.com/client/79b407fb-acc0-4880-ab98-254062c214ce',
350
                'client_id_issued_at'       => 1482177703,
351
            ]),
352
            UserAccountId::create('john.1')
353
        );
354
        $this->applicationContext->getApplication()->getClientRepository()->save($client);
355
        $request = $request->withAttribute('client', $client);
356
357
        $this->responseContext->setResponse($this->applicationContext->getApplication()->getClientConfigurationPipe()->dispatch($request));
358
    }
359
360
    /**
361
     * @Given a valid client configuration PUT request with software statement is received but the algorithm is not supported
362
     */
363
    public function aValidClientConfigurationPutRequestWithSoftwareStatementIsReceivedButTheAlgorithmIsNotSupported()
364
    {
365
        $request = $this->applicationContext->getServerRequestFactory()->createServerRequest([]);
366
        $request = $request->withMethod('PUT');
367
        $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded');
368
        $request = $request->withParsedBody([
369
            'redirect_uris'              => ['https://www.bar.com'],
370
            'token_endpoint_auth_method' => 'client_secret_basic',
371
            'software_statement'         => $this->createInvalidSoftwareStatement(),
372
        ]);
373
        $request = $request->withHeader('Authorization', 'Bearer JNWuIxHkTKtUmmtEpipDtPlTc3ordUNpSVVPLbQXKrFKyYVDR7N3k1ZzrHmPWXoibr2J2HrTSSozN6zIhHuypA');
374
        $client = Client::createEmpty();
375
        $client = $client->create(
376
            ClientId::create('79b407fb-acc0-4880-ab98-254062c214ce'),
377
            DataBag::createFromArray([
378
                'registration_access_token' => 'JNWuIxHkTKtUmmtEpipDtPlTc3ordUNpSVVPLbQXKrFKyYVDR7N3k1ZzrHmPWXoibr2J2HrTSSozN6zIhHuypA',
379
                'grant_types'               => [],
380
                'response_types'            => [],
381
                'redirect_uris'             => ['https://www.foo.com'],
382
                'registration_client_uri'   => 'https://www.config.example.com/client/79b407fb-acc0-4880-ab98-254062c214ce',
383
                'client_id_issued_at'       => 1482177703,
384
            ]),
385
            UserAccountId::create('john.1')
386
        );
387
        $this->applicationContext->getApplication()->getClientRepository()->save($client);
388
        $request = $request->withAttribute('client', $client);
389
390
        $this->responseContext->setResponse($this->applicationContext->getApplication()->getClientConfigurationPipe()->dispatch($request));
391
    }
392
393
    /**
394
     * @Then a client deleted event should be recorded
395
     */
396
    public function aClientDeletedEventShouldBeRecorded()
397
    {
398
        $events = $this->applicationContext->getApplication()->getClientDeletedEventHandler()->getEvents();
399
        Assertion::eq(1, count($events));
400
    }
401
402
    /**
403
     * @Then no client deleted event should be recorded
404
     */
405
    public function noClientDeletedEventShouldBeRecorded()
406
    {
407
        $events = $this->applicationContext->getApplication()->getClientDeletedEventHandler()->getEvents();
408
        Assertion::eq(0, count($events));
409
    }
410
411
    /**
412
     * @Then no client updated event should be recorded
413
     */
414
    public function noClientUpdatedEventShouldBeRecorded()
415
    {
416
        $events = $this->applicationContext->getApplication()->getClientUpdatedEventHandler()->getEvents();
417
        Assertion::eq(0, count($events));
418
    }
419
420
    /**
421
     * @Then a client created event should be recorded
422
     */
423
    public function aClientCreatedEventShouldBeRecorded()
424
    {
425
        $events = $this->applicationContext->getApplication()->getClientCreatedEventHandler()->getEvents();
426
        Assertion::eq(1, count($events));
427
    }
428
429
    /**
430
     * @Then a client updated event should be recorded
431
     */
432
    public function aClientUpdatedEventShouldBeRecorded()
433
    {
434
        $events = $this->applicationContext->getApplication()->getClientUpdatedEventHandler()->getEvents();
435
        Assertion::eq(1, count($events));
436
    }
437
438
    /**
439
     * @Then the response contains a client
440
     */
441
    public function theResponseContainsAClient()
442
    {
443
        $response = $this->responseContext->getResponse()->getBody()->getContents();
444
        $json = json_decode($response, true);
445
        Assertion::isArray($json);
446
        Assertion::keyExists($json, 'client_id');
447
        $this->client = $json;
448
    }
449
450
    /**
451
     * @Then no client should be created
452
     */
453
    public function noClientShouldBeCreated()
454
    {
455
        $events = $this->applicationContext->getApplication()->getClientCreatedEventHandler()->getEvents();
456
        Assertion::eq(0, count($events));
457
    }
458
459
    /**
460
     * @Then the software statement parameters are in the client parameters
461
     */
462
    public function theSoftwareStatementParametersAreInTheClientParameters()
463
    {
464
        Assertion::keyExists($this->client, 'software_statement');
465
        Assertion::keyExists($this->client, 'software_version');
466
        Assertion::keyExists($this->client, 'software_name');
467
        Assertion::keyExists($this->client, 'software_name#en');
468
        Assertion::keyExists($this->client, 'software_name#fr');
469
        Assertion::eq($this->client['software_version'], '1.0');
470
        Assertion::eq($this->client['software_name'], 'My application');
471
        Assertion::eq($this->client['software_name#en'], 'My application');
472
        Assertion::eq($this->client['software_name#fr'], 'Mon application');
473
    }
474
475
    /**
476
     * @return string
477
     */
478
    private function createSoftwareStatement(): string
479
    {
480
        $claims = [
481
            'software_version' => '1.0',
482
            'software_name'    => 'My application',
483
            'software_name#en' => 'My application',
484
            'software_name#fr' => 'Mon application',
485
        ];
486
        $headers = [
487
            'alg' => 'ES256',
488
        ];
489
        $key = $this->applicationContext->getApplication()->getPrivateKeys()->getKey(0);
490
491
        return $this->applicationContext->getApplication()->getJwTCreator()->sign($claims, $headers, $key);
492
    }
493
494
    /**
495
     * @return string
496
     */
497
    private function createInvalidSoftwareStatement(): string
498
    {
499
        $claims = [
500
            'software_version' => '1.0',
501
            'software_name'    => 'My application',
502
            'software_name#en' => 'My application',
503
            'software_name#fr' => 'Mon application',
504
        ];
505
        $headers = [
506
            'alg' => 'none',
507
        ];
508
        $key = \Jose\Factory\JWKFactory::createNoneKey([]);
509
510
        return $this->applicationContext->getApplication()->getJwTCreator()->sign($claims, $headers, $key);
511
    }
512
}
513