Skip to content

Commit

Permalink
Fix cookie transport to transmit path and domain when detaching
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Sep 13, 2019
1 parent 2b7ce58 commit 9d6641a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Sessions for the XP Framework ChangeLog
========================================================================

## 1.0.1 / 2019-09-13

* Fixed cookie transport to transmit path and domain when deleting the
cookie. See PR #9 for discussion.
(@thekid)

## 1.0.0 / 2019-08-23

* **Heads up:** The `Sessions::in($path)` and `Sessions::insecure()`
Expand Down
5 changes: 4 additions & 1 deletion src/main/php/web/session/Cookies.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public function attach($sessions, $response, $session) {
* @return void
*/
public function detach($sessions, $response, $session) {
$response->cookie(new Cookie($sessions->name(), null));
$response->cookie((new Cookie($sessions->name(), null))
->path($this->attributes['path'])
->domain($this->attributes['domain'])
);
}
}
26 changes: 26 additions & 0 deletions src/test/php/web/session/unittest/SessionsTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,32 @@ public function detach() {
$this->assertEquals([$sessions->name() => ''], [$cookie->name() => $cookie->value()]);
}

#[@test]
public function detach_uses_path() {
$sessions= $this->fixture()->via((new Cookies())->path('/testing'));
$response= $this->response();

$session= $sessions->create();
$session->destroy();
$session->transmit($response);

$cookie= $response->cookies()[0];
$this->assertEquals('/testing', $cookie->attributes()['path']);
}

#[@test]
public function detach_uses_domain() {
$sessions= $this->fixture()->via((new Cookies())->domain('example.org'));
$response= $this->response();

$session= $sessions->create();
$session->destroy();
$session->transmit($response);

$cookie= $response->cookies()[0];
$this->assertEquals('example.org', $cookie->attributes()['domain']);
}

#[@test]
public function valid() {
$session= $this->fixture()->create();
Expand Down

0 comments on commit 9d6641a

Please sign in to comment.