summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/public/security/isecurerandom.php2
-rw-r--r--tests/lib/security/securerandom.php19
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/public/security/isecurerandom.php b/lib/public/security/isecurerandom.php
index a6d24571ab9..46d82dd5f15 100644
--- a/lib/public/security/isecurerandom.php
+++ b/lib/public/security/isecurerandom.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.
diff --git a/tests/lib/security/securerandom.php b/tests/lib/security/securerandom.php
index 52c1dec92ea..2920077fa1d 100644
--- a/tests/lib/security/securerandom.php
+++ b/tests/lib/security/securerandom.php
@@ -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);
+ }
}