1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<?php
/**
* Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
class SecureRandomTest extends \PHPUnit_Framework_TestCase {
public function stringGenerationProvider() {
return array(
array(0, 0),
array(1, 1),
array(128, 128),
array(256, 256),
array(1024, 1024),
array(2048, 2048),
array(64000, 64000),
);
}
/**
* @dataProvider stringGenerationProvider
*/
function testGetLowStrengthGeneratorLength($length, $expectedLength) {
$rng = new \OC\Security\SecureRandom();
$generator = $rng->getLowStrengthGenerator();
$this->assertEquals($expectedLength, strlen($generator->generate($length)));
}
/**
* @dataProvider stringGenerationProvider
*/
function testMediumLowStrengthGeneratorLength($length, $expectedLength) {
$rng = new \OC\Security\SecureRandom();
$generator = $rng->getMediumStrengthGenerator();
$this->assertEquals($expectedLength, strlen($generator->generate($length)));
}
/**
* @expectedException \Exception
* @expectedExceptionMessage Generator is not initialized
*/
function testUninitializedGenerate() {
$rng = new \OC\Security\SecureRandom();
$rng->generate(30);
}
}
|