This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes ZF2018-01
- Loading branch information
Showing
5 changed files
with
205 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* @see https://github.com/zendframework/zend-feed for the canonical source repository | ||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com) | ||
* @license https://github.com/zendframework/zend-feed/blob/master/LICENSE.md New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Feed\PubSubHubbub; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use ReflectionMethod; | ||
use Zend\Feed\PubSubHubbub\AbstractCallback; | ||
|
||
class AbstractCallbackTest extends TestCase | ||
{ | ||
public function testDetectCallbackUrlIgnoresXOriginalUrlHeaderWhenXRewriteUrlHeaderIsNotPresent() | ||
{ | ||
$_SERVER = array_merge($_SERVER, [ | ||
'HTTP_X_ORIGINAL_URL' => '/hijack-attempt', | ||
'HTTPS' => 'on', | ||
'HTTP_HOST' => 'example.com', | ||
'REQUEST_URI' => '/requested/path', | ||
]); | ||
|
||
$callback = new TestAsset\Callback(); | ||
|
||
$r = new ReflectionMethod($callback, '_detectCallbackUrl'); | ||
$r->setAccessible(true); | ||
|
||
$this->assertSame('/requested/path', $r->invoke($callback)); | ||
} | ||
|
||
public function testDetectCallbackUrlRequiresCombinationOfIISWasUrlRewrittenAndUnencodedUrlToReturnEarly() | ||
{ | ||
$_SERVER = array_merge($_SERVER, [ | ||
'IIS_WasUrlRewritten' => '1', | ||
'UNENCODED_URL' => '/requested/path', | ||
]); | ||
|
||
$callback = new TestAsset\Callback(); | ||
|
||
$r = new ReflectionMethod($callback, '_detectCallbackUrl'); | ||
$r->setAccessible(true); | ||
|
||
$this->assertSame('/requested/path', $r->invoke($callback)); | ||
} | ||
|
||
public function testDetectCallbackUrlUsesRequestUriWhenNoOtherRewriteHeadersAreFound() | ||
{ | ||
$_SERVER = array_merge($_SERVER, [ | ||
'REQUEST_URI' => '/expected/path' | ||
]); | ||
|
||
$callback = new TestAsset\Callback(); | ||
|
||
$r = new ReflectionMethod($callback, '_detectCallbackUrl'); | ||
$r->setAccessible(true); | ||
|
||
$this->assertSame('/expected/path', $r->invoke($callback)); | ||
} | ||
|
||
public function testDetectCallbackUrlFallsBackToOrigPathInfoWhenAllElseFails() | ||
{ | ||
$_SERVER = array_merge($_SERVER, [ | ||
'ORIG_PATH_INFO' => '/expected/path', | ||
]); | ||
|
||
$callback = new TestAsset\Callback(); | ||
|
||
$r = new ReflectionMethod($callback, '_detectCallbackUrl'); | ||
$r->setAccessible(true); | ||
|
||
$this->assertSame('/expected/path', $r->invoke($callback)); | ||
} | ||
|
||
public function testDetectCallbackReturnsEmptyStringIfNoResourcesMatchedInServerSuperglobal() | ||
{ | ||
$callback = new TestAsset\Callback(); | ||
|
||
$r = new ReflectionMethod($callback, '_detectCallbackUrl'); | ||
$r->setAccessible(true); | ||
|
||
$this->assertSame('', $r->invoke($callback)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* @see https://github.com/zendframework/zend-feed for the canonical source repository | ||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com) | ||
* @license https://github.com/zendframework/zend-feed/blob/master/LICENSE.md New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Feed\PubSubHubbub\TestAsset; | ||
|
||
use Zend\Feed\PubSubHubbub\AbstractCallback; | ||
|
||
class Callback extends AbstractCallback | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function handle(array $httpData = null, $sendResponseNow = false) | ||
{ | ||
return false; | ||
} | ||
} |