aboutsummaryrefslogtreecommitdiff
path: root/models/openid-php-openid-782224d/Tests/Auth/OpenID/CryptUtil.php
blob: 29022d2e18cfb9fce737603c32abf49cbf652547 (plain)
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
52
53
54
<?php

/**
 * Tests for the CryptUtil functions.
 *
 * PHP versions 4 and 5
 *
 * LICENSE: See the COPYING file included in this distribution.
 *
 * @package OpenID
 * @author JanRain, Inc. <openid@janrain.com>
 * @copyright 2005-2008 Janrain, Inc.
 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache
 */

require_once 'Auth/OpenID.php';
require_once 'Auth/OpenID/CryptUtil.php';

class Tests_Auth_OpenID_CryptUtil extends PHPUnit_Framework_TestCase {
    function test_length()
    {
        $cases = array(1, 10, 255);
        foreach ($cases as $length) {
            $data = Auth_OpenID_CryptUtil::getBytes($length);
            $this->assertEquals(Auth_OpenID::bytes($data), $length);
        }
    }

    function test_different()
    {
        $num_iterations = 100;
        $data_length = 20;

        $data = Auth_OpenID_CryptUtil::getBytes($num_iterations);
        for ($i = 0; $i < $num_iterations; $i++) {
            $last = $data;
            $data = Auth_OpenID_CryptUtil::getBytes($data_length);
            $this->assertFalse($data == $last);
        }
    }

    function test_cryptrand()
    {
        // It's possible, but HIGHLY unlikely that a correct
        // implementation will fail by returning the same number twice

        $s = Auth_OpenID_CryptUtil::getBytes(32);
        $t = Auth_OpenID_CryptUtil::getBytes(32);
        $this->assertEquals(Auth_OpenID::bytes($s), 32);
        $this->assertEquals(Auth_OpenID::bytes($t), 32);
        $this->assertFalse($s == $t);
    }
}