Skip to content

Fix #67 Fixed Cookie creation in cookie plugin. #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

Bouwdie
Copy link

@Bouwdie Bouwdie commented Mar 18, 2016

fix #67

Fix applied by calculating the expireIn (max-age) seconds instead of expire datetime.
Expanded save spec by using a more complete cookie.

Use DATE_COOKIE constant instead of DateTime constant.
Expand the cookie header content with all parts.

@Bouwdie
Copy link
Author

Bouwdie commented Mar 18, 2016

I am sort a new to php-spec 😄 Therefor i did not know how to assert values in the cookie object, since the cookiejar can not be mocked (final). Any suggestions?

@sagikazarmark
Copy link
Member

Thanks for the report and the PR. I will review this shortly.

'cookie=value; expires=%s; Max-Age=60; path=/; domain=test.com; secure; HttpOnly',
(new \DateTime())->add(
new \DateInterval('PT60S')
)->format(DATE_COOKIE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use \DateTime::COOKIE instead?

@dbu
Copy link
Contributor

dbu commented Mar 29, 2016

that indeed looks more robust to me. @sagikazarmark can you maybe help with phpspec / my fear of a test that will randomly fail?

@@ -109,11 +110,11 @@ private function createCookie(RequestInterface $request, $setCookie)

switch (strtolower($key)) {
case 'expires':
$expires = \DateTime::createFromFormat(DATE_COOKIE, $value);
$expires = \DateTime::createFromFormat(\DateTime::COOKIE, $value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the test failure on hhvm, i wonder if hhvm can't handle dates that far in the future?

which in turn leads me to think we should check the return value as \DateTime::createFromFormat is one of those stupid functions that returns false instead of throwing an exception on failure. if we check for false === $expires we can throw an exception and put the $value in the message to say it was not converted to a date.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what exception type would you like this to be? It probably needs to implement the name namespace exception interface. Can it be a TransferException? Or since there is a response a HttpException?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say it is not an HTTP related exception, so we should just fail with one of the SPL exceptions. UnexpectedValue maybe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i am not mistaken, HttpException is to express a HTTP error code. so it would be TransferException and we say that the server sent unexpected data.

looking at DateTime::COOKIE having "l, d-M-Y H:i:s T" and Y meaning 4 digit year, i have no idea what hhvm is doing here. but if it works for all versions with a two digit year lets go with that - its just mock data after all.

and lets add a test that triggers the exception, with a date value of "this is not a date" or something.

Copy link
Contributor

@dbu dbu Mar 31, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fine from my side.

@Bouwdie
Copy link
Author

Bouwdie commented Mar 31, 2016

Hmm hhvm does not seem to handle 4 digit year in cookie expires date.
https://3v4l.org/bmmjC

@dbu
Copy link
Contributor

dbu commented Mar 31, 2016 via email

@sagikazarmark
Copy link
Member

One last minor thing (Style CI) and ready to merge from my point of view.

@dbu
Copy link
Contributor

dbu commented Mar 31, 2016

👍 maybe also squash the commits.

@@ -86,6 +87,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
* @param $setCookie
*
* @return Cookie|null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the styleci complaint is here: we require a blank line between the @return and an @throws

Expand the cookie header content test with all parts.
Pass cookie parts as intended to cookie object.
Throw transfer exception when the cookie expires header can not be parsed.
@Bouwdie
Copy link
Author

Bouwdie commented Apr 3, 2016

Fixed and squashed 🎱

@sagikazarmark
Copy link
Member

Merged this manually because there were some conflicts.

@sagikazarmark
Copy link
Member

Thanks @Bouwdie

sagikazarmark added a commit to php-http/client-common that referenced this pull request Apr 3, 2016
sagikazarmark added a commit to php-http/client-common that referenced this pull request May 1, 2016
Update todo

Remove options resolver dependency

Revert: Remove options resolver dependency

Add AddHostPlugin

Add Authentication plugins

Add content length plugin

Add final warning to plugins

Add cookie plugin

Add decoder plugin

Add error plugin

Add header plugins

Add history plugin

Fix namespace import order

Add redirect plugin

Add retry plugin

Make plugin classes final, related #18

Fix throw keyword

Manually apply php-http/plugins#68

Manually apply and close php-http/plugins#65
sagikazarmark added a commit to php-http/client-common that referenced this pull request May 1, 2016
Update todo

Remove options resolver dependency

Revert: Remove options resolver dependency

Add AddHostPlugin

Add Authentication plugins

Add content length plugin

Add final warning to plugins

Add cookie plugin

Add decoder plugin

Add error plugin

Add header plugins

Add history plugin

Fix namespace import order

Add redirect plugin

Add retry plugin

Make plugin classes final, related #18

Fix throw keyword

Manually apply php-http/plugins#68

Manually apply and close php-http/plugins#65
sagikazarmark added a commit to php-http/client-common that referenced this pull request May 1, 2016
Update todo

Remove options resolver dependency

Revert: Remove options resolver dependency

Add AddHostPlugin

Add Authentication plugins

Add content length plugin

Add final warning to plugins

Add cookie plugin

Add decoder plugin

Add error plugin

Add header plugins

Add history plugin

Fix namespace import order

Add redirect plugin

Add retry plugin

Make plugin classes final, related #18

Fix throw keyword

Manually apply php-http/plugins#68

Manually apply and close php-http/plugins#65
sagikazarmark added a commit to php-http/client-common that referenced this pull request May 3, 2016
Update todo

Remove options resolver dependency

Revert: Remove options resolver dependency

Add AddHostPlugin

Add Authentication plugins

Add content length plugin

Add final warning to plugins

Add cookie plugin

Add decoder plugin

Add error plugin

Add header plugins

Add history plugin

Fix namespace import order

Add redirect plugin

Add retry plugin

Make plugin classes final, related #18

Fix throw keyword

Manually apply php-http/plugins#68

Manually apply and close php-http/plugins#65
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants