Skip to content
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

Cookie\Jar: add input validation #610

Merged
merged 3 commits into from
Nov 15, 2021

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Nov 14, 2021

Cookie\Jar: move tests to dedicated file

The tests for the Cookie\Jar class were up to now mixed in with the tests for the Cookie class.

This moves the Jar tests to a dedicated test file.

The actual test code has not been touched.

This includes duplicating a helper method. At a later point in time when these tests are reviewed, it can be decided whether this helper should move to the TestCase.

Cookie\Jar::__construct(): add input validation

As array_merge() is used on the $cookies property in the before_redirect_check() method, only arrays can be accepted.

Includes test.

Cookie\Jar::normalize_cookie(): fix default value of $key

The $key parameter corresponds to the $name parameter in the Cookie::parse() method, which expects a string and has a default value of ''.

This fixes the default value of the $key parameter to be the same, i.e. an empty string.


Regarding the other public methods:

  • The public magic/ArrayIterator methods should not need input validation as they should not be called directly, but only indirectly and when called that way, will receive the correct input type.
  • The normalize_cookie() method checks for an instance of Cookie already and if not passes off to Cookie::parse() for which input validation is being added in PR Cookie: add input validation #609
  • The register() and before_redirect_check() methods already have a class based type declaration.
  • The before_request() method is intended to be only called as a Hook callback.
  • The other public methods do not take parameters.

The tests for the `Cookie\Jar` class were up to now mixed in with the tests for the `Cookie` class.

This moves the `Jar` tests to a dedicated test file.

The actual test code has not been touched.

This includes duplicating a helper method. At a later point in time when these tests are reviewed, it can be decided whether this helper should move to the `TestCase`.
As `array_merge()` is used on the `$cookies` property in the `before_redirect_check()` method, only arrays can be accepted.

Includes test.
The `$key` parameter corresponds to the `$name` parameter in the `Cookie::parse()` method, which expects a string and has a default value of `''`.

This fixes the default value of the `$key` parameter to be the same, i.e. an empty string.
@schlessera schlessera merged commit 11ccfbb into develop Nov 15, 2021
@schlessera schlessera deleted the feature/cookie-jar-add-input-validation branch November 15, 2021 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants