Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/marc-mabe/zf2 into hotfix…
Browse files Browse the repository at this point in the history
…/php53_version_checks
  • Loading branch information
weierophinney committed May 23, 2011
2 parents c48e63d + e27a311 commit 721cd66
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 181 deletions.
15 changes: 1 addition & 14 deletions library/Zend/Application/AbstractBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,25 +225,12 @@ public function mergeOptions(array $array1, $array2 = null)
/**
* Get class resources (as resource/method pairs)
*
* Uses get_class_methods() by default, reflection on prior to 5.2.6,
* as a bug prevents the usage of get_class_methods() there.
*
* @return array
*/
public function getClassResources()
{
if (null === $this->_classResources) {
if (version_compare(PHP_VERSION, '5.2.6') === -1) {
$class = new \ReflectionObject($this);
$classMethods = $class->getMethods();
$methodNames = array();

foreach ($classMethods as $method) {
$methodNames[] = $method->getName();
}
} else {
$methodNames = get_class_methods($this);
}
$methodNames = get_class_methods($this);

$this->_classResources = array();
foreach ($methodNames as $method) {
Expand Down
19 changes: 1 addition & 18 deletions library/Zend/Filter/Compress/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function decompress($content)
if (!empty($target) && !is_dir($target)) {
$target = dirname($target);
}

if (!empty($target)) {
$target = rtrim($target, '/\\') . DIRECTORY_SEPARATOR;
}
Expand All @@ -227,23 +227,6 @@ public function decompress($content)
throw new Exception\RuntimeException($this->_errorString($res));
}

if (version_compare(PHP_VERSION, '5.2.8', '<')) {
for ($i = 0; $i < $zip->numFiles; $i++) {
$statIndex = $zip->statIndex($i);
$currName = $statIndex['name'];
if (($currName{0} == '/') ||
(substr($currName, 0, 2) == '..') ||
(substr($currName, 0, 4) == './..')
)
{
throw new Exception\RuntimeException('Upward directory traversal was detected inside ' . $archive
. ' please use PHP 5.2.8 or greater to take advantage of path resolution features of '
. 'the zip extension in this decompress() method.'
);
}
}
}

$res = @$zip->extractTo($target);
if ($res !== true) {
throw new Exception\RuntimeException($this->_errorString($res));
Expand Down
15 changes: 6 additions & 9 deletions library/Zend/Filter/Encrypt/Mcrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,14 @@ public function setVector($vector = null)
$cipher = $this->_openCipher();
$size = mcrypt_enc_get_iv_size($cipher);
if (empty($vector)) {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && version_compare(PHP_VERSION, '5.3.0', '<')) {
$method = MCRYPT_RAND;
if (file_exists('/dev/urandom') || (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')) {
$method = MCRYPT_DEV_URANDOM;
} elseif (file_exists('/dev/random')) {
$method = MCRYPT_DEV_RANDOM;
} else {
if (file_exists('/dev/urandom') || (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')) {
$method = MCRYPT_DEV_URANDOM;
} elseif (file_exists('/dev/random')) {
$method = MCRYPT_DEV_RANDOM;
} else {
$method = MCRYPT_RAND;
}
$method = MCRYPT_RAND;
}

$vector = mcrypt_create_iv($size, $method);
} else if (strlen($vector) != $size) {
throw new Exception\InvalidArgumentException('The given vector has a wrong size for the set algorithm');
Expand Down
14 changes: 2 additions & 12 deletions library/Zend/InfoCard/InfoCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,7 @@ protected function _extractSignedToken($strXmlToken)

$PKcipher = Cipher::getInstanceByURI($encryptedKey->getEncryptionMethod());

$base64DecodeSupportsStrictParam = version_compare(PHP_VERSION, '5.2.0', '>=');

if ($base64DecodeSupportsStrictParam) {
$keyCipherValueBase64Decoded = base64_decode($encryptedKey->getCipherValue(), true);
} else {
$keyCipherValueBase64Decoded = base64_decode($encryptedKey->getCipherValue());
}
$keyCipherValueBase64Decoded = base64_decode($encryptedKey->getCipherValue(), true);

$symmetricKey = $PKcipher->decrypt(
$keyCipherValueBase64Decoded,
Expand All @@ -373,11 +367,7 @@ protected function _extractSignedToken($strXmlToken)

$symCipher = Cipher::getInstanceByURI($encryptedData->getEncryptionMethod());

if ($base64DecodeSupportsStrictParam) {
$dataCipherValueBase64Decoded = base64_decode($encryptedData->getCipherValue(), true);
} else {
$dataCipherValueBase64Decoded = base64_decode($encryptedData->getCipherValue());
}
$dataCipherValueBase64Decoded = base64_decode($encryptedData->getCipherValue(), true);

$signedToken = $symCipher->decrypt($dataCipherValueBase64Decoded, $symmetricKey);

Expand Down
15 changes: 2 additions & 13 deletions library/Zend/InfoCard/XML/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,8 @@ static public function validateXMLSignature($strXMLInput)
break;
}

$base64DecodeSupportsStrictParam = version_compare(PHP_VERSION, '5.2.0', '>=');

if ($base64DecodeSupportsStrictParam) {
$dValue = base64_decode((string)$sxe->Signature->SignedInfo->Reference->DigestValue, true);
} else {
$dValue = base64_decode((string)$sxe->Signature->SignedInfo->Reference->DigestValue);
}

if ($base64DecodeSupportsStrictParam) {
$signatureValue = base64_decode((string)$sxe->Signature->SignatureValue, true);
} else {
$signatureValue = base64_decode((string)$sxe->Signature->SignatureValue);
}
$dValue = base64_decode((string)$sxe->Signature->SignedInfo->Reference->DigestValue, true);
$signatureValue = base64_decode((string)$sxe->Signature->SignatureValue, true);

$transformer = new Security\Transform\TransformChain();

Expand Down
8 changes: 1 addition & 7 deletions library/Zend/InfoCard/XML/SecurityTokenReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,7 @@ public function getKeyReference($decode = true)
$decoded = "";
switch($this->getKeyThumbprintEncodingType()) {
case self::ENCODING_BASE64BIN:

if(version_compare(PHP_VERSION, "5.2.0", ">=")) {
$decoded = base64_decode($encoded, true);
} else {
$decoded = base64_decode($encoded);
}

$decoded = base64_decode($encoded, true);
break;
default:
throw new Exception\RuntimeException("Unknown Key Reference Encoding Type: {$this->getKeyThumbprintEncodingType()}");
Expand Down
12 changes: 2 additions & 10 deletions library/Zend/View/Helper/Navigation/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,7 @@ protected function _xmlEscape($string)
$enc = $this->view->getEncoding();
}

// TODO: remove check when minimum PHP version is >= 5.2.3
if (version_compare(PHP_VERSION, '5.2.3', '>=')) {
// do not encode existing HTML entities
return htmlspecialchars($string, ENT_QUOTES, $enc, false);
} else {
$string = preg_replace('/&(?!(?:#\d++|[a-z]++);)/ui', '&amp;', $string);
$string = str_replace(array('<', '>', '\'', '"'), array('&lt;', '&gt;', '&#39;', '&quot;'), $string);
return $string;
}
return htmlspecialchars($string, ENT_QUOTES, $enc, false);
}

// Public methods:
Expand Down Expand Up @@ -316,7 +308,7 @@ public function url(AbstractPage $page)
$curDoc = $this->getView()->broker('url')->direct();
$curDoc = ('/' == $curDoc) ? '' : trim($curDoc, '/');
$url = rtrim($this->getServerUrl(), '/') . '/'
. $curDoc
. $curDoc
. (empty($curDoc) ? '' : '/') . $href;
}

Expand Down
10 changes: 4 additions & 6 deletions tests/Zend/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,11 @@ public function testLoadSingleSection()

public function testIsset()
{
if (version_compare(PHP_VERSION, '5.1', '>=')) {
$config = new Config($this->_all, false);
$config = new Config($this->_all, false);

$this->assertFalse(isset($config->notarealkey));
$this->assertTrue(isset($config->hostname)); // top level
$this->assertTrue(isset($config->db->name)); // one level down
}
$this->assertFalse(isset($config->notarealkey));
$this->assertTrue(isset($config->hostname)); // top level
$this->assertTrue(isset($config->db->name)); // one level down
}

public function testModification()
Expand Down
5 changes: 1 addition & 4 deletions tests/Zend/Db/Select/StaticTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function setup()
{
$this->markTestSkipped('This suite is skipped until Zend\DB can be refactored.');
}

/**
* Test basic use of the Zend_Db_Select class.
*
Expand Down Expand Up @@ -691,9 +691,6 @@ public function testSelectOrderByMultiplePositions()
*/
public function testPhp53Assembly()
{
if (version_compare(PHP_VERSION, 5.3) == -1 ) {
$this->markTestSkipped('This test needs at least PHP 5.3');
}
$select = $this->_db->select();
$select->from('table1', '*');
$select->joinLeft(array('table2'), 'table1.id=table2.id');
Expand Down
3 changes: 0 additions & 3 deletions tests/Zend/Db/Statement/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -804,9 +804,6 @@ public function testStatementGetColumnMeta()
$meta = $stmt->getColumnMeta($i);
$this->assertType('array', $meta);
foreach ($this->_getColumnMetaKeys as $key) {
if ($key == 'table' && version_compare(PHP_VERSION, '5.2.0', '<')) {
continue;
}
$this->assertContains($key, array_keys($meta));
}
}
Expand Down
50 changes: 19 additions & 31 deletions tests/Zend/InfoCard/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,52 +71,48 @@ public function testCertificatePairs()
$this->assertTrue(!empty($key_pair['private']));
$this->assertTrue(!empty($key_pair['type_uri']));
}

public function testGetCertificatePairThrowsExceptionOnMissingKeyId()
{
$this->requireMcryptAndOpensslOrSkip();
$infoCard = new InfoCard\InfoCard();
$key_id = $infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey);
$infoCard->removeCertificatePair($key_id);

$this->setExpectedException('Zend\InfoCard\Exception\InvalidArgumentException', 'Invalid Certificate Pair ID provided');
$key_pair = $infoCard->getCertificatePair($key_id);
}

public function testAddCertificatePairThrowsExceptionOnMissingCertificates()
{
$this->requireMcryptAndOpensslOrSkip();
$infoCard = new InfoCard\InfoCard();

$this->setExpectedException('Zend\InfoCard\Exception\InvalidArgumentException', 'Could not locate the public and private certificate pair files');
$infoCard->addCertificatePair("I don't exist", "I don't exist");
}

public function testAddCertificatePairThrowsExceptionOnDuplicateRegistration()
{
$this->requireMcryptAndOpensslOrSkip();
$infoCard = new InfoCard\InfoCard();
$key_id = $infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey, Cipher::ENC_RSA_OAEP_MGF1P, "foo");

$this->setExpectedException('Zend\InfoCard\Exception\InvalidArgumentException', 'Attempted to add previously existing certificate pair');
$key_id = $infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey, Cipher::ENC_RSA_OAEP_MGF1P, "foo");
}

