1
1
<?php
2
+
2
3
/**
3
4
* The MIT License (MIT)
4
5
* Copyright (c) 2022 Redbit s.r.o., Jakub Bouček
6
+ *
7
+ * @noinspection PhpUnused
5
8
* @testCase
6
9
*/
7
10
14
17
use Redbitcz \DebugMode \Plugin \SignedUrl ;
15
18
use Redbitcz \DebugMode \Plugin \SignedUrlVerificationException ;
16
19
use Tester \Assert ;
20
+ use Tester \TestCase ;
17
21
18
22
require __DIR__ . '/../bootstrap.php ' ;
19
23
20
- class SignUrlTest extends \ Tester \ TestCase
24
+ class SignUrlTest extends TestCase
21
25
{
22
26
private const KEY_HS256 = "zhYiojmp7O3VYQNuW0C5rS0VgFNgoAvuxW4IdS/0tn8 " ;
23
27
@@ -148,18 +152,18 @@ public function testVerifyRequest(): void
148
152
Assert::equal ($ expected , $ parsed );
149
153
}
150
154
151
- public function testSignInvalidUrl ()
155
+ public function testSignInvalidUrl (): void
152
156
{
153
- Assert::exception (function () {
157
+ Assert::exception (static function () {
154
158
$ url = (string )base64_decode ('Ly8Eijrg+qawZw== ' );
155
159
$ plugin = new SignedUrl (self ::KEY_HS256 , 'HS256 ' );
156
160
$ plugin ->signUrl ($ url , 1600000600 );
157
161
}, LogicException::class);
158
162
}
159
163
160
- public function testSignRelativeUrl ()
164
+ public function testSignRelativeUrl (): void
161
165
{
162
- Assert::exception (function () {
166
+ Assert::exception (static function () {
163
167
$ url = '/login?email=foo@bar.cz ' ;
164
168
$ plugin = new SignedUrl (self ::KEY_HS256 , 'HS256 ' );
165
169
$ plugin ->signUrl ($ url , 1600000600 );
@@ -179,23 +183,23 @@ public function testVerifyPostRequest(): void
179
183
$ plugin = new SignedUrl (self ::KEY_HS256 , 'HS256 ' , $ audience );
180
184
$ plugin ->setTimestamp ($ timestamp );
181
185
JWT ::$ timestamp = $ timestamp ;
182
- Assert::exception (function () use ($ plugin , $ tokenUrl ) {
186
+ Assert::exception (static function () use ($ plugin , $ tokenUrl ) {
183
187
$ plugin ->verifyRequest (false , $ tokenUrl , 'POST ' );
184
188
}, SignedUrlVerificationException::class, 'HTTP method doesn \'t match signed HTTP method ' );
185
189
}
186
190
187
191
public function testVerifyInvalidRequest (): void
188
192
{
189
- Assert::exception (function () {
193
+ Assert::exception (static function () {
190
194
$ plugin = new SignedUrl (self ::KEY_HS256 , 'HS256 ' );
191
195
$ url = (string )base64_decode ('Ly8Eijrg+qawZw== ' );
192
196
$ plugin ->verifyRequest (false , $ url , 'GET ' );
193
197
}, SignedUrlVerificationException::class, 'Url is invalid ' );
194
198
}
195
199
196
- public function testVerifyInvalidUrl ()
200
+ public function testVerifyInvalidUrl (): void
197
201
{
198
- Assert::exception (function () {
202
+ Assert::exception (static function () {
199
203
$ plugin = new SignedUrl (self ::KEY_HS256 , 'HS256 ' );
200
204
$ plugin ->verifyUrl ('https://host.tld/path?query=value ' );
201
205
}, SignedUrlVerificationException::class, 'No token in URL ' );
@@ -213,7 +217,7 @@ public function testVerifyUrlWithSuffix(): void
213
217
$ tokenUrl .= '&fbclid=123456789 ' ;
214
218
215
219
Assert::exception (
216
- function () use ($ timestamp , $ tokenUrl ) {
220
+ static function () use ($ timestamp , $ tokenUrl ) {
217
221
$ plugin = new SignedUrl (self ::KEY_HS256 , 'HS256 ' );
218
222
$ plugin ->setTimestamp ($ timestamp );
219
223
JWT ::$ timestamp = $ timestamp ;
0 commit comments