Add test for the second argument

remotes/origin/fix-10825
Lukas Reschke 12 years ago
parent 1ccbaae846
commit a54af89d8a
  1. 2
      lib/public/security/isecurerandom.php
  2. 19
      tests/lib/security/securerandom.php

@ -26,7 +26,7 @@ interface ISecureRandom {
const CHAR_UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const CHAR_LOWER = 'abcdefghijklmnopqrstuvwxyz';
const CHAR_DIGITS = '0123456789';
const CHAR_SYMBOLS = "!\"#$%&\'()* +,-./:;<=>?@[\]^_`{|}~";
const CHAR_SYMBOLS = '!\"#$%&\\'()* +,-./:;<=>?@[\]^_`{|}~';
/**
* Convenience method to get a low strength random number generator.

@ -22,6 +22,14 @@ class SecureRandomTest extends \PHPUnit_Framework_TestCase {
);
}
public static function charCombinations() {
return array(
array('CHAR_LOWER', '[a-z]'),
array('CHAR_UPPER', '[A-Z]'),
array('CHAR_DIGITS', '[0-9]'),
);
}
/** @var SecureRandom */
protected $rng;
@ -54,4 +62,15 @@ class SecureRandomTest extends \PHPUnit_Framework_TestCase {
function testUninitializedGenerate() {
$this->rng->generate(30);
}
/**
* @dataProvider charCombinations
*/
public function testScheme($charName, $chars) {
$generator = $this->rng->getMediumStrengthGenerator();
$scheme = constant('OCP\Security\ISecureRandom::' . $charName);
$randomString = $generator->generate(100, $scheme);
$matchesRegex = preg_match('/^'.$chars.'+$/', $randomString);
$this->assertSame(1, $matchesRegex);
}
}

Loading…
Cancel
Save