Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Conversation

@Ragazzo
Copy link

@Ragazzo Ragazzo commented May 30, 2015

@Martin-P
Copy link
Contributor

Just as a reminder: please add unittests.

@Ragazzo
Copy link
Author

Ragazzo commented Jun 14, 2015

Afaik, empty expires means that cookie is only for current user session after which it should be deleted. Need to review if this fix is correct according this statetment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the actual test if the expires is null? You are now testing nothing.

Copy link
Author

Choose a reason for hiding this comment

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

i test condition if expires is empty string, remove fix to code and exception will be thrown

Copy link
Author

Choose a reason for hiding this comment

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

or you are referring to missing ->isNull on getExpires ?

Copy link
Contributor

Choose a reason for hiding this comment

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

There is no assertion, so nothing is tested. You can use a try/catch block to test if an exception is thrown. Also please update the method name so it reflects what you are actually testing.

You can do it like this:

public function testEmptyExpiresDoesNotThrowException()
{
    $cookieString = 'Set-Cookie:path=/; Expires=; HttpOnly;';

    try {
        SetCookie::fromString($cookie);
        $this->pass('No exception was thrown for empty "expires" value');
    } catch (\Exception $exception) {
        $this->fail('Empty "expires" value should not throw an exception');
    }   
}

Copy link
Author

Choose a reason for hiding this comment

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

dont need to add try catch, you can use @expectedException, overall i will only update code with assertIsNull, your fix is not correct. Tests should not always have assertions, if test has passed without exceptions than it is ok, pass or fail

Copy link
Contributor

Choose a reason for hiding this comment

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

you can use @expectedException

If you expect an exception you can use that, but in this case you expecting the opposite: no exception. You can not use annotations for that, because there is none for "not expecting an exception".

Tests should not always have assertions, if test has passed without exceptions than it is ok, pass or fail

I agree it is not mandatory, but IMO it is better to be explicit when testing.

Copy link
Member

Choose a reason for hiding this comment

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

Please assert getExpires returns the correct value.

Copy link
Author

Choose a reason for hiding this comment

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

Ok

Copy link
Contributor

Choose a reason for hiding this comment

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

Please assert getExpires returns the correct value.

I think that is a test on its own. One test to see there is no exception thrown and another test to see if getExpires returns null.

@Ragazzo
Copy link
Author

Ragazzo commented Jun 15, 2015

@Maks3w done, ready for review

Copy link
Member

Choose a reason for hiding this comment

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

Should 0 to be handle as null too?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, it seems 0 is not allowed. See: zendframework/zendframework#4684 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

@Martin-P that thread is about Expires HEADER

If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).
http://php.net/manual/en/function.setcookie.php

Copy link
Author

Choose a reason for hiding this comment

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

not sure, i've read rfc, but it is still unclear for me about this situation http://tools.ietf.org/html/rfc6265#section-4.1.2.1

yet, without this fix exception will be thrown that does not feel right

Copy link
Contributor

Choose a reason for hiding this comment

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

@Maks3w I know, but a cookie is just a header. Also the class name confirms this: Zend\Http\Header\SetCookie.

Edit: The PHP function setcookie is not used in this class, so I doubt if that applies here.

Copy link
Member

Choose a reason for hiding this comment

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

@Martin-P Expires header and Set-Cookie headers are defined by different rules.

It's wrong assume a constraint for Proxy header affects to Authorization header. The same is applicable for Expires and Set-Cookie

@Martin-P
Copy link
Contributor

@Ragazzo Can you provide a link to the specifications where empty expires is mentioned?

@Ragazzo
Copy link
Author

Ragazzo commented Jun 15, 2015

@Martin-P do let me know if other things need to be done, as for rfc as i said i am not sure about correct behavior in this case, but throwing exception on valid header attribute does not sound right too

@weierophinney
Copy link
Member

@Ragazzo — per @Martin-P , can you provide the link to the expires specification in the Cookie header RFC so (a) others coming to the issue know where to look, and (b) we can validate the behavior is correct per the RFC?

@Ragazzo
Copy link
Author

Ragazzo commented Aug 6, 2015

@weierophinney updated description, yet as i said it is still unclean for me about this situation in RFC

ezimuel pushed a commit to ezimuel/zend-http that referenced this pull request Aug 4, 2016
@ezimuel
Copy link
Contributor

ezimuel commented Jan 17, 2017

I close this PR due to inactivity.

@ezimuel ezimuel closed this Jan 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants