php-src/ext/sodium/tests/bug78516.phpt
Max Semenik 6c9a05667b run-tests: use the EXTENSIONS section for skipping
Currently, most skip checks are just for making sure an extension is
available. Even with recent addition of skip caching, this makes tests
needlessly slow:
* Checks for the same extension in its tests can have small differences
  impacting cacheability.
* Even identical skip checks in two tests can still be executed twice if
  they're run by different workers.

To remedy this, I'm repurposing the existing --EXTENSIONS-- section of
.phpt files to specify wjich extensions are required for current test to
run. Current behavior:
1) If the extension is already visible to PHP, all is good
2) If it isn't, assume it's present as a shared module and attempt to add
   it via a command line parameter
3) If that works, all is good
4) If it doesn't, PHP fails with a cryptic error message trying to
   execute the test itself

After this commit:
1) and 2) are kept unchanged
3) Check if shared extension file from 2) is actually present
4) Skip the test if it isn't

Other benefits include clear skip reasons (vs. sometimes none in many
current skip checks) and moving test information from code to metadata,
opening more opportunities for search and analysis.

Since --EXTENSIONS-- is barely ever used, this change poses no risk of
hidden failures.

As a demonstration of the new approach, this commit migrates one
extension to it. If merged, I will migrate other extensions in
subsequent PRs.

Closes GH-6787.
2021-03-22 09:53:38 +01:00

21 lines
670 B
PHP

--TEST--
Bug #78516 (password_hash(): Memory cost is not in allowed range)
--EXTENSIONS--
sodium
--SKIPIF--
<?php
if (!defined('PASSWORD_ARGON2ID')) die('skip PASSWORD_ARGON2ID not available');
?>
--FILE--
<?php
$pass = password_hash('secret', PASSWORD_ARGON2ID, ['memory_cost' => 8191]);
password_needs_rehash($pass, PASSWORD_ARGON2ID, ['memory_cost' => 8191]);
var_dump(password_get_info($pass)['options']['memory_cost']);
$pass = password_hash('secret', PASSWORD_ARGON2I, ['memory_cost' => 8191]);
password_needs_rehash($pass, PASSWORD_ARGON2I, ['memory_cost' => 8191]);
var_dump(password_get_info($pass)['options']['memory_cost']);
?>
--EXPECT--
int(8191)
int(8191)