You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by ch...@apache.org on 2009/05/12 15:07:20 UTC

svn commit: r773877 - /incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php

Author: chabotc
Date: Tue May 12 13:07:20 2009
New Revision: 773877

URL: http://svn.apache.org/viewvc?rev=773877&view=rev
Log:
SHINDIG-1056 by lipeng, BasicRemoteContentTest doesn't depend on static private key file

Modified:
    incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php

Modified: incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php?rev=773877&r1=773876&r2=773877&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php (original)
+++ incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php Tue May 12 13:07:20 2009
@@ -22,6 +22,38 @@
 
 require_once 'external/PHPUnit/Framework/TestCase.php';
 
+class MockSigningFetcherFactory {
+  private $keyName;
+  private $privateKey;
+
+  /**
+   * Produces a signing fetcher that will sign requests and delegate actual
+   * network retrieval to the {@code networkFetcher}
+   *
+   * @param RemoteContentFetcher $networkFetcher The fetcher that will be doing actual work.
+   * @return SigningFetcher
+   * @throws GadgetException
+   */
+  public function getSigningFetcher(RemoteContentFetcher $networkFetcher) {
+    return SigningFetcher::makeFromB64PrivateKey($networkFetcher, $this->keyName, $this->privateKey);
+  }
+
+  /**
+   * @here will create a private key.
+   */
+  public function __construct() {
+    $privkey = openssl_pkey_new();
+    openssl_pkey_export($privkey, $rsa_private_key, "partuza"); //the string must be same as shindig container private_key_phrase
+    
+    $phrase = Config::get('private_key_phrase') != '' ? (Config::get('private_key_phrase')) : null;
+    if (! $rsa_private_key = @openssl_pkey_get_private($rsa_private_key, $phrase)) {
+      throw new Exception("Could not create the key");
+    }
+    $this->privateKey = $rsa_private_key;
+    $this->keyName = 'http://' . $_SERVER["HTTP_HOST"] . Config::get('web_prefix') . '/public.cer';
+  }
+}
+
 class MockRemoteContentFetcher extends RemoteContentFetcher {
   private $expectedRequest = array();
 
@@ -122,7 +154,7 @@
   protected function setUp() {
     parent::setUp();
     $this->fetcher = new MockRemoteContentFetcher();
-    $signingFetcherFactory = new SigningFetcherFactory(Config::get("private_key_file"));
+    $signingFetcherFactory = new MockSigningFetcherFactory();
     $this->basicRemoteContent = new BasicRemoteContent($this->fetcher, $signingFetcherFactory, new BasicSecurityTokenDecoder());
   }
 
@@ -189,7 +221,6 @@
    */
   public function testmultiFetchValid() {
     $this->fetcher->clean();
-    
     $requests = array();
     $requests[] = new RemoteContentRequest('http://test.chabotc.com/valid1.html');
     $requests[] = new RemoteContentRequest('http://test.chabotc.com/valid2.html');