22
33declare (strict_types=1 );
44
5- namespace Tests \ Tempest \ Integration \Mapper ;
5+ namespace Integration \Route ;
66
77use Laminas \Diactoros \ServerRequest ;
88use Laminas \Diactoros \Stream ;
99use Laminas \Diactoros \UploadedFile ;
1010use Laminas \Diactoros \Uri ;
1111use Tempest \Cryptography \Encryption \Encrypter ;
12+ use Tempest \Http \Cookie \CookieManager ;
1213use Tempest \Http \GenericRequest ;
1314use Tempest \Http \Mappers \PsrRequestToGenericRequestMapper ;
14- use Tempest \Http \Method ;
1515use Tempest \Http \Request ;
1616use Tempest \Http \Upload ;
1717use Tests \Tempest \Integration \FrameworkIntegrationTestCase ;
1818
1919/**
2020 * @internal
2121 */
22- final class PsrRequestToRequestMapperTest extends FrameworkIntegrationTestCase
22+ final class PsrRequestToGenericRequestMapperTest extends FrameworkIntegrationTestCase
2323{
2424 private Encrypter $ encrypter {
2525 get => $ this ->container ->get (Encrypter::class);
2626 }
2727
28+ private CookieManager $ cookies {
29+ get => $ this ->container ->get (CookieManager::class);
30+ }
31+
32+ private PsrRequestToGenericRequestMapper $ mapper {
33+ get => new PsrRequestToGenericRequestMapper ($ this ->encrypter , $ this ->cookies );
34+ }
35+
2836 public function test_generic_request_is_used_when_interface_is_passed (): void
2937 {
30- $ mapper = new PsrRequestToGenericRequestMapper ($ this ->encrypter );
31-
32- $ request = $ mapper ->map (
38+ $ request = $ this ->mapper ->map (
3339 from: $ this ->http ->makePsrRequest ('/ ' ),
3440 to: Request::class,
3541 );
@@ -45,7 +51,7 @@ public function test_raw(): void
4551
4652 $ _COOKIE ['test ' ] = $ this ->encrypter ->encrypt ('cookie-value ' )->serialize ();
4753
48- $ request = new PsrRequestToGenericRequestMapper ( $ this ->encrypter ) ->map (new ServerRequest (
54+ $ request = $ this ->mapper ->map (new ServerRequest (
4955 uri: new Uri ('/json-endpoint ' ),
5056 method: 'POST ' ,
5157 body: $ stream ,
@@ -65,10 +71,8 @@ public function test_files(): void
6571
6672 copy (__DIR__ . '/Fixtures/upload.txt ' , $ currentPath );
6773
68- $ mapper = new PsrRequestToGenericRequestMapper ($ this ->encrypter );
69-
7074 /** @var GenericRequest $request */
71- $ request = $ mapper ->map (
75+ $ request = $ this -> mapper ->map (
7276 from: $ this ->http ->makePsrRequest ('/ ' , files: [new UploadedFile (
7377 streamOrFile: $ currentPath ,
7478 size: 1 ,
@@ -99,7 +103,7 @@ public function test_files(): void
99103
100104 public function test_body_field_in_body (): void
101105 {
102- $ request = new PsrRequestToGenericRequestMapper ( $ this ->encrypter ) ->map (
106+ $ request = $ this ->mapper ->map (
103107 from: $ this ->http ->makePsrRequest (
104108 uri: '/ ' ,
105109 body: [
@@ -111,4 +115,26 @@ public function test_body_field_in_body(): void
111115
112116 $ this ->assertSame (['body ' => 'text ' ], $ request ->body );
113117 }
118+
119+ public function test_unencrypted_cookies_are_discarded (): void
120+ {
121+ $ request = $ this ->mapper ->map (
122+ from: $ this ->http ->makePsrRequest (
123+ uri: '/ ' ,
124+ body: [
125+ 'body ' => 'text ' ,
126+ ],
127+ cookies: [
128+ 'foo ' => 'bar ' ,
129+ ],
130+ ),
131+ to: GenericRequest::class,
132+ );
133+
134+ $ this ->assertSame ([], $ request ->cookies );
135+
136+ $ cookies = $ this ->cookies ->all ();
137+ $ this ->assertSame ($ cookies ['foo ' ]->expiresAt , -1 );
138+ $ this ->assertSame ($ cookies ['foo ' ]->value , '' );
139+ }
114140}
0 commit comments