Pārlūkot izejas kodu

fixes ZF-5217 where invalid filename causes infinite loop.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18630 44c647ce-9c0f-0410-b52a-842ac1e357ba
klassicd 16 gadi atpakaļ
vecāks
revīzija
cdaa5d2c16
2 mainītis faili ar 23 papildinājumiem un 1 dzēšanām
  1. 6 1
      library/Zend/Gdata/HttpClient.php
  2. 17 0
      tests/Zend/Gdata/AuthSubTest.php

+ 6 - 1
library/Zend/Gdata/HttpClient.php

@@ -96,7 +96,12 @@ class Zend_Gdata_HttpClient extends Zend_Http_Client
      */
     public function setAuthSubPrivateKeyFile($file, $passphrase = null,
                                              $useIncludePath = false) {
-        $fp = fopen($file, "r", $useIncludePath);
+        $fp = @fopen($file, "r", $useIncludePath);
+        if (!$fp) {
+        	require_once 'Zend/Gdata/App/InvalidArgumentException.php';
+        	throw new Zend_Gdata_App_InvalidArgumentException('Failed to open private key file for AuthSub.');
+        }
+        
         $key = '';
         while (!feof($fp)) {
             $key .= fread($fp, 8192);

+ 17 - 0
tests/Zend/Gdata/AuthSubTest.php

@@ -20,6 +20,11 @@
  * @version    $Id $
  */
 
+/**
+ * Test helper
+ */
+require_once dirname(__FILE__) . '/../../TestHelper.php';
+
 require_once 'Zend/Gdata/AuthSub.php';
 require_once 'Zend/Gdata/HttpClient.php';
 
@@ -113,4 +118,16 @@ class Zend_Gdata_AuthSubTest extends PHPUnit_Framework_TestCase
                                 'Auth header not found for sig verification.');
         }
     }
+    
+    public function testPrivateKeyNotFound()
+    {
+    	$this->setExpectedException('Zend_Gdata_App_InvalidArgumentException');
+    	
+        if (!extension_loaded('openssl')) {
+            $this->markTestSkipped('The openssl extension is not available');
+        } else {
+            $c = new Zend_Gdata_HttpClient();
+            $c->setAuthSubPrivateKeyFile("zendauthsubfilenotfound",  null, true);
+        }
+    }
 }