X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Ffront%2Fcontroller%2Fvisitor%2FShaarliVisitorControllerTest.php;h=935ec24ef7597ad67dcf043176883d3f571f9995;hb=a5a9cf23acd1248585173aa32757d9720b5f2d62;hp=316ce49c021114d667d16d3a84942adf629d18ab;hpb=a975d97a8da64864c3c49f1c54f571eb4ea5b81a;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/front/controller/visitor/ShaarliVisitorControllerTest.php b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php index 316ce49c..935ec24e 100644 --- a/tests/front/controller/visitor/ShaarliVisitorControllerTest.php +++ b/tests/front/controller/visitor/ShaarliVisitorControllerTest.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\BookmarkFilter; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; @@ -110,7 +110,7 @@ class ShaarliVisitorControllerTest extends TestCase */ public function testRedirectFromRefererDefault(): void { - $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2'; $response = new Response(); @@ -125,7 +125,7 @@ class ShaarliVisitorControllerTest extends TestCase */ public function testRedirectFromRefererWithUnmatchedLoopTerm(): void { - $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2'; $response = new Response(); @@ -140,7 +140,7 @@ class ShaarliVisitorControllerTest extends TestCase */ public function testRedirectFromRefererWithMatchingLoopTermInPath(): void { - $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2'; $response = new Response(); @@ -155,7 +155,7 @@ class ShaarliVisitorControllerTest extends TestCase */ public function testRedirectFromRefererWithMatchingLoopTermInQueryParam(): void { - $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2'; $response = new Response(); @@ -171,7 +171,7 @@ class ShaarliVisitorControllerTest extends TestCase */ public function testRedirectFromRefererWithMatchingLoopTermInQueryValue(): void { - $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2'; $response = new Response(); @@ -187,7 +187,7 @@ class ShaarliVisitorControllerTest extends TestCase */ public function testRedirectFromRefererWithLoopTermInDomain(): void { - $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2'; $response = new Response(); @@ -203,7 +203,7 @@ class ShaarliVisitorControllerTest extends TestCase */ public function testRedirectFromRefererWithMatchingClearedParam(): void { - $this->container->environment['HTTP_REFERER'] = 'http://shaarli.tld/subfolder/controller?query=param&other=2'; + $this->container->environment['HTTP_REFERER'] = 'http://shaarli/subfolder/controller?query=param&other=2'; $response = new Response(); @@ -212,4 +212,35 @@ class ShaarliVisitorControllerTest extends TestCase static::assertSame(302, $result->getStatusCode()); static::assertSame(['/subfolder/controller?other=2'], $result->getHeader('location')); } + + /** + * Test redirectFromReferer() - From another domain -> we ignore the given referrer. + */ + public function testRedirectExternalReferer(): void + { + $this->container->environment['HTTP_REFERER'] = 'http://other.domain.tld/controller?query=param&other=2'; + + $response = new Response(); + + $result = $this->controller->redirectFromReferer($this->request, $response, ['query'], ['query']); + + static::assertSame(302, $result->getStatusCode()); + static::assertSame(['/subfolder/'], $result->getHeader('location')); + } + + /** + * Test redirectFromReferer() - From another domain -> we ignore the given referrer. + */ + public function testRedirectExternalRefererExplicitDomainName(): void + { + $this->container->environment['SERVER_NAME'] = 'my.shaarli.tld'; + $this->container->environment['HTTP_REFERER'] = 'http://your.shaarli.tld/controller?query=param&other=2'; + + $response = new Response(); + + $result = $this->controller->redirectFromReferer($this->request, $response, ['query'], ['query']); + + static::assertSame(302, $result->getStatusCode()); + static::assertSame(['/subfolder/'], $result->getHeader('location')); + } }