public function testAddCertificatePairThrowsExceptionOnBadCipher()
{
$this->requireMcryptAndOpensslOrSkip();

$this->setExpectedException('Zend\InfoCard\Exception\InvalidArgumentException', 'Invalid Certificate Pair Type specified');
$infoCard = new InfoCard\InfoCard();
$infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey, "Doesn't Exist", "foo");
}

public function testStandAloneProcess()
{
if (version_compare(PHP_VERSION, '5.2.0', '<')) {
$this->markTestSkipped('DOMDocument::C14N() not available until PHP 5.2.0');
}

$this->requireMcryptAndOpensslOrSkip();
$infoCard = new InfoCard\InfoCard();

Expand All @@ -129,10 +125,6 @@ public function testStandAloneProcess()

public function testPlugins()
{
if (version_compare(PHP_VERSION, '5.2.0', '<')) {
$this->markTestSkipped('DOMDocument::C14N() not available until PHP 5.2.0');
}

$adapter = new TestAsset\MockAdapter();

$this->requireMcryptAndOpensslOrSkip();
Expand Down Expand Up @@ -165,12 +157,8 @@ public function testPlugins()

public function testClaims()
{
if (version_compare(PHP_VERSION, '5.2.0', '<')) {
$this->markTestSkipped('DOMDocument::C14N() not available until PHP 5.2.0');
}

$this->requireMcryptAndOpensslOrSkip();

$infoCard = new InfoCard\InfoCard();

$infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey);
Expand Down Expand Up @@ -200,25 +188,25 @@ public function testClaims()

$this->assertTrue(isset($claims->givenname));
}

public function testClaimsThrowExceptionOnUnset()
{
$this->requireMcryptAndOpensslOrSkip();
$this->requireMcryptAndOpensslOrSkip();
$infoCard = new InfoCard\InfoCard();
$infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey);
$claims = $infoCard->process($this->_xmlDocument);

$this->setExpectedException('Zend\InfoCard\Exception\InvalidArgumentException', 'Claim objects are read-only');
unset($claims->givenname);
}

