/usr/share/php/tests/Horde_Token/Horde/Token/BackendTestCase.php is in php-horde-token 2.0.4-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | <?php
/**
* Tests that each backend should fulfil.
*
* PHP version 5
*
* @category Horde
* @package Token
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Token
*/
/**
* Tests that each backend should fulfil.
*
* Copyright 2010-2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @package Token
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://pear.horde.org/index.php?package=Token
*/
abstract class Horde_Token_BackendTestCase extends Horde_Test_Case
{
public function testToken()
{
$this->assertEquals(51, strlen($this->_getBackend()->get()));
}
public function testValidation()
{
$t = $this->_getBackend();
$this->assertTrue($t->isValid($t->get()));
}
public function testValidationWithSeed()
{
$t = $this->_getBackend();
$this->assertTrue($t->isValid($t->get('a'), 'a'));
}
public function testInvalidToken()
{
$t = $this->_getBackend();
$this->assertFalse($t->isValid('something'));
}
public function testInvalidEmptyToken()
{
$this->assertFalse($this->_getBackend()->isValid(''));
}
public function testInvalidSeed()
{
$t = $this->_getBackend();
$this->assertFalse($t->isValid($t->get('a'), 'b'));
}
public function testActiveToken()
{
$t = $this->_getBackend();
$this->assertTrue($t->isValid($t->get('a'), 'a', 10));
}
public function testImmediateTimeout()
{
$t = $this->_getBackend();
$this->assertFalse($t->isValid($t->get('a'), 'a', 0));
}
public function testTimeoutAfterOneSecond()
{
$t = $this->_getBackend(array('token_lifetime' => 1));
$token = $t->get('a');
sleep(1);
$this->assertFalse($t->isValid($token, 'a', 1));
// Pack two assertions in this test to avoid sleeping twice
$this->assertFalse($t->isValid($token, 'a'));
}
public function testTokenLifetimeParameter()
{
$t = $this->_getBackend(array('token_lifetime' => -1));
$this->assertTrue($t->isValid($t->get()));
}
public function testUniqueToken()
{
$t = $this->_getBackend();
$token = $t->get('a');
$t->isValid($token, 'a', -1, true);
$this->assertFalse($t->isValid($token, 'a', -1, true));
}
public function testNonces()
{
$t = $this->_getBackend();
$this->assertEquals(6, strlen($t->getNonce()));
}
/**
* @expectedException Horde_Token_Exception_Invalid
*/
public function testInvalidTokenException()
{
$t = $this->_getBackend();
$t->validate('something');
}
/**
* @expectedException Horde_Token_Exception_Invalid
*/
public function testInvalidSeedException()
{
$t = $this->_getBackend();
$t->validate($t->get('a'), 'b');
}
/**
* @expectedException Horde_Token_Exception_Expired
*/
public function testTimeoutException()
{
$t = $this->_getBackend(array('token_lifetime' => 1));
$token = $t->get('a');
sleep(1);
$t->validate($token, 'a');
}
public function testOverrideTimeoutException()
{
$t = $this->_getBackend(array('token_lifetime' => 1));
$token = $t->get('a');
sleep(1);
$this->assertInternalType('array', $t->validate($token, 'a', 2));
}
public function testDisableTimeoutException()
{
$t = $this->_getBackend(array('token_lifetime' => 1));
$token = $t->get('a');
sleep(1);
$this->assertInternalType('array', $t->validate($token, 'a', -1));
}
public function testIsValidUnique()
{
$t = $this->_getBackend();
$token = $t->get('a');
$this->assertNull($t->validateUnique($token, 'a'));
}
/**
* @expectedException Horde_Token_Exception_Used
*/
public function testIsValidAndUnusedException()
{
$t = $this->_getBackend();
$token = $t->get('a');
$t->validateUnique($token, 'a');
$t->validateUnique($token, 'a');
}
/**
* @expectedException Horde_Token_Exception_Used
*/
public function testIsValidAndValidateException()
{
$t = $this->_getBackend();
$token = $t->get('a');
$t->isValid($token, 'a', null, true);
$t->validateUnique($token, 'a');
}
abstract protected function _getBackend(array $params = array());
}
|