No Description

UriSignerTest.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Tests;
  11. use Symfony\Component\HttpKernel\UriSigner;
  12. class UriSignerTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testSign()
  15. {
  16. $signer = new UriSigner('foobar');
  17. $this->assertContains('?_hash=', $signer->sign('http://example.com/foo'));
  18. $this->assertContains('&_hash=', $signer->sign('http://example.com/foo?foo=bar'));
  19. }
  20. public function testCheck()
  21. {
  22. $signer = new UriSigner('foobar');
  23. $this->assertFalse($signer->check('http://example.com/foo?_hash=foo'));
  24. $this->assertFalse($signer->check('http://example.com/foo?foo=bar&_hash=foo'));
  25. $this->assertFalse($signer->check('http://example.com/foo?foo=bar&_hash=foo&bar=foo'));
  26. $this->assertTrue($signer->check($signer->sign('http://example.com/foo')));
  27. $this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar')));
  28. $this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&0=integer')));
  29. $this->assertTrue($signer->sign('http://example.com/foo?foo=bar&bar=foo') === $signer->sign('http://example.com/foo?bar=foo&foo=bar'));
  30. }
  31. public function testCheckWithDifferentArgSeparator()
  32. {
  33. $this->iniSet('arg_separator.output', '&amp;');
  34. $signer = new UriSigner('foobar');
  35. $this->assertSame(
  36. 'http://example.com/foo?baz=bay&foo=bar&_hash=rIOcC%2FF3DoEGo%2FvnESjSp7uU9zA9S%2F%2BOLhxgMexoPUM%3D',
  37. $signer->sign('http://example.com/foo?foo=bar&baz=bay')
  38. );
  39. $this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&baz=bay')));
  40. }
  41. }