You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by rb...@apache.org on 2011/10/02 21:44:15 UTC

svn commit: r1178236 [4/4] - in /shindig/trunk: config/ content/samplecontainer/examples/commoncontainer/ features/src/main/javascript/features/container.util/ features/src/main/javascript/features/container/ features/src/main/javascript/features/rpc/ ...

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyHandlerTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyHandlerTest.java?rev=1178236&r1=1178235&r2=1178236&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyHandlerTest.java (original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyHandlerTest.java Sun Oct  2 19:44:13 2011
@@ -18,17 +18,21 @@
  */
 package org.apache.shindig.gadgets.servlet;
 
-import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
 
 import org.apache.shindig.common.EasyMockTestCase;
 import org.apache.shindig.common.uri.Uri;
 import org.apache.shindig.common.util.FakeTimeSource;
 import org.apache.shindig.config.ContainerConfig;
 import org.apache.shindig.gadgets.Gadget;
-import org.apache.shindig.gadgets.GadgetBlacklist;
 import org.apache.shindig.gadgets.GadgetException;
+import org.apache.shindig.gadgets.admin.GadgetAdminStore;
 import org.apache.shindig.gadgets.http.HttpRequest;
 import org.apache.shindig.gadgets.http.HttpResponse;
 import org.apache.shindig.gadgets.http.HttpResponseBuilder;
@@ -44,15 +48,11 @@ import org.apache.shindig.gadgets.uri.Pr
 import org.apache.shindig.gadgets.uri.UriCommon.Param;
 import org.easymock.Capture;
 import org.easymock.EasyMock;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.isA;
-
 import org.junit.Test;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
 
 public class ProxyHandlerTest extends EasyMockTestCase {
   private final static String GADGET = "http://some/gadget.xml";
@@ -62,19 +62,18 @@ public class ProxyHandlerTest extends Ea
 
 
   public final RequestPipeline pipeline = mock(RequestPipeline.class);
-  private GadgetBlacklist gadgetBlacklist = mock(GadgetBlacklist.class); 
+  private GadgetAdminStore gadgetAdminStore = mock(GadgetAdminStore.class);
   public CaptureRewriter rewriter = new CaptureRewriter();
   public ResponseRewriterRegistry rewriterRegistry
       = new DefaultResponseRewriterRegistry(Arrays.<ResponseRewriter>asList(rewriter), null);
   private ProxyUriManager.ProxyUri request;
 
   private final ProxyHandler proxyHandler
-      = new ProxyHandler(pipeline, rewriterRegistry, true, gadgetBlacklist, LONG_LIVED_REFRESH);
+      = new ProxyHandler(pipeline, rewriterRegistry, true, gadgetAdminStore, LONG_LIVED_REFRESH);
 
   private void expectGetAndReturnData(String url, byte[] data) throws Exception {
     HttpRequest req = new HttpRequest(Uri.parse(url));
     HttpResponse resp = new HttpResponseBuilder().setResponse(data).create();
-    expect(gadgetBlacklist.isBlacklisted(isA(Uri.class))).andReturn(false);
     expect(pipeline.execute(req)).andReturn(resp);
   }
 
@@ -82,10 +81,14 @@ public class ProxyHandlerTest extends Ea
       throws Exception {
     HttpRequest req = new HttpRequest(Uri.parse(url));
     HttpResponse resp = new HttpResponseBuilder().addAllHeaders(headers).create();
-    expect(gadgetBlacklist.isBlacklisted(isA(Uri.class))).andReturn(false);
     expect(pipeline.execute(req)).andReturn(resp);
   }
-  
+
+  private void setupGadgetAdminMock(boolean isWhitelisted) {
+    expect(gadgetAdminStore.isWhitelisted(isA(String.class), isA(String.class)))
+    .andReturn(isWhitelisted);
+  }
+
   private void setupProxyRequestMock(String host, String url,
       boolean noCache, int refresh, String rewriteMime, String fallbackUrl) throws Exception {
     request = new ProxyUriManager.ProxyUri(
@@ -120,31 +123,31 @@ public class ProxyHandlerTest extends Ea
   }
 
   @Test
-  public void testBlacklistedGadget() throws Exception {
+  public void testNonWhitelistedGadget() throws Exception {
     String url = "http://example.org/mypage.html";
     String domain = "example.org";
-    String gadget = "http://blacklisted/gadget.xml";
     setupProxyRequestMock(domain, url, true, -1, null, null);
-    expect(gadgetBlacklist.isBlacklisted(isA(Uri.class))).andReturn(true);
+    setupGadgetAdminMock(false);
     replay();
     boolean exceptionCaught = false;
     try {
       proxyHandler.fetch(request);
     } catch (GadgetException e) {
       exceptionCaught = true;
-      assertEquals(GadgetException.Code.BLACKLISTED_GADGET, e.getCode());
+      assertEquals(GadgetException.Code.NON_WHITELISTED_GADGET, e.getCode());
       assertEquals(HttpResponse.SC_FORBIDDEN, e.getHttpStatusCode());
     }
     assertTrue(exceptionCaught);
     verify();
   }
-  
+
   @Test
   public void testInvalidHeaderDropped() throws Exception {
     String url = "http://example.org/mypage.html";
     String domain = "example.org";
 
     setupProxyRequestMock(domain, url, true, -1, null, null);
+    setupGadgetAdminMock(true);
 
     HttpRequest req = new HttpRequest(Uri.parse(url))
         .setIgnoreCache(true);
@@ -172,7 +175,7 @@ public class ProxyHandlerTest extends Ea
   public void testLockedDomainEmbed() throws Exception {
     setupNoArgsProxyRequestMock("www.example.com", URL_ONE);
     expectGetAndReturnData(URL_ONE, DATA_ONE.getBytes());
-
+    setupGadgetAdminMock(true);
     replay();
     HttpResponse response = proxyHandler.fetch(request);
     verify();
@@ -193,6 +196,7 @@ public class ProxyHandlerTest extends Ea
   @Test
   public void testHttpRequestFillsParentAndContainer() throws Exception {
     setupNoArgsProxyRequestMock("www.example.com", URL_ONE);
+    setupGadgetAdminMock(true);
     //HttpRequest req = new HttpRequest(Uri.parse(URL_ONE));
     HttpResponse resp = new HttpResponseBuilder().setResponse(DATA_ONE.getBytes()).create();
 
@@ -223,6 +227,7 @@ public class ProxyHandlerTest extends Ea
     headers.put("X-Magic-Garbage", Arrays.asList(magicGarbage));
 
     setupNoArgsProxyRequestMock(domain, url);
+    setupGadgetAdminMock(true);
     expectGetAndReturnHeaders(url, headers);
 
     replay();
@@ -240,6 +245,7 @@ public class ProxyHandlerTest extends Ea
     String domain = "example.org";
 
     setupNoArgsProxyRequestMock(domain, url);
+    setupGadgetAdminMock(true);
     expectGetAndReturnHeaders(url, Maps.<String, List<String>>newHashMap());
 
     replay();
@@ -253,11 +259,13 @@ public class ProxyHandlerTest extends Ea
 
   @Test
   public void testNoContentDispositionForFlash() throws Exception {
+    setupGadgetAdminMock(true);
     assertNoContentDispositionForFlash("application/x-shockwave-flash");
   }
 
   @Test
   public void testNoContentDispositionForFlashUtf8() throws Exception {
+    setupGadgetAdminMock(true);
     assertNoContentDispositionForFlash("application/x-shockwave-flash;charset=utf-8");
   }
 
@@ -287,6 +295,7 @@ public class ProxyHandlerTest extends Ea
     String fallback_url = "http://fallback.com/fallback.png";
 
     setupProxyRequestMock(domain, url, true, -1, null, fallback_url);
+    setupGadgetAdminMock(true);
 
     HttpRequest req = new HttpRequest(Uri.parse(url)).setIgnoreCache(true);
     HttpResponse resp = HttpResponse.error();
@@ -305,6 +314,7 @@ public class ProxyHandlerTest extends Ea
     String domain = "example.org";
 
     setupProxyRequestMock(domain, url, true, -1, null, null);
+    setupGadgetAdminMock(true);
 
     HttpRequest req = new HttpRequest(Uri.parse(url)).setIgnoreCache(true);
     HttpResponse resp = new HttpResponse("Hello");
@@ -322,6 +332,7 @@ public class ProxyHandlerTest extends Ea
     String domain = "example.org";
 
     setupProxyRequestMock(domain, url, true, -1, null, null);
+    setupGadgetAdminMock(true);
 
     String contentType = "text/html; charset=UTF-8";
     HttpResponse resp = new HttpResponseBuilder()
@@ -329,7 +340,6 @@ public class ProxyHandlerTest extends Ea
         .addHeader("Content-Type", contentType)
         .create();
 
-    expect(gadgetBlacklist.isBlacklisted(isA(Uri.class))).andReturn(false);
     expect(pipeline.execute((HttpRequest) EasyMock.anyObject())).andReturn(resp);
 
     replay();
@@ -340,7 +350,7 @@ public class ProxyHandlerTest extends Ea
     ResponseRewriterRegistry rewriterRegistry =
         new DefaultResponseRewriterRegistry(
             Arrays.<ResponseRewriter>asList(rewriter), null);
-    ProxyHandler proxyHandler = new ProxyHandler(pipeline, rewriterRegistry, true, gadgetBlacklist,
+    ProxyHandler proxyHandler = new ProxyHandler(pipeline, rewriterRegistry, true, gadgetAdminStore,
         LONG_LIVED_REFRESH);
 
     request.setReturnOriginalContentOnError(true);
@@ -361,6 +371,7 @@ public class ProxyHandlerTest extends Ea
     String domain = "example.org";
 
     setupProxyRequestMock(domain, url, true, -1, null, null);
+    setupGadgetAdminMock(true);
 
     String contentType = "text/html; charset=UTF-8";
     HttpResponse resp = new HttpResponseBuilder()
@@ -368,7 +379,6 @@ public class ProxyHandlerTest extends Ea
         .addHeader("Content-Type", contentType)
         .create();
 
-    expect(gadgetBlacklist.isBlacklisted(isA(Uri.class))).andReturn(false);
     expect(pipeline.execute((HttpRequest) EasyMock.anyObject())).andReturn(resp);
 
     replay();
@@ -379,7 +389,7 @@ public class ProxyHandlerTest extends Ea
     ResponseRewriterRegistry rewriterRegistry =
         new DefaultResponseRewriterRegistry(
             Arrays.<ResponseRewriter>asList(rewriter), null);
-    ProxyHandler proxyHandler = new ProxyHandler(pipeline, rewriterRegistry, true, gadgetBlacklist,
+    ProxyHandler proxyHandler = new ProxyHandler(pipeline, rewriterRegistry, true, gadgetAdminStore,
         LONG_LIVED_REFRESH);
 
     boolean exceptionCaught = false;
@@ -427,6 +437,7 @@ public class ProxyHandlerTest extends Ea
     HttpResponse.setTimeSource(new FakeTimeSource());
 
     setupProxyRequestMock(domain, url, false, 120, null, null);
+    setupGadgetAdminMock(true);
 
     HttpRequest req = new HttpRequestCache(Uri.parse(url)).setCacheTtl(120).setIgnoreCache(false);
     HttpResponseBuilder resp = new HttpResponseBuilder().setCacheTtl(1234);
@@ -446,6 +457,7 @@ public class ProxyHandlerTest extends Ea
     HttpResponse.setTimeSource(new FakeTimeSource());
 
     setupProxyRequestMock(domain, url, false, -1, null, null);
+    setupGadgetAdminMock(true);
 
     HttpRequest req = new HttpRequestCache(Uri.parse(url)).setCacheTtl(-1).setIgnoreCache(false);
     HttpResponseBuilder resp = new HttpResponseBuilder().setCacheTtl(1234);
@@ -465,6 +477,7 @@ public class ProxyHandlerTest extends Ea
     String domain = "example.org";
 
     setupProxyRequestMock(domain, url, false, -1, expectedMime, null);
+    setupGadgetAdminMock(true);
 
     HttpRequest req = new HttpRequest(Uri.parse(url))
         .setRewriteMimeType(expectedMime);

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/templates/tags/TemplateBasedTagHandlerTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/templates/tags/TemplateBasedTagHandlerTest.java?rev=1178236&r1=1178235&r2=1178236&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/templates/tags/TemplateBasedTagHandlerTest.java (original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/templates/tags/TemplateBasedTagHandlerTest.java Sun Oct  2 19:44:13 2011
@@ -18,10 +18,18 @@
  */
 package org.apache.shindig.gadgets.templates.tags;
 
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import javax.el.ELResolver;
+
 import org.apache.shindig.common.PropertiesModule;
 import org.apache.shindig.expressions.RootELResolver;
+import org.apache.shindig.gadgets.DefaultGuiceModule;
 import org.apache.shindig.gadgets.Gadget;
 import org.apache.shindig.gadgets.GadgetException;
+import org.apache.shindig.gadgets.admin.GadgetAdminModule;
 import org.apache.shindig.gadgets.oauth.OAuthModule;
 import org.apache.shindig.gadgets.parse.DefaultHtmlSerializer;
 import org.apache.shindig.gadgets.parse.GadgetHtmlParser;
@@ -29,12 +37,6 @@ import org.apache.shindig.gadgets.parse.
 import org.apache.shindig.gadgets.templates.TagRegistry;
 import org.apache.shindig.gadgets.templates.TemplateContext;
 import org.apache.shindig.gadgets.templates.TemplateProcessor;
-import org.apache.shindig.gadgets.DefaultGuiceModule;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import static org.junit.Assert.assertEquals;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -44,8 +46,9 @@ import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
-import javax.el.ELResolver;
-import java.io.IOException;
+import com.google.common.collect.ImmutableSet;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
 
 /**
  * Tests the behavior of template-based tag handlers.
@@ -61,7 +64,8 @@ public class TemplateBasedTagHandlerTest
   
   @Before
   public void setUp() throws Exception {
-    Injector injector = Guice.createInjector(new DefaultGuiceModule(), new OAuthModule(), new PropertiesModule());
+    Injector injector = Guice.createInjector(new GadgetAdminModule(), new DefaultGuiceModule(),
+            new OAuthModule(), new PropertiesModule());
     parser = injector.getInstance(GadgetHtmlParser.class);
     processor = injector.getInstance(TemplateProcessor.class);
     context = new TemplateContext(new Gadget(), null);

Modified: shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/integration/JpaTestGuiceModule.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/integration/JpaTestGuiceModule.java?rev=1178236&r1=1178235&r2=1178236&view=diff
==============================================================================
--- shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/integration/JpaTestGuiceModule.java (original)
+++ shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/integration/JpaTestGuiceModule.java Sun Oct  2 19:44:13 2011
@@ -20,9 +20,12 @@ package org.apache.shindig.social.openso
 
 import javax.persistence.EntityManager;
 
+import net.oauth.OAuthConsumer;
+
 import org.apache.shindig.auth.SecurityToken;
 import org.apache.shindig.common.PropertiesModule;
 import org.apache.shindig.gadgets.DefaultGuiceModule;
+import org.apache.shindig.gadgets.admin.GadgetAdminModule;
 import org.apache.shindig.gadgets.oauth.OAuthModule;
 import org.apache.shindig.social.core.config.SocialApiGuiceModule;
 import org.apache.shindig.social.opensocial.jpa.AccountDb;
@@ -53,8 +56,6 @@ import org.apache.shindig.social.opensoc
 
 import com.google.inject.AbstractModule;
 
-import net.oauth.OAuthConsumer;
-
 /**
  * Provides component injection for tests
  * Injects Social API and JPA persistence guice modules
@@ -75,6 +76,7 @@ public class JpaTestGuiceModule extends 
   @Override
   protected void configure() {
     install(new PropertiesModule());
+    install(new GadgetAdminModule());
     install(new DefaultGuiceModule());
     install(new SocialApiGuiceModule());
     install(new OAuthModule());

Modified: shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml?rev=1178236&r1=1178235&r2=1178236&view=diff
==============================================================================
--- shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml (original)
+++ shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml Sun Oct  2 19:44:13 2011
@@ -38,7 +38,8 @@
       org.apache.shindig.common.cache.ehcache.EhCacheModule:
       org.apache.shindig.sample.shiro.ShiroGuiceModule:
       org.apache.shindig.sample.container.SampleContainerGuiceModule:
-      org.apache.shindig.extras.ShindigExtrasGuiceModule
+      org.apache.shindig.extras.ShindigExtrasGuiceModule:
+      org.apache.shindig.gadgets.admin.GadgetAdminModule
     </param-value>
   </context-param>
 

Modified: shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndServer.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndServer.java?rev=1178236&r1=1178235&r2=1178236&view=diff
==============================================================================
--- shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndServer.java (original)
+++ shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndServer.java Sun Oct  2 19:44:13 2011
@@ -22,6 +22,7 @@ import org.apache.shindig.auth.Authentic
 import org.apache.shindig.common.PropertiesModule;
 import org.apache.shindig.common.servlet.GuiceServletContextListener;
 import org.apache.shindig.gadgets.DefaultGuiceModule;
+import org.apache.shindig.gadgets.admin.GadgetAdminModule;
 import org.apache.shindig.gadgets.oauth.OAuthModule;
 import org.apache.shindig.gadgets.servlet.ConcatProxyServlet;
 import org.apache.shindig.gadgets.servlet.GadgetRenderingServlet;
@@ -122,7 +123,8 @@ public class EndToEndServer {
     Map<String, String> initParams = Maps.newHashMap();
     String modules = Joiner.on(":")
         .join(SocialApiGuiceModule.class.getName(),
-              SampleModule.class.getName(), 
+              SampleModule.class.getName(),
+              GadgetAdminModule.class.getName(),
               DefaultGuiceModule.class.getName(),
               PropertiesModule.class.getName(), 
               OAuthModule.class.getName()