@Test public void testDoGetWithOAuth() throws Exception { Map<String, String> options = new HashMap<String, String>(); options.put("OAUTH_SERVICE_NAME", "example"); ProxyUriManager.ProxyUri proxyUri = new ProxyUri(-1, false, true, "default", "http://example.org/gadget.xml", REQUEST_URL); proxyUri.setAuthType(AuthType.OAUTH); Uri uri = Uri.parse(BASIC_SYNTAX_URL + "&authz=oauth&OAUTH_SERVICE_NAME=example&container=default&gadget=http://example.org/gadget.xml"); expect(proxyUriManager.process(uri)).andReturn(proxyUri); expect(request.getScheme()).andReturn(uri.getScheme()); expect(request.getServerName()).andReturn(uri.getAuthority()); expect(request.getServerPort()).andReturn(80); expect(request.getRequestURI()).andReturn(uri.getPath()); expect(request.getQueryString()).andReturn(uri.getQuery()); expect(request.getHeader("Host")).andReturn(uri.getAuthority()); expect(request.getParameter("OAUTH_SERVICE_NAME")).andReturn("example"); expect(request.getParameterNames()).andReturn(Collections.enumeration(options.keySet())); expect(lockedDomainService.isSafeForOpenProxy(uri.getAuthority())).andReturn(true); ProxyUriManager.ProxyUri pUri = new ProxyUri(-1, false, true, "default", "http://example.org/gadget.xml", REQUEST_URL); pUri.setAuthType(AuthType.OAUTH); pUri.setOAuthArguments(new OAuthArguments(AuthType.OAUTH, options)); expect(proxyHandler.fetch(pUri)).andReturn(new HttpResponse(RESPONSE_BODY)); replay(); servlet.doGet(request, recorder); verify(); assertResponseOk(HttpResponse.SC_OK, RESPONSE_BODY); } }
@Test public void testDoGetWithOAuth() throws Exception { Map<String, String> options = new HashMap<String, String>(); options.put("OAUTH_SERVICE_NAME", "example"); ProxyUriManager.ProxyUri proxyUri = new ProxyUri(-1, false, true, "default", "http://example.org/gadget.xml", REQUEST_URL); proxyUri.setAuthType(AuthType.OAUTH); Uri uri = Uri.parse(BASIC_SYNTAX_URL + "&authz=oauth&OAUTH_SERVICE_NAME=example&container=default&gadget=http://example.org/gadget.xml"); expect(proxyUriManager.process(uri)).andReturn(proxyUri); expect(request.getScheme()).andReturn(uri.getScheme()); expect(request.getServerName()).andReturn(uri.getAuthority()); expect(request.getServerPort()).andReturn(80); expect(request.getRequestURI()).andReturn(uri.getPath()); expect(request.getQueryString()).andReturn(uri.getQuery()); expect(request.getHeader("Host")).andReturn(uri.getAuthority()); expect(request.getParameter("OAUTH_SERVICE_NAME")).andReturn("example"); expect(request.getParameterNames()).andReturn(Collections.enumeration(options.keySet())); expect(lockedDomainService.isSafeForOpenProxy(uri.getAuthority())).andReturn(true); ProxyUriManager.ProxyUri pUri = new ProxyUri(-1, false, true, "default", "http://example.org/gadget.xml", REQUEST_URL); pUri.setAuthType(AuthType.OAUTH); pUri.setOAuthArguments(new OAuthArguments(AuthType.OAUTH, options)); expect(proxyHandler.fetch(pUri)).andReturn(new HttpResponse(RESPONSE_BODY)); replay(); servlet.doGet(request, recorder); verify(); assertResponseOk(HttpResponse.SC_OK, RESPONSE_BODY); } }
proxyUri.setOAuthArguments(new OAuthArguments(AuthType.OAUTH, request)); } else if(AuthType.OAUTH2.equals(authType)) { proxyUri.setOAuth2Arguments(new OAuth2Arguments(request));
@Test public void testWithOAuth() throws Exception { String url = "http://example.org/oauth2"; String domain = "example.org"; setupProxyRequestMock(domain, url, false, -1, null, null); setupGadgetAdminMock(true); Map<String, String> options = new HashMap<String, String>(); options.put("OAUTH_SERVICE_NAME", "example"); request.setAuthType(AuthType.OAUTH); request.setOAuthArguments(new OAuthArguments(AuthType.OAUTH, options)); options = new HashMap<String, String>(); options.put("OAUTH_SERVICE_NAME", "example"); HttpRequest req = new HttpRequest(Uri.parse(url)) .setAuthType(AuthType.OAUTH) .setGadget(Uri.parse("")) .setContainer("default") .setOAuthArguments(new OAuthArguments(AuthType.OAUTH, options)); HttpResponse resp = new HttpResponseBuilder() .setResponseString("Hello") .create(); expect(pipeline.execute(req)).andReturn(resp); replay(); HttpResponse response = proxyHandler.fetch(request); verify(); assertEquals("Hello", response.getResponseAsString()); }
@Test public void testWithOAuth() throws Exception { String url = "http://example.org/oauth2"; String domain = "example.org"; setupProxyRequestMock(domain, url, false, -1, null, null); setupGadgetAdminMock(true); Map<String, String> options = new HashMap<String, String>(); options.put("OAUTH_SERVICE_NAME", "example"); request.setAuthType(AuthType.OAUTH); request.setOAuthArguments(new OAuthArguments(AuthType.OAUTH, options)); options = new HashMap<String, String>(); options.put("OAUTH_SERVICE_NAME", "example"); HttpRequest req = new HttpRequest(Uri.parse(url)) .setAuthType(AuthType.OAUTH) .setGadget(Uri.parse("")) .setContainer("default") .setOAuthArguments(new OAuthArguments(AuthType.OAUTH, options)); HttpResponse resp = new HttpResponseBuilder() .setResponseString("Hello") .create(); expect(pipeline.execute(req)).andReturn(resp); replay(); HttpResponse response = proxyHandler.fetch(request); verify(); assertEquals("Hello", response.getResponseAsString()); }