diff --git a/tests/Symfony/Tests/Component/Security/Http/Firewall/DigestDataTest.php b/tests/Symfony/Tests/Component/Security/Http/Firewall/DigestDataTest.php index df96470d3b..82f3215dea 100644 --- a/tests/Symfony/Tests/Component/Security/Http/Firewall/DigestDataTest.php +++ b/tests/Symfony/Tests/Component/Security/Http/Firewall/DigestDataTest.php @@ -15,11 +15,6 @@ use Symfony\Component\Security\Http\Firewall\DigestData; class DigestDataTest extends \PHPUnit_Framework_TestCase { - public function setUp() - { - class_exists('Symfony\Component\Security\Http\Firewall\DigestAuthenticationListener', true); - } - public function testGetResponse() { $digestAuth = new DigestData( @@ -85,6 +80,28 @@ class DigestDataTest extends \PHPUnit_Framework_TestCase $this->calculateServerDigest('\"user\"', 'Welcome, \"robot\"!', 'pass,word=password', 'ThisIsAKey', '00000001', 'MDIwODkz', 'auth', 'GET', '/path/info?p1=5&p2=5'); } + public function testIsNonceExpired() + { + $time = microtime(true) + 10; + $key = 'ThisIsAKey'; + $nonce = base64_encode($time . ':' . md5($time . ':' . $key)); + + $digestAuth = new DigestData( + 'username="user", realm="Welcome, robot!", nonce="' . $nonce . '", ' . + 'uri="/path/info?p1=5&p2=5", cnonce="MDIwODkz", nc=00000001, qop="auth", ' . + 'response="b52938fc9e6d7c01be7702ece9031b42"' + ); + + $digestAuth->validateAndDecode($key, 'Welcome, robot!'); + + $this->assertFalse($digestAuth->isNonceExpired()); + } + + protected function setUp() + { + class_exists('Symfony\Component\Security\Http\Firewall\DigestAuthenticationListener', true); + } + private function calculateServerDigest($username, $realm, $password, $key, $nc, $cnonce, $qop, $method, $uri) { $time = microtime(true); @@ -102,21 +119,4 @@ class DigestDataTest extends \PHPUnit_Framework_TestCase $this->assertEquals($digestAuth->getResponse(), $digestAuth->calculateServerDigest($password, $method)); } - - public function testIsNonceExpired() - { - $time = microtime(true) + 10; - $key = 'ThisIsAKey'; - $nonce = base64_encode($time . ':' . md5($time . ':' . $key)); - - $digestAuth = new DigestData( - 'username="user", realm="Welcome, robot!", nonce="' . $nonce . '", ' . - 'uri="/path/info?p1=5&p2=5", cnonce="MDIwODkz", nc=00000001, qop="auth", ' . - 'response="b52938fc9e6d7c01be7702ece9031b42"' - ); - - $digestAuth->validateAndDecode($key, 'Welcome, robot!'); - - $this->assertFalse($digestAuth->isNonceExpired()); - } -} \ No newline at end of file +}