rng = new \OC\Security\SecureRandom(); } /** * @dataProvider stringGenerationProvider */ public function testGetLowStrengthGeneratorLength($length, $expectedLength) { $generator = $this->rng; $this->assertEquals($expectedLength, strlen($generator->generate($length))); } /** * @dataProvider stringGenerationProvider */ public function testMediumLowStrengthGeneratorLength($length, $expectedLength) { $generator = $this->rng; $this->assertEquals($expectedLength, strlen($generator->generate($length))); } /** * @dataProvider stringGenerationProvider */ public function testUninitializedGenerate($length, $expectedLength) { $this->assertEquals($expectedLength, strlen($this->rng->generate($length))); } /** * @dataProvider charCombinations */ public function testScheme($charName, $chars) { $generator = $this->rng; $scheme = constant('OCP\Security\ISecureRandom::' . $charName); $randomString = $generator->generate(100, $scheme); $matchesRegex = preg_match('/^'.$chars.'+$/', $randomString); $this->assertSame(1, $matchesRegex); } public static function invalidLengths() { return [ [0], [-1], ]; } /** * @dataProvider invalidLengths */ public function testInvalidLengths($length) { $this->expectException(\LengthException::class); $generator = $this->rng; $generator->generate($length); } }