Author: chabotc
Date: Mon Mar 30 20:27:01 2009
New Revision: 760155

URL: http://svn.apache.org/viewvc?rev=760155&view=rev
Log:

1. remove dependency of GadgetContext when fetching remote content.
2. remove RemoteContentRequest->ignoreCache, use 
RemoteContentRequest->options->ignoreCache instead (will likely be changed to 
->setIgnoreCache very soon)
3. remove dependency of SecurityToken in SigningFetcher, use 
$request->getToken()

Now, we support multiFetch with mixed signed and normal requests:
   $request1 = new RemoteContentRequest('http://test.chabotc.com/signing.html');
   $token = BasicSecurityToken::createFromValues('owner', 'viewer', 'app', 
'domain', 'appUrl', '1', 'default');
   $request1->setToken($token);
   $request1->setAuthType(RemoteContentRequest::$AUTH_SIGNED);
   $request2 = new RemoteContentRequest('http://test.chabotc.com/ok.html');
   $requests = array($request1, $request2);
   $this->basicRemoteContent->multiFetch($requests);


Modified:
    incubator/shindig/trunk/php/src/common/RemoteContent.php
    incubator/shindig/trunk/php/src/common/RemoteContentRequest.php
    incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php
    incubator/shindig/trunk/php/src/gadgets/GadgetFactory.php
    incubator/shindig/trunk/php/src/gadgets/GadgetFeatureRegistry.php
    incubator/shindig/trunk/php/src/gadgets/MakeRequestHandler.php
    incubator/shindig/trunk/php/src/gadgets/ProxyBase.php
    incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php
    incubator/shindig/trunk/php/src/gadgets/SigningFetcher.php
    incubator/shindig/trunk/php/src/gadgets/SigningFetcherFactory.php
    incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php

Modified: incubator/shindig/trunk/php/src/common/RemoteContent.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/RemoteContent.php?rev=760155&r1=760154&r2=760155&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/RemoteContent.php (original)
+++ incubator/shindig/trunk/php/src/common/RemoteContent.php Mon Mar 30 
20:27:01 2009
@@ -32,9 +32,9 @@
 
 abstract class RemoteContent {
 
-  abstract public function fetch(RemoteContentRequest $request, GadgetContext 
$context);
+  abstract public function fetch(RemoteContentRequest $request);
 
-  abstract public function multiFetch(Array $requests, Array $contexts);
+  abstract public function multiFetch(Array $requests);
   
   abstract public function invalidate(RemoteContentRequest $request);
 }

Modified: incubator/shindig/trunk/php/src/common/RemoteContentRequest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/RemoteContentRequest.php?rev=760155&r1=760154&r2=760155&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/RemoteContentRequest.php (original)
+++ incubator/shindig/trunk/php/src/common/RemoteContentRequest.php Mon Mar 30 
20:27:01 2009
@@ -32,7 +32,6 @@
   private $responseHeaders = false;
   private $httpCode = false;
   private $contentType = null;
-  private $options;
   private $created;
   private $refreshInterval;
   private static $SC_OK = 200; //Please, use only for testing!
@@ -40,6 +39,11 @@
   public static $DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded; 
charset=utf-8";
 
   /**
+   * @var Options
+   */
+  private $options;
+  
+  /**
    * @var SecurityToken
    */
   private $token;
@@ -113,18 +117,6 @@
     $this->createRemoteContentRequest("GET", $uri, null, null, 
RemoteContentRequest::getDefaultOptions());
   }
 
-  /**
-   * Creates a simple GET request
-   *
-   * @param uri
-   * @param ignoreCache
-   */
-  public function getRequest($uri, $ignoreCache) {
-    $options = new Options();
-    $options->ignoreCache = $ignoreCache;
-    return $this->createRemoteContentRequestWithUriOptions($uri, $options);
-  }
-
   // returns a hash code which identifies this request, used for caching
   // takes url and postbody into account for constructing the sha1 checksum
   public function toHash() {
@@ -187,9 +179,12 @@
     $this->method = $method;
   }
 
+  /**
+   * @return Options
+   */
   public function getOptions() {
     if (empty($this->options)) {
-      return new Options();
+      $this->options = new Options();
     }
     return $this->options;
   }

Modified: incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php?rev=760155&r1=760154&r2=760155&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php 
(original)
+++ incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php Mon 
Mar 30 20:27:01 2009
@@ -61,33 +61,34 @@
     $this->basicFetcher = $basicFetcher;
   }
 