public function testClaimsThrowsExceptionOnMutation()
{
$this->requireMcryptAndOpensslOrSkip();
$this->requireMcryptAndOpensslOrSkip();
$infoCard = new InfoCard\InfoCard();
$infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey);
$claims = $infoCard->process($this->_xmlDocument);

$this->setExpectedException('Zend\InfoCard\Exception\InvalidArgumentException', 'Claim objects are read-only');
$claims->givenname = "Test";
}
Expand All @@ -237,22 +225,22 @@ public function testTransforms()
$trans = new \Zend\InfoCard\XML\Security\Transform\TransformChain();
$this->assertTrue(is_array($trans->getTransformList()));
}

public function testTransformsThrowsExceptionOnInvalidInput()
{
$trans = new \Zend\InfoCard\XML\Security\Transform\TransformChain();

$this->setExpectedException('Zend\InfoCard\XML\Security\Exception\InvalidArgumentException', 'Unknown or Unsupported Transformation Requested');
$trans->addTransform("foo");
}

protected function requireMcryptAndOpensslOrSkip()
{
if (!extension_loaded('mcrypt') || !extension_loaded('openssl')) {
$this->markTestSkipped('Extension mcrypt and extension openssl are requred for this test');
}
}

}


Loading

0 comments on commit 721cd66

Please sign in to comment.