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: add input validation #609

Merged
merged 5 commits into from
Nov 15, 2021
Merged

Commits on Nov 15, 2021

  1. Cookie::__construct(): add input validation

    This commit adds input validation for all parameters of the `Cookie::__construct()` method:
    * For `$name` and `$value`, I've chosen to only accept plain strings and not `Stringable` objects.
    * The `$attributes` parameter accepts an array or an instance of `CaseInsensitiveDictionary` according to the docs, but the important thing about the `CaseInsensitiveDictionary` part is that if the parameter is passed as an object, it needs to have both `ArrayAccess`, as well as be `Traversable`, so the input validation checks for those characteristics rather than hard-requiring an instance of `CaseInsensitiveDictionary`.
    * As the `$flags` parameter is used with `array_merge()`, we cannot accept objects, so an array is the only valid input type.
    * As for `$reference_time`: as the default value is set using `time()`, which returns an integer time stamp, I've implemented the input validation to expect an integer.
    
    Includes tests for these new exceptions.
    jrfnl committed Nov 15, 2021
    Configuration menu
    Copy the full SHA
    ffb83e7 View commit details
    Browse the repository at this point in the history
  2. Cookie::domain_matches(): add input validation

    As this method only returns `boolean`, we may as well return boolean `false` instead of throwing an exception.
    
    Includes tests.
    jrfnl committed Nov 15, 2021
    Configuration menu
    Copy the full SHA
    d8f3ac5 View commit details
    Browse the repository at this point in the history
  3. Cookie::path_matches(): add input validation

    As this method only returns `boolean`, we may as well return boolean `false` instead of throwing an exception.
    
    The input validation in this case is not done at the very start of the function to prevent changing the behaviour of the function for those cases which were already being handled by the method. This is also the reason for using `is_scalar()` instead of `is_string()`.
    
    Includes tests.
    jrfnl committed Nov 15, 2021
    Configuration menu
    Copy the full SHA
    ace298d View commit details
    Browse the repository at this point in the history
  4. Cookie::parse(): add input validation

    This adds input validation to the `Cookie::parse()` method for the `$cookie_header` and `$name` parameters.
    
    As the `$reference_time` parameter is not directly used in this method, but only passed through to the `Cookie::__construct()` method, no input validation has been added, as it will be validated by the `Cookie::__construct()` method.
    
    Includes tests for the new exceptions + a test to safeguard that the "fall through validation for the `$reference_time`" actually happens.
    
    Includes fixing up two tests which were passing the wrong value type for an optional parameter.
    jrfnl committed Nov 15, 2021
    Configuration menu
    Copy the full SHA
    82f1fbb View commit details
    Browse the repository at this point in the history
  5. Cookie::parse_from_headers(): add test safeguarding input validation

    The first and second argument for the `Cookie::parse_from_headers()` method already have (class-based) type declarations.
    The third argument - `$time` - is only used to pass it through to the `parse()` method, which will subsequently pass it through to the class constructor which contains input validation for the parameter.
    
    This just adds a test to safeguard that the "fall through" validation for the `$time` parameter actually happens.
    jrfnl committed Nov 15, 2021
    Configuration menu
    Copy the full SHA
    3aa2065 View commit details
    Browse the repository at this point in the history