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

Improve error reporting in random extension #9071

Merged
merged 10 commits into from
Jul 25, 2022

Commits on Jul 20, 2022

  1. Use php_random_bytes_throw() in Secure engine's generate()

    This exposes the underlying exception, improving debugging:
    
        Fatal error: Uncaught Exception: Cannot open source device in php-src/test.php:5
        Stack trace:
        #0 php-src/test.php(5): Random\Engine\Secure->generate()
        #1 {main}
    
        Next RuntimeException: Random number generation failed in php-src/test.php:5
        Stack trace:
        #0 php-src/test.php(5): Random\Engine\Secure->generate()
        #1 {main}
          thrown in php-src/test.php on line 5
    TimWolla committed Jul 20, 2022
    Configuration menu
    Copy the full SHA
    8daa5fe View commit details
    Browse the repository at this point in the history
  2. Use php_random_int_throw() in Secure engine's range()

    This exposes the underlying exception, improving debugging:
    
        Exception: Cannot open source device in php-src/test.php:17
        Stack trace:
        #0 php-src/test.php(17): Random\Randomizer->getInt(1, 3)
        #1 {main}
    
        Next RuntimeException: Random number generation failed in php-src/test.php:17
        Stack trace:
        #0 php-src/test.php(17): Random\Randomizer->getInt(1, 3)
        #1 {main}
    TimWolla committed Jul 20, 2022
    Configuration menu
    Copy the full SHA
    b7bdf1a View commit details
    Browse the repository at this point in the history
  3. Throw exception when a user engine returns an empty string

    This improves debugging, because the actual reason for the failure is available
    as a previous Exception:
    
        DomainException: The returned string must not be empty in php-src/test.php:17
        Stack trace:
        #0 php-src/test.php(17): Random\Randomizer->getBytes(123)
        #1 {main}
    
        Next RuntimeException: Random number generation failed in php-src/test.php:17
        Stack trace:
        #0 php-src/test.php(17): Random\Randomizer->getBytes(123)
        #1 {main}
    TimWolla committed Jul 20, 2022
    Configuration menu
    Copy the full SHA
    f93daeb View commit details
    Browse the repository at this point in the history
  4. Throw exception when the range selector fails to get acceptable numbe…

    …rs in 50 attempts
    
    This improves debugging, because the actual reason for the failure is available
    as a previous Exception:
    
        RuntimeException: Failed to generate an acceptable random number in 50 attempts in php-src/test.php:17
        Stack trace:
        #0 php-src/test.php(17): Random\Randomizer->getInt(1, 3)
        #1 {main}
    
        Next RuntimeException: Random number generation failed in php-src/test.php:17
        Stack trace:
        #0 php-src/test.php(17): Random\Randomizer->getInt(1, 3)
        #1 {main}
    TimWolla committed Jul 20, 2022
    Configuration menu
    Copy the full SHA
    fdfa2f3 View commit details
    Browse the repository at this point in the history
  5. Improve user_unsafe test

    Select parameters for ->getInt() that will actually lead to unsafe behavior.
    TimWolla committed Jul 20, 2022
    Configuration menu
    Copy the full SHA
    12b07ce View commit details
    Browse the repository at this point in the history
  6. Fix user_unsafe test

    If an engine fails once it will be permanently poisoned by setting
    `->last_unsafe`. This is undesirable for the test, because it skews the
    results.
    
    Fix this by creating a fresh engine for each "assertion".
    TimWolla committed Jul 20, 2022
    Configuration menu
    Copy the full SHA
    3e18441 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    8adb67a View commit details
    Browse the repository at this point in the history

Commits on Jul 21, 2022

  1. Catch Throwable in user_unsafe.phpt

    As we print the full stringified exception we implicitly assert the type of the
    exception. No need to be overly specific in the catch block.
    TimWolla committed Jul 21, 2022
    Configuration menu
    Copy the full SHA
    3090379 View commit details
    Browse the repository at this point in the history

Commits on Jul 24, 2022

  1. Configuration menu
    Copy the full SHA
    39b996a View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    734c79c View commit details
    Browse the repository at this point in the history