summaryrefslogtreecommitdiffstats
path: root/Core/Tests/Util/SecureRandomTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'Core/Tests/Util/SecureRandomTest.php')
-rw-r--r--Core/Tests/Util/SecureRandomTest.php66
1 files changed, 13 insertions, 53 deletions
diff --git a/Core/Tests/Util/SecureRandomTest.php b/Core/Tests/Util/SecureRandomTest.php
index 2e94cc1..a78d5a2 100644
--- a/Core/Tests/Util/SecureRandomTest.php
+++ b/Core/Tests/Util/SecureRandomTest.php
@@ -13,26 +13,27 @@ namespace Symfony\Component\Security\Core\Tests\Util;
use Symfony\Component\Security\Core\Util\SecureRandom;
+/**
+ * @group legacy
+ */
class SecureRandomTest extends \PHPUnit_Framework_TestCase
{
/**
* T1: Monobit test.
- *
- * @dataProvider getSecureRandoms
*/
- public function testMonobit($secureRandom)
+ public function testMonobit()
{
+ $secureRandom = new SecureRandom();
$nbOnBits = substr_count($this->getBitSequence($secureRandom, 20000), '1');
$this->assertTrue($nbOnBits > 9654 && $nbOnBits < 10346, 'Monobit test failed, number of turned on bits: '.$nbOnBits);
}
/**
* T2: Chi-square test with 15 degrees of freedom (chi-Quadrat-Anpassungstest).
- *
- * @dataProvider getSecureRandoms
*/
- public function testPoker($secureRandom)
+ public function testPoker()
{
+ $secureRandom = new SecureRandom();
$b = $this->getBitSequence($secureRandom, 20000);
$c = array();
for ($i = 0; $i <= 15; ++$i) {
@@ -56,11 +57,10 @@ class SecureRandomTest extends \PHPUnit_Framework_TestCase
/**
* Run test.
- *
- * @dataProvider getSecureRandoms
*/
- public function testRun($secureRandom)
+ public function testRun()
{
+ $secureRandom = new SecureRandom();
$b = $this->getBitSequence($secureRandom, 20000);
$runs = array();
@@ -104,11 +104,10 @@ class SecureRandomTest extends \PHPUnit_Framework_TestCase
/**
* Long-run test.
- *
- * @dataProvider getSecureRandoms
*/
- public function testLongRun($secureRandom)
+ public function testLongRun()
{
+ $secureRandom = new SecureRandom();
$b = $this->getBitSequence($secureRandom, 20000);
$longestRun = $currentRun = 0;
@@ -133,11 +132,10 @@ class SecureRandomTest extends \PHPUnit_Framework_TestCase
/**
* Serial Correlation (Autokorrelationstest).
- *
- * @dataProvider getSecureRandoms
*/
- public function testSerialCorrelation($secureRandom)
+ public function testSerialCorrelation()
{
+ $secureRandom = new SecureRandom();
$shift = mt_rand(1, 5000);
$b = $this->getBitSequence($secureRandom, 20000);
@@ -149,44 +147,6 @@ class SecureRandomTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($Z > 2326 && $Z < 2674, 'Failed serial correlation test: '.$Z);
}
- public function getSecureRandoms()
- {
- $secureRandoms = array();
-
- // only add if openssl is indeed present
- $secureRandom = new SecureRandom();
- if ($this->hasOpenSsl($secureRandom)) {
- $secureRandoms[] = array($secureRandom);
- }
-
- // no-openssl with custom seed provider
- $secureRandom = new SecureRandom(sys_get_temp_dir().'/_sf2.seed');
- $this->disableOpenSsl($secureRandom);
- $secureRandoms[] = array($secureRandom);
-
- return $secureRandoms;
- }
-
- protected function disableOpenSsl($secureRandom)
- {
- $ref = new \ReflectionProperty($secureRandom, 'useOpenSsl');
- $ref->setAccessible(true);
- $ref->setValue($secureRandom, false);
- $ref->setAccessible(false);
- }
-
- protected function hasOpenSsl($secureRandom)
- {
- $ref = new \ReflectionProperty($secureRandom, 'useOpenSsl');
- $ref->setAccessible(true);
-
- $ret = $ref->getValue($secureRandom);
-
- $ref->setAccessible(false);
-
- return $ret;
- }
-
private function getBitSequence($secureRandom, $length)
{
$bitSequence = '';