diff options
| author | jvoisin | 2020-12-31 15:33:08 +0100 |
|---|---|---|
| committer | jvoisin | 2020-12-31 15:42:17 +0100 |
| commit | 22793562313fd7efaeaa663d405357bbb788da5f (patch) | |
| tree | c70a2c28946ce640060e130a8d2128b0fe8de4dc /src | |
| parent | c3a35b46107fc5ddf94b15ccd6a4d1697610e48f (diff) | |
Add tests for harden_rand
Diffstat (limited to 'src')
| -rw-r--r-- | src/tests/harden_rand_php8/config/harden_rand.ini | 1 | ||||
| -rw-r--r-- | src/tests/harden_rand_php8/harden_rand_noargs.phpt | 43 |
2 files changed, 44 insertions, 0 deletions
diff --git a/src/tests/harden_rand_php8/config/harden_rand.ini b/src/tests/harden_rand_php8/config/harden_rand.ini new file mode 100644 index 0000000..89e19be --- /dev/null +++ b/src/tests/harden_rand_php8/config/harden_rand.ini | |||
| @@ -0,0 +1 @@ | |||
| sp.harden_random.enable(); | |||
diff --git a/src/tests/harden_rand_php8/harden_rand_noargs.phpt b/src/tests/harden_rand_php8/harden_rand_noargs.phpt new file mode 100644 index 0000000..5f00c8f --- /dev/null +++ b/src/tests/harden_rand_php8/harden_rand_noargs.phpt | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | --TEST-- | ||
| 2 | Harden rand without any arguments | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) print "skip"; ?> | ||
| 5 | <?php if (PHP_VERSION_ID < 80000) print "skip"; ?> | ||
| 6 | --INI-- | ||
| 7 | sp.configuration_file={PWD}/config/harden_rand.ini | ||
| 8 | --FILE-- | ||
| 9 | <?php | ||
| 10 | rand(); | ||
| 11 | mt_rand(); | ||
| 12 | |||
| 13 | rand(1); | ||
| 14 | mt_rand(1); | ||
| 15 | |||
| 16 | rand(1, 2); | ||
| 17 | mt_rand(1, 2); | ||
| 18 | |||
| 19 | rand(2, 1); | ||
| 20 | mt_rand(2, 1); | ||
| 21 | |||
| 22 | rand(2, 1, 0); | ||
| 23 | mt_rand(2, 1, 0); | ||
| 24 | |||
| 25 | rand("test", 1); | ||
| 26 | mt_rand("test", 1); | ||
| 27 | |||
| 28 | rand(1, "test"); | ||
| 29 | mt_rand(1, "test"); | ||
| 30 | |||
| 31 | rand(1, 2, "test"); | ||
| 32 | mt_rand(1, 2, "test"); | ||
| 33 | |||
| 34 | echo "Everything is fine\n"; | ||
| 35 | echo "Absolutely everything\n"; | ||
| 36 | echo 'Even with single quotes'; | ||
| 37 | ?> | ||
| 38 | --EXPECTF-- | ||
| 39 | Fatal error: Uncaught ArgumentCountError: rand() expects exactly 2 arguments, 1 given in %s/tests/harden_rand_php8/harden_rand_noargs.php:5 | ||
| 40 | Stack trace: | ||
| 41 | #0 %s/tests/harden_rand_php8/harden_rand_noargs.php(5): rand(1) | ||
| 42 | #1 {main} | ||
| 43 | thrown in %s/tests/harden_rand_php8/harden_rand_noargs.php on line 5 | ||
