mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 15:28:40 +00:00
Conditionalize hash_hmac tests for 5.0
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
This commit is contained in:
parent
0beecad78a
commit
8cd08620dc
@ -48,7 +48,7 @@ class HTMLPurifier_URIFilter_Munge extends HTMLPurifier_URIFilter
|
||||
$this->doEmbed = $config->get('URI.MungeResources');
|
||||
$this->secretKey = $config->get('URI.MungeSecretKey');
|
||||
if ($this->secretKey && !function_exists('hash_hmac')) {
|
||||
trigger_error("Cannot use %URI.MungeSecretKey without hash_hmac support.", E_USER_ERROR);
|
||||
throw new Exception("Cannot use %URI.MungeSecretKey without hash_hmac support.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
--SKIPIF--
|
||||
return !function_exists('hash_hmac');
|
||||
--INI--
|
||||
URI.Munge = "/redirect?s=%s&t=%t&r=%r&n=%n&m=%m&p=%p"
|
||||
URI.MungeSecretKey = "foo"
|
||||
|
@ -1,3 +1,5 @@
|
||||
--SKIPIF--
|
||||
return !function_exists('hash_hmac');
|
||||
--INI--
|
||||
HTML.SafeObject = true
|
||||
HTML.SafeEmbed = true
|
||||
|
@ -1,3 +1,5 @@
|
||||
--SKIPIF--
|
||||
return !function_exists('hash_hmac');
|
||||
--INI--
|
||||
URI.Munge = "/redirect.php?url=%s&check=%t"
|
||||
URI.MungeSecretKey = "foo"
|
||||
|
@ -16,8 +16,10 @@ class HTMLPurifier_URIFilter_MungeTest extends HTMLPurifier_URIFilterHarness
|
||||
|
||||
protected function setSecureMunge($key = 'secret')
|
||||
{
|
||||
if (!function_exists('hash_hmac')) return false;
|
||||
$this->setMunge('/redirect.php?url=%s&checksum=%t');
|
||||
$this->config->set('URI.MungeSecretKey', $key);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function testMunge()
|
||||
@ -92,13 +94,13 @@ class HTMLPurifier_URIFilter_MungeTest extends HTMLPurifier_URIFilterHarness
|
||||
|
||||
public function testSecureMungePreserve()
|
||||
{
|
||||
$this->setSecureMunge();
|
||||
if (!$this->setSecureMunge()) return;
|
||||
$this->assertFiltering('/local');
|
||||
}
|
||||
|
||||
public function testSecureMungePreserveEmbedded()
|
||||
{
|
||||
$this->setSecureMunge();
|
||||
if (!$this->setSecureMunge()) return;
|
||||
$embedded = true;
|
||||
$this->context->register('EmbeddedURI', $embedded);
|
||||
$this->assertFiltering('http://google.com');
|
||||
@ -106,26 +108,26 @@ class HTMLPurifier_URIFilter_MungeTest extends HTMLPurifier_URIFilterHarness
|
||||
|
||||
public function testSecureMungeStandard()
|
||||
{
|
||||
$this->setSecureMunge();
|
||||
if (!$this->setSecureMunge()) return;
|
||||
$this->assertFiltering('http://google.com', '/redirect.php?url=http%3A%2F%2Fgoogle.com&checksum=46267a796aca0ea5839f24c4c97ad2648373a4eca31b1c0d1fa7c7ff26798f79');
|
||||
}
|
||||
|
||||
public function testSecureMungeIgnoreUnknownSchemes()
|
||||
{
|
||||
// This should be integration tested as well to be false
|
||||
$this->setSecureMunge();
|
||||
if (!$this->setSecureMunge()) return;
|
||||
$this->assertFiltering('javascript:', true);
|
||||
}
|
||||
|
||||
public function testSecureMungeIgnoreUnbrowsableSchemes()
|
||||
{
|
||||
$this->setSecureMunge();
|
||||
if (!$this->setSecureMunge()) return;
|
||||
$this->assertFiltering('news:', true);
|
||||
}
|
||||
|
||||
public function testSecureMungeToDirectory()
|
||||
{
|
||||
$this->setSecureMunge();
|
||||
if (!$this->setSecureMunge()) return;
|
||||
$this->setMunge('/links/%s/%t');
|
||||
$this->assertFiltering('http://google.com', '/links/http%3A%2F%2Fgoogle.com/46267a796aca0ea5839f24c4c97ad2648373a4eca31b1c0d1fa7c7ff26798f79');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user