4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Tests;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpKernel\UriSigner;
17 class UriSignerTest extends TestCase
19 public function testSign()
21 $signer = new UriSigner('foobar');
23 $this->assertContains('?_hash=', $signer->sign('http://example.com/foo'));
24 $this->assertContains('&_hash=', $signer->sign('http://example.com/foo?foo=bar'));
27 public function testCheck()
29 $signer = new UriSigner('foobar');
31 $this->assertFalse($signer->check('http://example.com/foo?_hash=foo'));
32 $this->assertFalse($signer->check('http://example.com/foo?foo=bar&_hash=foo'));
33 $this->assertFalse($signer->check('http://example.com/foo?foo=bar&_hash=foo&bar=foo'));
35 $this->assertTrue($signer->check($signer->sign('http://example.com/foo')));
36 $this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar')));
37 $this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&0=integer')));
39 $this->assertTrue($signer->sign('http://example.com/foo?foo=bar&bar=foo') === $signer->sign('http://example.com/foo?bar=foo&foo=bar'));
42 public function testCheckWithDifferentArgSeparator()
44 $this->iniSet('arg_separator.output', '&');
45 $signer = new UriSigner('foobar');
48 'http://example.com/foo?baz=bay&foo=bar&_hash=rIOcC%2FF3DoEGo%2FvnESjSp7uU9zA9S%2F%2BOLhxgMexoPUM%3D',
49 $signer->sign('http://example.com/foo?foo=bar&baz=bay')
51 $this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&baz=bay')));