-  public function fetch(RemoteContentRequest $request, GadgetContext $context) 
{
-    if (! $context->getIgnoreCache() && ! $request->isPost() && 
($cachedRequest = $this->cache->get($request->toHash())) !== false && 
$this->invalidateService->isValid($cachedRequest)) {
+  public function fetch(RemoteContentRequest $request) {
+    $ignoreCache = $request->getOptions()->ignoreCache;
+    if (!$ignoreCache && ! $request->isPost() && ($cachedRequest = 
$this->cache->get($request->toHash())) !== false && 
$this->invalidateService->isValid($cachedRequest)) {
       $request = $cachedRequest;
     } else {
       $originalRequest = clone $request;
       $request = $this->divertFetch($request);
-      if ($request->getHttpCode() != 200 && ! $context->getIgnoreCache() && ! 
$request->isPost()) {
+      if ($request->getHttpCode() != 200 && !$ignoreCache && 
!$request->isPost()) {
         $cachedRequest = $this->cache->expiredGet($request->toHash());
         if ($cachedRequest['found'] == true) {
           return $cachedRequest['data'];
         }
       }
-      $this->setRequestCache($originalRequest, $request, $this->cache, 
$context);
+      $this->setRequestCache($originalRequest, $request, $this->cache);
     }
     return $request;
   }
 
-  public function multiFetch(Array $requests, Array $contexts) {
+  public function multiFetch(Array $requests) {
     $rets = array();
     $requestsToProc = array();
     foreach ($requests as $request) {
-      list(, $context) = each($contexts);
       if (! ($request instanceof RemoteContentRequest)) {
         throw new RemoteContentException("Invalid request type in 
remoteContent");
       }
+      $ignoreCache = $request->getOptions()->ignoreCache;
       // determine which requests we can load from cache, and which we have to 
actually fetch
-      if (! $context->getIgnoreCache() && ! $request->isPost() && 
($cachedRequest = $this->cache->get($request->toHash())) !== false && 
$this->invalidateService->isValid($cachedRequest)) {
+      if (!$ignoreCache && !$request->isPost() && ($cachedRequest = 
$this->cache->get($request->toHash())) !== false && 
$this->invalidateService->isValid($cachedRequest)) {
         $rets[] = $cachedRequest;
       } else {
         $originalRequest = clone $request;
@@ -97,16 +98,37 @@
     }
 
     if ($requestsToProc) {
-      $newRets = $this->basicFetcher->multiFetchRequest($requestsToProc);
-      foreach ($newRets as $request) {
+      $normal = array();
+      $signing = array();
+      foreach ($requestsToProc as $request) {
+        switch ($request->getAuthType()) {
+          case RemoteContentRequest::$AUTH_SIGNED:
+            $signing[] = $request;
+            break;
+          case RemoteContentRequest::$AUTH_OAUTH:
+            // We do not allow multi fetch oauth content.
+            break;
+          default:
+            $normal[] = $request;
+        }
+      }
+      if ($signing) {
+        $signingFetcher = 
$this->signingFetcherFactory->getSigningFetcher($this->basicFetcher);
+        $signingFetcher->multiFetchRequest($signing);
+      }
+      if ($normal) {
+        $this->basicFetcher->multiFetchRequest($normal);
+      }
+      foreach ($requestsToProc as $request) {
         list(, $originalRequest) = each($originalRequestArray);
-        if ($request->getHttpCode() != 200 && ! $context->getIgnoreCache() && 
! $request->isPost()) {
+        $ignoreCache = $request->getOptions()->ignoreCache;
+        if ($request->getHttpCode() != 200 && !$ignoreCache && 
!$request->isPost()) {
           $cachedRequest = $this->cache->expiredGet($request->toHash());
           if ($cachedRequest['found'] == true) {
             $rets[] = $cachedRequest['data'];
           }
         } else {
-          $this->setRequestCache($originalRequest, $request, $this->cache, 
$context);
+          $this->setRequestCache($originalRequest, $request, $this->cache);
           $rets[] = $request;
         }
       }
@@ -118,8 +140,9 @@
     $this->cache->invalidate($request->toHash());
   }
 
-  private function setRequestCache(RemoteContentRequest $originalRequest, 
RemoteContentRequest $request, Cache $cache, GadgetContext $context) {
-    if (! $request->isPost() && ! $context->getIgnoreCache()) {
+  private function setRequestCache(RemoteContentRequest $originalRequest, 
RemoteContentRequest $request, Cache $cache) {
+    $ignoreCache = $originalRequest->getOptions()->ignoreCache;
+    if (!$request->isPost() && !$ignoreCache) {
       $ttl = Config::get('cache_time');
       if ($request->getHttpCode() == '200') {
         // Got a 200 OK response, calculate the TTL to use for caching it
@@ -156,13 +179,12 @@
   private function divertFetch(RemoteContentRequest $request) {
     switch ($request->getAuthType()) {
       case RemoteContentRequest::$AUTH_SIGNED:
-        $token = $request->getToken();
-        $fetcher = 
$this->signingFetcherFactory->getSigningFetcher($this->basicFetcher, $token);
+        $fetcher = 
$this->signingFetcherFactory->getSigningFetcher($this->basicFetcher);
         return $fetcher->fetchRequest($request);
       case RemoteContentRequest::$AUTH_OAUTH:
         $params = new OAuthRequestParams();
         $token = $request->getToken();
-        $fetcher = 
$this->signingFetcherFactory->getSigningFetcher($this->basicFetcher, $token);
+        $fetcher = 
$this->signingFetcherFactory->getSigningFetcher($this->basicFetcher);
         $oAuthFetcherFactory = new OAuthFetcherFactory($fetcher);
         $oauthFetcher = $oAuthFetcherFactory->getOAuthFetcher($fetcher, 
$token, $params);
         return $oauthFetcher->fetch($request);

Modified: incubator/shindig/trunk/php/src/gadgets/GadgetFactory.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetFactory.php?rev=760155&r1=760154&r2=760155&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetFactory.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetFactory.php Mon Mar 30 
20:27:01 2009
@@ -24,6 +24,9 @@
  *
  */
 class GadgetFactory {
+  /**
+   * @var GadgetContext
+   */
   private $context;
   private $token;
 
@@ -184,7 +187,7 @@
    */
   private function fetchResources(Gadget &$gadget) {
     $contextLocale = $this->context->getLocale();
-    $unsignedRequests = $unsignedContexts = $signedRequests = $signedContexts 
= array();
+    $unsignedRequests = $signedRequests = array();
     foreach ($gadget->getLocales() as $key => $locale) {
       // Only fetch the locales that match the current context's language and 
country
       if (($locale['country'] == 'all' && $locale['lang'] == 'all') || 
($locale['lang'] == $contextLocale['lang'] && $locale['country'] == 'all') || 
($locale['lang'] == $contextLocale['lang'] && $locale['country'] == 
$contextLocale['country'])) {
@@ -214,13 +217,13 @@
     foreach ($unsignedRequests as $key => $requestUrl) {
       $request = new RemoteContentRequest($requestUrl);
       $request->createRemoteContentRequestWithUri($requestUrl);
+      $request->getOptions()->ignoreCache = $this->context->getIgnoreCache();
       $unsignedRequests[$key] = $request;
-      $unsignedContexts[$key] = $this->context;
     }
     $responses = array();
     if (count($unsignedRequests)) {
       $brc = new BasicRemoteContent();
-      $resps = $brc->multiFetch($unsignedRequests, $unsignedContexts);
+      $resps = $brc->multiFetch($unsignedRequests);
       foreach ($resps as $response) {
         $responses[$response->getUrl()] = array(
             'body' => $response->getResponseContent(),
@@ -232,12 +235,12 @@
       $request = new RemoteContentRequest($requestUrl);
       $request->setAuthType(RemoteContentRequest::$AUTH_SIGNED);
       $request->setNotSignedUri($requestUrl);
+      $request->getOptions()->ignoreCache = $this->context->getIgnoreCache();
       $signedRequests[$key] = $request;
-      $signedContexts[$key] = $this->context;
     }
     if (count($signedRequests)) {
       $remoteContent = new BasicRemoteContent(new BasicRemoteContentFetcher(), 
$signingFetcherFactory);
-      $resps = $remoteContent->multiFetch($signedRequests,$signedContexts);
+      $resps = $remoteContent->multiFetch($signedRequests);
       foreach ($resps as $response) {
         $responses[$response->getNotSignedUrl()] = array(
             'body' => $response->getResponseContent(),
@@ -297,7 +300,8 @@
   protected function fetchGadget($gadgetUrl) {
     $request = new RemoteContentRequest($gadgetUrl);
     $request->setToken($this->token);
-    $xml = $this->context->getHttpFetcher()->fetch($request, $this->context);
+    $request->getOptions()->ignoreCache = $this->context->getIgnoreCache();
+    $xml = $this->context->getHttpFetcher()->fetch($request);
     if ($xml->getHttpCode() != '200') {
       throw new GadgetException("Failed to retrieve gadget content (recieved 
http code " . $xml->getHttpCode() . ")");
     }

Modified: incubator/shindig/trunk/php/src/gadgets/GadgetFeatureRegistry.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetFeatureRegistry.php?rev=760155&r1=760154&r2=760155&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetFeatureRegistry.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetFeatureRegistry.php Mon Mar 
30 20:27:01 2009
@@ -55,7 +55,8 @@
       switch ($entry['type']) {
         case 'URL':
           $request = new RemoteContentRequest($entry['content']);
-          $context->getHttpFetcher()->fetch($request, $context);
+          $request->getOptions()->ignoreCache = $context->getIgnoreCache();
+          $context->getHttpFetcher()->fetch($request);
           if ($request->getHttpCode() == '200') {
             $ret .= $request->getResponseContent()."\n";
           }

Modified: incubator/shindig/trunk/php/src/gadgets/MakeRequestHandler.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/MakeRequestHandler.php?rev=760155&r1=760154&r2=760155&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/MakeRequestHandler.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/MakeRequestHandler.php Mon Mar 30 
20:27:01 2009
@@ -88,7 +88,8 @@
     $basicFetcher = new BasicRemoteContentFetcher();
     $basicRemoteContent = new BasicRemoteContent($basicFetcher, 
$this->signingFetcherFactory, $signer);
     $request = $this->buildRequest($url, $method, $signer);
-    return $basicRemoteContent->fetch($request, $this->context);
+    $request->getOptions()->ignoreCache = $this->context->getIgnoreCache();
+    return $basicRemoteContent->fetch($request);
   }
 
   /**

Modified: incubator/shindig/trunk/php/src/gadgets/ProxyBase.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/ProxyBase.php?rev=760155&r1=760154&r2=760155&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/ProxyBase.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/ProxyBase.php Mon Mar 30 20:27:01 
2009
@@ -39,7 +39,7 @@
    * @param string $url the url to fetch
    * @param string $method http method
    * @param SecurityTokenDecoder $signer
-   * @return the filled in request (RemoteContentRequest)
+   * @return RemoteContentRequest the filled in request (RemoteContentRequest)
    */
   protected function buildRequest($url, $method = 'GET', $signer = null) {
     // Check the protocol requested - curl doesn't really support file://

Modified: incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php?rev=760155&r1=760154&r2=760155&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php Mon Mar 30 
20:27:01 2009
@@ -35,7 +35,8 @@
   public function fetch($url) {
     $url = $this->validateUrl($url);
     $request = $this->buildRequest($url, 'GET');
-    $result = $this->context->getHttpFetcher()->fetch($request, 
$this->context);
+    $request->getOptions()->ignoreCache = $this->context->getIgnoreCache();
+    $result = $this->context->getHttpFetcher()->fetch($request);
     $httpCode = (int)$result->getHttpCode();
     $isShockwaveFlash = false;
     foreach ($result->getResponseHeaders() as $key => $val) {

Modified: incubator/shindig/trunk/php/src/gadgets/SigningFetcher.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/SigningFetcher.php?rev=760155&r1=760154&r2=760155&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/SigningFetcher.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/SigningFetcher.php Mon Mar 30 
20:27:01 2009
@@ -36,12 +36,6 @@
   protected static $ALLOWED_PARAM_NAME = '^[-_[:alnum:]]+$';
 
   /**
-   * Authentication token for the user and gadget making the request.
-   * @var SecurityToken
-   */
-  protected $authToken;
-
-  /**
    * Private key we pass to the OAuth RSA_SHA1 algorithm.This can be a
    * PrivateKey object, or a PEM formatted private key, or a DER encoded byte
    * array for the private key.(No, really, they accept any of them.)
@@ -58,42 +52,44 @@
    */
   private $fetcher;
 
-  /**
-   * Constructor based on signing with the given PrivateKey object.
-   *
-   * @param authToken verified gadget security token
-   * @param keyName name of the key to include in the request
-   * @param privateKey the key to use for the signing
+  /**
+   * Constructor based on signing with the given PrivateKey object.
+   *
+   * @param RemoteContentFetcher $fetcher
+   * @param keyName name of the key to include in the request
+   * @param privateKey the key to use for the signing
+   * @return SigningFetcher
    */
-  public static function makeFromPrivateKey(RemoteContentFetcher $fetcher, 
SecurityToken $authToken, $keyName, $privateKey) {
-    return new SigningFetcher($fetcher, $authToken, $keyName, $privateKey);
+  public static function makeFromPrivateKey(RemoteContentFetcher $fetcher, 
$keyName, $privateKey) {
+    return new SigningFetcher($fetcher, $keyName, $privateKey);
   }
 
-  /**
-   * Constructor based on signing with the given PrivateKey object.
-   *
-   * @param authToken verified gadget security token
-   * @param keyName name of the key to include in the request
-   * @param privateKey base64 encoded private key
+  /**
+   * Constructor based on signing with the given PrivateKey object.
+   *
+   * @param RemoteContentFetcher $fetcher
+   * @param keyName name of the key to include in the request
+   * @param privateKey base64 encoded private key
+   * @return SigningFetcher
    */
-  public static function makeFromB64PrivateKey(RemoteContentFetcher $fetcher, 
SecurityToken $authToken, $keyName, $privateKey) {
-    return new SigningFetcher($fetcher, $authToken, $keyName, $privateKey);
+  public static function makeFromB64PrivateKey(RemoteContentFetcher $fetcher, 
$keyName, $privateKey) {
+    return new SigningFetcher($fetcher, $keyName, $privateKey);
   }
 
   /**
    * Constructor based on signing with the given PrivateKey object.
    *
-   * @param authToken verified gadget security token
-   * @param keyName name of the key to include in the request
-   * @param privateKey DER encoded private key
+   * @param RemoteContentFetcher $fetcher
+   * @param keyName name of the key to include in the request
+   * @param privateKey DER encoded private key
+   * @return SigningFetcher
    */
-  public static function makeFromPrivateKeyBytes(RemoteContentFetcher 
$fetcher, SecurityToken $authToken, $keyName, $privateKey) {
-    return new SigningFetcher($fetcher, $authToken, $keyName, $privateKey);
+  public static function makeFromPrivateKeyBytes(RemoteContentFetcher 
$fetcher, $keyName, $privateKey) {
+    return new SigningFetcher($fetcher, $keyName, $privateKey);
   }
 
-  protected function __construct(RemoteContentFetcher $fetcher, SecurityToken 
$authToken, $keyName, $privateKeyObject) {
+  protected function __construct(RemoteContentFetcher $fetcher, $keyName, 
$privateKeyObject) {
     $this->fetcher = $fetcher;
-    $this->authToken = $authToken;
     $this->keyName = $keyName;
     $this->privateKeyObject = $privateKeyObject;
   }
@@ -105,7 +101,7 @@
 
   public function multiFetchRequest(Array $requests) {
     foreach ($requests as $request) {
-      $this->signRequest($requests);
+      $this->signRequest($request);
     }
     return $this->fetcher->multiFetchRequest($requests);
   }
@@ -137,8 +133,8 @@
       $msgParams = array();
       $msgParams = array_merge($msgParams, $queryParams);
       $msgParams = array_merge($msgParams, $postParams);
-      $this->addOpenSocialParams($msgParams);
-      $this->addOAuthParams($msgParams);
+      $this->addOpenSocialParams($msgParams, $request->getToken());
+      $this->addOAuthParams($msgParams, $request->getToken());
       $consumer = new OAuthConsumer(NULL, NULL, NULL);
       $consumer->setProperty(OAuthSignatureMethod_RSA_SHA1::$PRIVATE_KEY, 
$this->privateKeyObject);
       $signatureMethod = new OAuthSignatureMethod_RSA_SHA1();
@@ -191,24 +187,24 @@
     }
   }
 
-  private function addOpenSocialParams(&$msgParams) {
-    $owner = $this->authToken->getOwnerId();
+  private function addOpenSocialParams(&$msgParams, SecurityToken $token) {
+    $owner = $token->getOwnerId();
     if ($owner != null) {
       $msgParams[SigningFetcher::$OPENSOCIAL_OWNERID] = $owner;
     }
-    $viewer = $this->authToken->getViewerId();
+    $viewer = $token->getViewerId();
     if ($viewer != null) {
       $msgParams[SigningFetcher::$OPENSOCIAL_VIEWERID] = $viewer;
     }
-    $app = $this->authToken->getAppId();
+    $app = $token->getAppId();
     if ($app != null) {
       $msgParams[SigningFetcher::$OPENSOCIAL_APPID] = $app;
     }
   }
 
-  private function addOAuthParams(&$msgParams) {
+  private function addOAuthParams(&$msgParams, SecurityToken $token) {
     $msgParams[OAuth::$OAUTH_TOKEN] = '';
-    $domain = $this->authToken->getDomain();
+    $domain = $token->getDomain();
     if ($domain != null) {
       $msgParams[OAuth::$OAUTH_CONSUMER_KEY] = $domain;
     }

Modified: incubator/shindig/trunk/php/src/gadgets/SigningFetcherFactory.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/SigningFetcherFactory.php?rev=760155&r1=760154&r2=760155&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/SigningFetcherFactory.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/SigningFetcherFactory.php Mon Mar 
30 20:27:01 2009
@@ -29,13 +29,12 @@
    * Produces a signing fetcher that will sign requests and delegate actual
    * network retrieval to the {...@code networkFetcher}
    *
-   * @param networkFetcher The fetcher that will be doing actual work.
-   * @param token The gadget token used for extracting signing parameters.
-   * @return The signing fetcher.
+   * @param RemoteContentFetcher $networkFetcher The fetcher that will be 
doing actual work.
+   * @return SigningFetcher
    * @throws GadgetException
    */
-  public function getSigningFetcher($networkFetcher, $token) {
-    return SigningFetcher::makeFromB64PrivateKey($networkFetcher, $token, 
$this->keyName, $this->privateKey);
+  public function getSigningFetcher(RemoteContentFetcher $networkFetcher) {
+    return SigningFetcher::makeFromB64PrivateKey($networkFetcher, 
$this->keyName, $this->privateKey);
   }
 
   /**

Modified: incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php?rev=760155&r1=760154&r2=760155&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php 
(original)
+++ incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php Mon Mar 
30 20:27:01 2009
@@ -86,6 +86,17 @@
       } else {
         $request->setHttpCode(404);
       }
+    } else if (strpos($request->getUrl(), 
'http://test.chabotc.com/signing.html') == 0) {
+      $url = parse_url($request->getUrl());
+      $query = array();
+      parse_str($url['query'], $query);
+      $request->setHttpCode(200);
+      $request->setContentType('text/html; charset=UTF-8');
+      if ($query['xoauth_signature_publickey'] && $query['oauth_signature']) {
+        $request->setResponseContent('OK');
+      } else {
+        $request->setResponseContent('FAILED');
+      }
     }
   }
 }
@@ -111,7 +122,8 @@
   protected function setUp() {
     parent::setUp();
     $this->fetcher = new MockRemoteContentFetcher();
-    $this->basicRemoteContent = new BasicRemoteContent($this->fetcher);
+    $signingFetcherFactory = new 
SigningFetcherFactory(Config::get("private_key_file"));
+    $this->basicRemoteContent = new BasicRemoteContent($this->fetcher, 
$signingFetcherFactory, new BasicSecurityTokenDecoder());
   }
 
   /**
@@ -136,8 +148,7 @@
    */
   public function testFetch() {
     $request = new RemoteContentRequest('http://test.chabotc.com/ok.html');
-    $context = new TestContext();
-    $ret = $this->basicRemoteContent->fetch($request, $context);
+    $ret = $this->basicRemoteContent->fetch($request);
     $content = $ret->getResponseContent();
     $this->assertEquals("OK", trim($content));
   }
@@ -147,8 +158,7 @@
    */
   public function testFetch404() {
     $request = new RemoteContentRequest('http://test.chabotc.com/fail.html');
-    $context = new TestContext();
-    $ret = $this->basicRemoteContent->fetch($request, $context);
+    $ret = $this->basicRemoteContent->fetch($request);
     $this->assertEquals('404', $ret->getHttpCode());
   }
   
@@ -158,19 +168,17 @@
   public function testFetchValid() {
     $this->fetcher->clean();
     $request = new RemoteContentRequest('http://test.chabotc.com/valid0.html');
-    $context = new TestContext();
     $this->basicRemoteContent->invalidate($request);
     $this->fetcher->expectFetchRequest($request);
-    $ret = $this->basicRemoteContent->fetch($request, $context);
+    $ret = $this->basicRemoteContent->fetch($request);
     $this->assertTrue($this->fetcher->verify());
     $content = $ret->getResponseContent();
     $this->assertEquals("OK", trim($content));
     
     $request = new RemoteContentRequest('http://test.chabotc.com/valid0.html');
-    $context = new TestContext();
     $this->basicRemoteContent->invalidate($request);
     $this->fetcher->expectFetchRequest($request);
-    $ret = $this->basicRemoteContent->fetch($request, $context);
+    $ret = $this->basicRemoteContent->fetch($request);
     $this->assertTrue($this->fetcher->verify());
     $content = $ret->getResponseContent();
     $this->assertEquals("OK", trim($content));
@@ -183,18 +191,14 @@
     $this->fetcher->clean();
     
     $requests = array();
-    $contexts = array();
     $requests[] = new 
RemoteContentRequest('http://test.chabotc.com/valid1.html');
     $requests[] = new 
RemoteContentRequest('http://test.chabotc.com/valid2.html');
     $requests[] = new 
RemoteContentRequest('http://test.chabotc.com/valid3.html');
-    $contexts[] = new TestContext();
-    $contexts[] = new TestContext();
-    $contexts[] = new TestContext();
     $this->basicRemoteContent->invalidate($requests[0]);
     $this->basicRemoteContent->invalidate($requests[1]);
     $this->basicRemoteContent->invalidate($requests[2]);
     $this->fetcher->expectMultiFetchRequest($requests);
-    $rets = $this->basicRemoteContent->multiFetch($requests, $contexts);
+    $rets = $this->basicRemoteContent->multiFetch($requests);
     $this->assertTrue($this->fetcher->verify());
     $content_0 = $rets[0]->getResponseContent();
     $content_1 = $rets[1]->getResponseContent();
@@ -209,14 +213,11 @@
     $requests[] = new 
RemoteContentRequest('http://test.chabotc.com/valid1.html');
     $requests[] = new 
RemoteContentRequest('http://test.chabotc.com/valid2.html');
     $requests[] = new 
RemoteContentRequest('http://test.chabotc.com/valid3.html');
-    $contexts[] = new TestContext();
-    $contexts[] = new TestContext();
-    $contexts[] = new TestContext();
     $this->basicRemoteContent->invalidate($requests[0]);
     $this->basicRemoteContent->invalidate($requests[1]);
     $this->basicRemoteContent->invalidate($requests[2]);
     $this->fetcher->expectMultiFetchRequest($requests);
-    $rets = $this->basicRemoteContent->multiFetch($requests, $contexts);
+    $rets = $this->basicRemoteContent->multiFetch($requests);
     $this->assertTrue($this->fetcher->verify());
     $content_0 = $rets[0]->getResponseContent();
     $content_1 = $rets[1]->getResponseContent();
@@ -234,15 +235,11 @@
    */
   public function testMultiFetch() {
     $requests = array();
-    $contexts = array();
     $requests[] = new RemoteContentRequest('http://test.chabotc.com/ok.html');
     $requests[] = new RemoteContentRequest('http://test.chabotc.com/ok.html');
     $requests[] = new RemoteContentRequest('http://test.chabotc.com/ok.html');
-    $contexts[] = new TestContext();
-    $contexts[] = new TestContext();
-    $contexts[] = new TestContext();
 
-    $rets = $this->basicRemoteContent->multiFetch($requests, $contexts);
+    $rets = $this->basicRemoteContent->multiFetch($requests);
     $content_0 = $rets[0]->getResponseContent();
     $content_1 = $rets[1]->getResponseContent();
     $content_2 = $rets[2]->getResponseContent();
@@ -259,15 +256,11 @@
    */
   public function testMultiFetchMix() {
     $requests = array();
-    $contexts = array();
     $requests[] = new RemoteContentRequest('http://test.chabotc.com/ok.html');
     $requests[] = new RemoteContentRequest('http://test.chabotc.com/ok.html');
     $requests[] = new 
RemoteContentRequest('http://test.chabotc.com/fail.html');
-    $contexts[] = new TestContext();
-    $contexts[] = new TestContext();
-    $contexts[] = new TestContext();
 
-    $rets = $this->basicRemoteContent->multiFetch($requests, $contexts);
+    $rets = $this->basicRemoteContent->multiFetch($requests);
     $content_0 = $rets[0]->getResponseContent();
     $content_1 = $rets[1]->getResponseContent();
     $this->assertEquals("OK", trim($content_0));
@@ -282,49 +275,29 @@
    */
   public function testMultiFetch404() {
     $requests = array();
-    $contexts = array();
     $requests[] = new 
RemoteContentRequest('http://test.chabotc.com/fail.html');
     $requests[] = new 
RemoteContentRequest('http://test.chabotc.com/fail.html');
     $requests[] = new 
RemoteContentRequest('http://test.chabotc.com/fail.html');
-    $contexts[] = new TestContext();
-    $contexts[] = new TestContext();
-    $contexts[] = new TestContext();
-    $rets = $this->basicRemoteContent->multiFetch($requests, $contexts);
+    $rets = $this->basicRemoteContent->multiFetch($requests);
     $this->assertEquals('404', $rets[0]->getHttpCode());
     $this->assertEquals('404', $rets[1]->getHttpCode());
     $this->assertEquals('404', $rets[2]->getHttpCode());
   }
 
   /**
-   * Tests BasicRemoteContent->fetch.
-   */
-  public function testFeedFetch() {
-    $fetcher = new BasicRemoteContentFetcher();
-    $this->basicRemoteContent->setBasicFetcher($fetcher);
-    $request = new 
RemoteContentRequest('http://adwordsapi.blogspot.com/atom.xml');
-    $context = new TestContext();
-    $ret = $this->basicRemoteContent->fetch($request, $context);
-    $content = $ret->getResponseContent();
-    $this->assertNotEquals(null, $content);
-  }
-
-
-  /**
    * Tests BasicRemoteContent->invalidate()
    */
   public function testInvalidate() {
     // Fetches url for the first time.
     $request = new RemoteContentRequest('http://test.chabotc.com/ok.html');
-    $context = new TestContext();
-    $ret = $this->basicRemoteContent->fetch($request, $context);
+    $ret = $this->basicRemoteContent->fetch($request);
     $this->fetcher->clean();
     $content = $ret->getResponseContent();
     $this->assertEquals("OK", trim($content));
 
     // Fetches url again and $this->fetcher->fetchRequest will not be called.
     $request = new RemoteContentRequest('http://test.chabotc.com/ok.html');
-    $context = new TestContext();
-    $ret = $this->basicRemoteContent->fetch($request, $context);
+    $ret = $this->basicRemoteContent->fetch($request);
     $this->assertTrue($this->fetcher->verify());
     $content = $ret->getResponseContent();
     $this->assertEquals("OK", trim($content));
@@ -332,12 +305,30 @@
     // Invalidates cache and fetches url.
     // $this->fetcher->fetchRequest will be called.
     $request = new RemoteContentRequest('http://test.chabotc.com/ok.html');
-    $context = new TestContext();
     $this->fetcher->expectFetchRequest($request);
     $this->basicRemoteContent->invalidate($request);
-    $ret = $this->basicRemoteContent->fetch($request, $context);
+    $ret = $this->basicRemoteContent->fetch($request);
     $this->assertTrue($this->fetcher->verify());
     $content = $ret->getResponseContent();
     $this->assertEquals("OK", trim($content));
   }
+  
+  /**
+   * Tests through SigningFetcher
+   */
+  public function testSigningFetch() {
+    $request1 = new 
RemoteContentRequest('http://test.chabotc.com/signing.html');
+    $token = BasicSecurityToken::createFromValues('owner', 'viewer', 'app', 
'domain', 'appUrl', '1', 'default');
+    $request1->setToken($token);
+    $request1->setAuthType(RemoteContentRequest::$AUTH_SIGNED);
+    $request2 = new RemoteContentRequest('http://test.chabotc.com/ok.html');
+    $this->basicRemoteContent->invalidate($request1);
+    $this->basicRemoteContent->invalidate($request2);
+    $requests = array($request1, $request2);
+    $this->basicRemoteContent->multiFetch($requests);
+    $content = $request1->getResponseContent();
+    $this->assertEquals("OK", trim($content));
+    $content = $request2->getResponseContent();
+    $this->assertEquals("OK", trim($content));
+  }
 }


Reply via email to