@Test public void testGetProxySimple() throws Exception { List<String> fields = ImmutableList.of("proxyurl"); Uri resUri = Uri.parse("server.com/gadgets/proxy?url=" + RESOURCE); GadgetsHandlerApi.ProxyRequest request = createProxyRequest(RESOURCE, CONTAINER, fields); Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); expect(proxyUriManager.make(capture(uriCapture), EasyMock.anyInt())).andReturn( ImmutableList.of(resUri)); replay(); GadgetsHandlerApi.ProxyResponse response = gadgetHandler.getProxy(request); assertEquals(1, uriCapture.getValue().size()); ProxyUri pUri = uriCapture.getValue().get(0); assertEquals(CONTAINER, pUri.getContainer()); assertEquals(resUri, response.getProxyUrl()); assertNull(response.getProxyContent()); assertEquals(timeSource.currentTimeMillis() + HttpUtil.getDefaultTtl() * 1000, response .getExpireTimeMs().longValue()); verify(); }
@Test public void testGetProxySimple() throws Exception { List<String> fields = ImmutableList.of("proxyurl"); Uri resUri = Uri.parse("server.com/gadgets/proxy?url=" + RESOURCE); GadgetsHandlerApi.ProxyRequest request = createProxyRequest(RESOURCE, CONTAINER, fields); Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); expect(proxyUriManager.make(capture(uriCapture), EasyMock.anyInt())).andReturn( ImmutableList.of(resUri)); replay(); GadgetsHandlerApi.ProxyResponse response = gadgetHandler.getProxy(request); assertEquals(1, uriCapture.getValue().size()); ProxyUri pUri = uriCapture.getValue().get(0); assertEquals(CONTAINER, pUri.getContainer()); assertEquals(resUri, response.getProxyUrl()); assertNull(response.getProxyContent()); assertEquals(timeSource.currentTimeMillis() + HttpUtil.getDefaultTtl() * 1000, response .getExpireTimeMs().longValue()); verify(); }
@Test public void testGetProxyEmptyData() throws Exception { List<String> fields = ImmutableList.of("proxycontent.*"); Uri resUri = Uri.parse("server.com/gadgets/proxy?url=" + RESOURCE); GadgetsHandlerApi.ProxyRequest request = createProxyRequest(RESOURCE, CONTAINER, fields); Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); expect(proxyUriManager.make(capture(uriCapture), EasyMock.anyInt())).andReturn( ImmutableList.of(resUri)); HttpResponse httpResponse = new HttpResponseBuilder().setHttpStatusCode(504).create(); expect(proxyHandler.fetch(EasyMock.isA(ProxyUri.class))).andReturn(httpResponse); replay(); GadgetsHandlerApi.ProxyResponse response = gadgetHandler.getProxy(request); assertEquals(1, uriCapture.getValue().size()); ProxyUri pUri = uriCapture.getValue().get(0); assertEquals(CONTAINER, pUri.getContainer()); assertNull(response.getProxyUrl()); assertEquals("", response.getProxyContent().getContentBase64()); assertEquals(504, response.getProxyContent().getCode()); verify(); }
private void checkValidate(String path, UriStatus status, String version) throws Exception { String host = "host.com"; // Pass null for status if version is null, since null version shouldn't result // in a check to the versioner. ProxyUriManager.Versioner versioner = makeVersioner(version == null ? null : status, version); DefaultProxyUriManager manager = makeManager(host, path, versioner); Gadget gadget = mockGadget(false, false); List<Uri> resources = ImmutableList.of(RESOURCE_1); List<Uri> uris = manager.make( ProxyUriManager.ProxyUri.fromList(gadget, resources), 123); assertEquals(1, uris.size()); ProxyUriManager.ProxyUri proxyUri = manager.process(uris.get(0)); assertEquals(RESOURCE_1, proxyUri.getResource()); assertEquals(CONTAINER, proxyUri.getContainer()); assertEquals(SPEC_URI.toString(), proxyUri.getGadget()); assertEquals(123, (int)proxyUri.getRefresh()); assertEquals(status, proxyUri.getStatus()); assertEquals(false, proxyUri.isDebug()); assertEquals(false, proxyUri.isNoCache()); }
@Test public void testGetProxyEmptyData() throws Exception { List<String> fields = ImmutableList.of("proxycontent.*"); Uri resUri = Uri.parse("server.com/gadgets/proxy?url=" + RESOURCE); GadgetsHandlerApi.ProxyRequest request = createProxyRequest(RESOURCE, CONTAINER, fields); Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); expect(proxyUriManager.make(capture(uriCapture), EasyMock.anyInt())).andReturn( ImmutableList.of(resUri)); HttpResponse httpResponse = new HttpResponseBuilder().setHttpStatusCode(504).create(); expect(proxyHandler.fetch(EasyMock.isA(ProxyUri.class))).andReturn(httpResponse); replay(); GadgetsHandlerApi.ProxyResponse response = gadgetHandler.getProxy(request); assertEquals(1, uriCapture.getValue().size()); ProxyUri pUri = uriCapture.getValue().get(0); assertEquals(CONTAINER, pUri.getContainer()); assertNull(response.getProxyUrl()); assertEquals("", response.getProxyContent().getContentBase64()); assertEquals(504, response.getProxyContent().getCode()); verify(); }
private void checkValidate(String path, UriStatus status, String version) throws Exception { String host = "host.com"; // Pass null for status if version is null, since null version shouldn't result // in a check to the versioner. ProxyUriManager.Versioner versioner = makeVersioner(version == null ? null : status, version); DefaultProxyUriManager manager = makeManager(host, path, versioner); Gadget gadget = mockGadget(false, false); List<Uri> resources = ImmutableList.of(RESOURCE_1); List<Uri> uris = manager.make( ProxyUriManager.ProxyUri.fromList(gadget, resources), 123); assertEquals(1, uris.size()); ProxyUriManager.ProxyUri proxyUri = manager.process(uris.get(0)); assertEquals(RESOURCE_1, proxyUri.getResource()); assertEquals(CONTAINER, proxyUri.getContainer()); assertEquals(SPEC_URI.toString(), proxyUri.getGadget()); assertEquals(123, (int)proxyUri.getRefresh()); assertEquals(status, proxyUri.getStatus()); assertEquals(false, proxyUri.isDebug()); assertEquals(false, proxyUri.isNoCache()); }
@Test public void containerFallsBackToSynd() throws Exception { String host = "host.com"; String path = "/path"; DefaultProxyUriManager manager = makeManager(host, path, null); UriBuilder uriBuilder = new UriBuilder(); uriBuilder.setScheme("http").setAuthority(host).setPath(path); uriBuilder.addQueryParameter(Param.URL.getKey(), RESOURCE_1.toString()); uriBuilder.addQueryParameter("synd", CONTAINER); uriBuilder.addQueryParameter(Param.GADGET.getKey(), SPEC_URI.toString()); uriBuilder.addQueryParameter(Param.REFRESH.getKey(), "321"); ProxyUriManager.ProxyUri proxyUri = manager.process(uriBuilder.toUri()); assertEquals(RESOURCE_1, proxyUri.getResource()); assertEquals(CONTAINER, proxyUri.getContainer()); assertEquals(SPEC_URI.toString(), proxyUri.getGadget()); assertEquals(321, (int)proxyUri.getRefresh()); assertEquals(false, proxyUri.isDebug()); assertEquals(false, proxyUri.isNoCache()); }
private void verifyQueryUriWithRefresh(Uri orig, Uri uri, boolean debug, boolean noCache, String version, Integer refresh, String host, String path) throws Exception { // Make sure the manager can parse out results. DefaultProxyUriManager manager = makeManager(host, path, null); ProxyUri proxyUri = manager.process(uri); assertEquals(orig, proxyUri.getResource()); assertEquals(debug, proxyUri.isDebug()); assertEquals(noCache, proxyUri.isNoCache()); assertEquals(noCache ? Integer.valueOf(0) : refresh, proxyUri.getRefresh()); assertEquals(CONTAINER, proxyUri.getContainer()); assertEquals(SPEC_URI.toString(), proxyUri.getGadget()); // "Raw" query param verification. assertEquals(noCache || refresh == null ? null : refresh.toString(), uri.getQueryParameter(Param.REFRESH.getKey())); if (version != null) { assertEquals(version, uri.getQueryParameter(Param.VERSION.getKey())); } }
private void verifyQueryUriWithRefresh(Uri orig, Uri uri, boolean debug, boolean noCache, String version, Integer refresh, String host, String path) throws Exception { // Make sure the manager can parse out results. DefaultProxyUriManager manager = makeManager(host, path, null); ProxyUri proxyUri = manager.process(uri); assertEquals(orig, proxyUri.getResource()); assertEquals(debug, proxyUri.isDebug()); assertEquals(noCache, proxyUri.isNoCache()); assertEquals(noCache ? Integer.valueOf(0) : refresh, proxyUri.getRefresh()); assertEquals(CONTAINER, proxyUri.getContainer()); assertEquals(SPEC_URI.toString(), proxyUri.getGadget()); // "Raw" query param verification. assertEquals(noCache || refresh == null ? null : refresh.toString(), uri.getQueryParameter(Param.REFRESH.getKey())); if (version != null) { assertEquals(version, uri.getQueryParameter(Param.VERSION.getKey())); } }
@Test public void containerFallsBackToSynd() throws Exception { String host = "host.com"; String path = "/path"; DefaultProxyUriManager manager = makeManager(host, path, null); UriBuilder uriBuilder = new UriBuilder(); uriBuilder.setScheme("http").setAuthority(host).setPath(path); uriBuilder.addQueryParameter(Param.URL.getKey(), RESOURCE_1.toString()); uriBuilder.addQueryParameter("synd", CONTAINER); uriBuilder.addQueryParameter(Param.GADGET.getKey(), SPEC_URI.toString()); uriBuilder.addQueryParameter(Param.REFRESH.getKey(), "321"); ProxyUriManager.ProxyUri proxyUri = manager.process(uriBuilder.toUri()); assertEquals(RESOURCE_1, proxyUri.getResource()); assertEquals(CONTAINER, proxyUri.getContainer()); assertEquals(SPEC_URI.toString(), proxyUri.getGadget()); assertEquals(321, (int)proxyUri.getRefresh()); assertEquals(false, proxyUri.isDebug()); assertEquals(false, proxyUri.isNoCache()); }
private void verifyQueryUriWithRefresh(Uri orig, Uri uri, boolean debug, boolean noCache, String version, Integer refresh, String host, String path) throws Exception { // Make sure the manager can parse out results. DefaultProxyUriManager manager = makeManager(host, path, null); ProxyUri proxyUri = manager.process(uri); assertEquals(orig, proxyUri.getResource()); assertEquals(debug, proxyUri.isDebug()); assertEquals(noCache, proxyUri.isNoCache()); assertEquals(noCache ? Integer.valueOf(0) : refresh, proxyUri.getRefresh()); assertEquals(CONTAINER, proxyUri.getContainer()); assertEquals(SPEC_URI.toString(), proxyUri.getGadget()); // "Raw" query param verification. assertEquals(noCache || refresh == null ? null : refresh.toString(), uri.getQueryParameter(Param.REFRESH.getKey())); if (version != null) { assertEquals(version, uri.getQueryParameter(Param.VERSION.getKey())); } }
@Test public void testProxyGadgetsChainGif() throws Exception { String host = "host.com"; String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN; DefaultProxyUriManager uriManager = makeManager(host, path, null); Uri uri = Uri.parse("http://host.com/gadgets/proxy/container=container&" + "gadget=http%3A%2F%2Fwww.orkut.com%2Fcss%2Fgen%2Fbase054.css.int&" + "debug=0&nocache=0/http://www.orkut.com/img/castro/i_reply.gif"); ProxyUri pUri = uriManager.process(uri); assertEquals(false, pUri.isDebug()); assertEquals("http://www.orkut.com/img/castro/i_reply.gif", pUri.getResource().toString()); assertEquals(CONTAINER, pUri.getContainer()); assertEquals("http://www.orkut.com/css/gen/base054.css.int", pUri.getGadget()); }
@Test public void testProxyGadgetsChainDecodeGif() throws Exception { String host = "host.com"; String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN; DefaultProxyUriManager uriManager = makeManager(host, path, null); Uri uri = Uri.parse("http://host.com/gadgets/proxy/container%3dcontainer%26" + "gadget%3dhttp%3A%2F%2Fwww.orkut.com%2Fcss%2Fgen%2Fbase054.css.int%26" + "debug%3d0%26nocache%3d0/http://www.orkut.com/img/castro/i%5freply.gif"); ProxyUri pUri = uriManager.process(uri); assertEquals(false, pUri.isDebug()); assertEquals("http://www.orkut.com/img/castro/i%5freply.gif", pUri.getResource().toString()); assertEquals(CONTAINER, pUri.getContainer()); assertEquals("http://www.orkut.com/css/gen/base054.css.int", pUri.getGadget()); }
@Test public void testProxyGadgetsChainDecodeGif() throws Exception { String host = "host.com"; String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN; DefaultProxyUriManager uriManager = makeManager(host, path, null); Uri uri = Uri.parse("http://host.com/gadgets/proxy/container%3dcontainer%26" + "gadget%3dhttp%3A%2F%2Fwww.orkut.com%2Fcss%2Fgen%2Fbase054.css.int%26" + "debug%3d0%26nocache%3d0/http://www.orkut.com/img/castro/i%5freply.gif"); ProxyUri pUri = uriManager.process(uri); assertEquals(false, pUri.isDebug()); assertEquals("http://www.orkut.com/img/castro/i%5freply.gif", pUri.getResource().toString()); assertEquals(CONTAINER, pUri.getContainer()); assertEquals("http://www.orkut.com/css/gen/base054.css.int", pUri.getGadget()); }
@Test public void testProxyGadgetsChainGif() throws Exception { String host = "host.com"; String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN; DefaultProxyUriManager uriManager = makeManager(host, path, null); Uri uri = Uri.parse("http://host.com/gadgets/proxy/container=container&" + "gadget=http%3A%2F%2Fwww.orkut.com%2Fcss%2Fgen%2Fbase054.css.int&" + "debug=0&nocache=0/http://www.orkut.com/img/castro/i_reply.gif"); ProxyUri pUri = uriManager.process(uri); assertEquals(false, pUri.isDebug()); assertEquals("http://www.orkut.com/img/castro/i_reply.gif", pUri.getResource().toString()); assertEquals(CONTAINER, pUri.getContainer()); assertEquals("http://www.orkut.com/css/gen/base054.css.int", pUri.getGadget()); }
@Test public void testProxyGadgetsChainDecodeGif() throws Exception { String host = "host.com"; String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN; DefaultProxyUriManager uriManager = makeManager(host, path, null); Uri uri = Uri.parse("http://host.com/gadgets/proxy/container%3dcontainer%26" + "gadget%3dhttp%3A%2F%2Fwww.orkut.com%2Fcss%2Fgen%2Fbase054.css.int%26" + "debug%3d0%26nocache%3d0/http://www.orkut.com/img/castro/i%5freply.gif"); ProxyUri pUri = uriManager.process(uri); assertEquals(false, pUri.isDebug()); assertEquals("http://www.orkut.com/img/castro/i%5freply.gif", pUri.getResource().toString()); assertEquals(CONTAINER, pUri.getContainer()); assertEquals("http://www.orkut.com/css/gen/base054.css.int", pUri.getGadget()); }
@Test public void testProxyGadgetsChainGif() throws Exception { String host = "host.com"; String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN; DefaultProxyUriManager uriManager = makeManager(host, path, null); Uri uri = Uri.parse("http://host.com/gadgets/proxy/container=container&" + "gadget=http%3A%2F%2Fwww.orkut.com%2Fcss%2Fgen%2Fbase054.css.int&" + "debug=0&nocache=0/http://www.orkut.com/img/castro/i_reply.gif"); ProxyUri pUri = uriManager.process(uri); assertEquals(false, pUri.isDebug()); assertEquals("http://www.orkut.com/img/castro/i_reply.gif", pUri.getResource().toString()); assertEquals(CONTAINER, pUri.getContainer()); assertEquals("http://www.orkut.com/css/gen/base054.css.int", pUri.getGadget()); }
@Test public void testProxyGadgetsChainDecode() throws Exception { String host = "host.com"; String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN; DefaultProxyUriManager uriManager = makeManager(host, path, null); Uri uri = Uri.parse("http://host.com/gadgets/proxy/refresh%3d55%26container%3dcontainer/" + "http://www.cnn.com/news?refresh=45"); ProxyUri pUri = uriManager.process(uri); assertEquals(new Integer(55), pUri.getRefresh()); assertEquals("http://www.cnn.com/news?refresh=45", pUri.getResource().toString()); assertEquals(CONTAINER, pUri.getContainer()); }
@Test public void testProxyGadgetsChainDecode() throws Exception { String host = "host.com"; String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN; DefaultProxyUriManager uriManager = makeManager(host, path, null); Uri uri = Uri.parse("http://host.com/gadgets/proxy/refresh%3d55%26container%3dcontainer/" + "http://www.cnn.com/news?refresh=45"); ProxyUri pUri = uriManager.process(uri); assertEquals(new Integer(55), pUri.getRefresh()); assertEquals("http://www.cnn.com/news?refresh=45", pUri.getResource().toString()); assertEquals(CONTAINER, pUri.getContainer()); }
@Test public void testProxyGadgetsChainDecode() throws Exception { String host = "host.com"; String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN; DefaultProxyUriManager uriManager = makeManager(host, path, null); Uri uri = Uri.parse("http://host.com/gadgets/proxy/refresh%3d55%26container%3dcontainer/" + "http://www.cnn.com/news?refresh=45"); ProxyUri pUri = uriManager.process(uri); assertEquals(new Integer(55), pUri.getRefresh()); assertEquals("http://www.cnn.com/news?refresh=45", pUri.getResource().toString()); assertEquals(CONTAINER, pUri.getContainer()); }