12
12
namespace Symfony \Component \HttpFoundation \Tests ;
13
13
14
14
use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Component \HttpFoundation \Exception \ExpiredSignedUriException ;
15
16
use Symfony \Component \HttpFoundation \Exception \LogicException ;
17
+ use Symfony \Component \HttpFoundation \Exception \UnSignedUriException ;
18
+ use Symfony \Component \HttpFoundation \Exception \UnverifiedSignedUriException ;
16
19
use Symfony \Component \HttpFoundation \Request ;
17
20
use Symfony \Component \HttpFoundation \UriSigner ;
18
21
@@ -204,4 +207,50 @@ public function testNonUrlSafeBase64()
204
207
$ signer = new UriSigner ('foobar ' );
205
208
$ this ->assertTrue ($ signer ->check ('http://example.com/foo?_hash=rIOcC%2FF3DoEGo%2FvnESjSp7uU9zA9S%2F%2BOLhxgMexoPUM%3D&baz=bay&foo=bar ' ));
206
209
}
210
+
211
+ public function testVerifyUnSignedUri ()
212
+ {
213
+ $ signer = new UriSigner ('foobar ' );
214
+ $ uri = 'http://example.com/foo ' ;
215
+
216
+ try {
217
+ $ signer ->verify ($ uri );
218
+
219
+ $ this ->fail ('Exception not thrown. ' );
220
+ } catch (UnSignedUriException $ e ) {
221
+ $ this ->assertSame ('The URI is not signed. ' , $ e ->getMessage ());
222
+ $ this ->assertSame ($ uri , $ e ->uri );
223
+ }
224
+ }
225
+
226
+ public function testVerifyUnverifiedUri ()
227
+ {
228
+ $ signer = new UriSigner ('foobar ' );
229
+ $ uri = 'http://example.com/foo?_hash=invalid ' ;
230
+
231
+ try {
232
+ $ signer ->verify ($ uri );
233
+
234
+ $ this ->fail ('Exception not thrown. ' );
235
+ } catch (UnverifiedSignedUriException $ e ) {
236
+ $ this ->assertSame ('The URI signature is invalid. ' , $ e ->getMessage ());
237
+ $ this ->assertSame ($ uri , $ e ->uri );
238
+ }
239
+ }
240
+
241
+ public function testVerifyExpiredUri ()
242
+ {
243
+ $ signer = new UriSigner ('foobar ' );
244
+ $ uri = $ signer ->sign ('http://example.com/foo ' , 123456 );
245
+
246
+ try {
247
+ $ signer ->verify ($ uri );
248
+
249
+ $ this ->fail ('Exception not thrown. ' );
250
+ } catch (ExpiredSignedUriException $ e ) {
251
+ $ this ->assertSame ('The URI has expired. ' , $ e ->getMessage ());
252
+ $ this ->assertSame ($ uri , $ e ->uri );
253
+ $ this ->assertSame (123456 , $ e ->expiredAt ->getTimestamp ());
254
+ }
255
+ }
207
256
}
0 commit comments