From 775803a05cdba9d7fc1b37af4b15ecd80a8cbcc2 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 6 Jul 2015 10:22:00 +0200 Subject: Prevent redirection loop everytime we rely on HTTP_REFERER: * search tag * delete tag * pagination * display privates only * delete link * new/edit/cancel link return page Move location generation to Utils.php + unit tests. Fixes #256 ninja --- tests/UtilsTest.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'tests/UtilsTest.php') diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 90392dfb..8355c7f8 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -93,5 +93,30 @@ class UtilsTest extends PHPUnit_Framework_TestCase $this->assertFalse(checkDateFormat('Y-m-d', '2015-06')); $this->assertFalse(checkDateFormat('Ymd', 'DeLorean')); } + + /** + * Test generate location with valid data. + */ + public function testGenerateLocation() { + $ref = 'http://localhost/?test'; + $this->assertEquals($ref, generateLocation($ref, 'localhost')); + $ref = 'http://localhost:8080/?test'; + $this->assertEquals($ref, generateLocation($ref, 'localhost:8080')); + } + + /** + * Test generate location - anti loop. + */ + public function testGenerateLocationLoop() { + $ref = 'http://localhost/?test'; + $this->assertEquals('?', generateLocation($ref, 'localhost', ['test'])); + } + + /** + * Test generate location - from other domain. + */ + public function testGenerateLocationOut() { + $ref = 'http://somewebsite.com/?test'; + $this->assertEquals('?', generateLocation($ref, 'localhost')); + } } -?> -- cgit v1.2.3