@Test public void testDoOAuthRequest() throws Exception { // Doesn't actually do oauth dance since it returns the standard fetcher. // OAuth tests are in OAuthRequestTest expectGetAndReturnBody(AuthType.OAUTH, RESPONSE_BODY); FakeGadgetToken authToken = new FakeGadgetToken().setUpdatedToken("updated"); expect(request.getAttribute(AuthInfo.Attribute.SECURITY_TOKEN.getId())) .andReturn(authToken).atLeastOnce(); expect(request.getParameter(MakeRequestHandler.AUTHZ_PARAM)) .andReturn(AuthType.OAUTH.toString()).atLeastOnce(); // This isn't terribly accurate, but is close enough for this test. expect(request.getParameterMap()).andStubReturn(Collections.emptyMap()); expectParameters(request); replay(); handler.fetch(request, recorder); JSONObject results = extractJsonFromResponse(); assertEquals(HttpResponse.SC_OK, results.getInt("rc")); assertEquals(RESPONSE_BODY, results.get("body")); assertTrue(rewriter.responseWasRewritten()); }
@Test public void testChangeSecurityToken() throws Exception { // Doesn't actually sign since it returns the standard fetcher. // Signing tests are in SigningFetcherTest expectGetAndReturnBody(AuthType.SIGNED, RESPONSE_BODY); FakeGadgetToken authToken = new FakeGadgetToken().setUpdatedToken("updated"); expect(request.getAttribute(AuthInfo.Attribute.SECURITY_TOKEN.getId())) .andReturn(authToken).atLeastOnce(); expect(request.getParameter(MakeRequestHandler.AUTHZ_PARAM)) .andReturn(AuthType.SIGNED.toString()).atLeastOnce(); expectParameters(request, MakeRequestHandler.AUTHZ_PARAM); replay(); handler.fetch(request, recorder); JSONObject results = extractJsonFromResponse(); assertEquals(RESPONSE_BODY, results.get("body")); assertEquals("updated", results.getString("st")); assertTrue(rewriter.responseWasRewritten()); }
@Test public void testDoOAuthRequest() throws Exception { // Doesn't actually do oauth dance since it returns the standard fetcher. // OAuth tests are in OAuthRequestTest expectGetAndReturnBody(AuthType.OAUTH, RESPONSE_BODY); FakeGadgetToken authToken = new FakeGadgetToken() .setUpdatedToken("updated") .setAppUrl(DUMMY_TOKEN.getAppUrl()) .setContainer(DUMMY_TOKEN.getContainer()); expect(request.getAttribute(AuthInfoUtil.Attribute.SECURITY_TOKEN.getId())) .andReturn(authToken).atLeastOnce(); expect(request.getParameter(MakeRequestHandler.AUTHZ_PARAM)) .andReturn(AuthType.OAUTH.toString()).atLeastOnce(); // This isn't terribly accurate, but is close enough for this test. expect(request.getParameterMap()).andStubReturn(Collections.emptyMap()); expectParameters(request); replay(); handler.fetch(request, recorder); JSONObject results = extractJsonFromResponse(); assertEquals(HttpResponse.SC_OK, results.getInt("rc")); assertEquals(RESPONSE_BODY, results.get("body")); assertTrue(rewriter.responseWasRewritten()); }
@Test public void testDoOAuthRequest() throws Exception { // Doesn't actually do oauth dance since it returns the standard fetcher. // OAuth tests are in OAuthRequestTest expectGetAndReturnBody(AuthType.OAUTH, RESPONSE_BODY); FakeGadgetToken authToken = new FakeGadgetToken() .setUpdatedToken("updated") .setAppUrl(DUMMY_TOKEN.getAppUrl()) .setContainer(DUMMY_TOKEN.getContainer()); expect(request.getAttribute(AuthInfoUtil.Attribute.SECURITY_TOKEN.getId())) .andReturn(authToken).atLeastOnce(); expect(request.getParameter(MakeRequestHandler.AUTHZ_PARAM)) .andReturn(AuthType.OAUTH.toString()).atLeastOnce(); // This isn't terribly accurate, but is close enough for this test. expect(request.getParameterMap()).andStubReturn(Collections.emptyMap()); expectParameters(request); replay(); handler.fetch(request, recorder); JSONObject results = extractJsonFromResponse(); assertEquals(HttpResponse.SC_OK, results.getInt("rc")); assertEquals(RESPONSE_BODY, results.get("body")); assertTrue(rewriter.responseWasRewritten()); }
@Test public void testChangeSecurityToken() throws Exception { // Doesn't actually sign since it returns the standard fetcher. // Signing tests are in SigningFetcherTest expectGetAndReturnBody(AuthType.SIGNED, RESPONSE_BODY); FakeGadgetToken authToken = new FakeGadgetToken() .setUpdatedToken("updated") .setAppUrl(DUMMY_TOKEN.getAppUrl()) .setContainer(DUMMY_TOKEN.getContainer()); expect(request.getAttribute(AuthInfoUtil.Attribute.SECURITY_TOKEN.getId())) .andReturn(authToken).atLeastOnce(); expect(request.getParameter(MakeRequestHandler.AUTHZ_PARAM)) .andReturn(AuthType.SIGNED.toString()).atLeastOnce(); expectParameters(request, MakeRequestHandler.AUTHZ_PARAM); replay(); handler.fetch(request, recorder); JSONObject results = extractJsonFromResponse(); assertEquals(RESPONSE_BODY, results.get("body")); assertEquals("updated", results.getString("st")); assertTrue(rewriter.responseWasRewritten()); }
@Test public void testChangeSecurityToken() throws Exception { // Doesn't actually sign since it returns the standard fetcher. // Signing tests are in SigningFetcherTest expectGetAndReturnBody(AuthType.SIGNED, RESPONSE_BODY); FakeGadgetToken authToken = new FakeGadgetToken() .setUpdatedToken("updated") .setAppUrl(DUMMY_TOKEN.getAppUrl()) .setContainer(DUMMY_TOKEN.getContainer()); expect(request.getAttribute(AuthInfoUtil.Attribute.SECURITY_TOKEN.getId())) .andReturn(authToken).atLeastOnce(); expect(request.getParameter(MakeRequestHandler.AUTHZ_PARAM)) .andReturn(AuthType.SIGNED.toString()).atLeastOnce(); expectParameters(request, MakeRequestHandler.AUTHZ_PARAM); replay(); handler.fetch(request, recorder); JSONObject results = extractJsonFromResponse(); assertEquals(RESPONSE_BODY, results.get("body")); assertEquals("updated", results.getString("st")); assertTrue(rewriter.responseWasRewritten()); }
@Test public void testSignedPostAndUpdateSecurityToken() throws Exception { token.setUpdatedToken("updated"); JSONObject request = new JSONObject("{method:http.post, id:req1, params : {" + "href:'http://www.example.org/somecontent'," + "body:'POSTBODY'," + "authz: 'signed' }" + "}}"); HttpRequest httpRequest = new HttpRequest(Uri.parse("http://www.example.org/somecontent")); httpRequest.setMethod("POST"); httpRequest.setAuthType(AuthType.SIGNED); httpRequest.setOAuthArguments( new OAuthArguments(AuthType.SIGNED, ImmutableMap.<String, String>of())); httpRequest.setPostBody("POSTBODY".getBytes()); expect(pipeline.execute(eqRequest(httpRequest))).andReturn(builder.create()).anyTimes(); replay(); RpcHandler operation = registry.getRpcHandler(request); HttpRequestHandler.HttpApiResponse httpApiResponse = (HttpRequestHandler.HttpApiResponse)operation.execute(emptyFormItems, token, converter).get(); verify(); JsonAssert.assertJsonEquals("{ headers : {}, status : 200, content : 'CONTENT', token : updated }}", converter.convertToString(httpApiResponse)); assertTrue(rewriter.responseWasRewritten()); }
@Test public void testSignedPostAndUpdateSecurityToken() throws Exception { token.setUpdatedToken("updated"); JSONObject request = new JSONObject("{method:http.post, id:req1, params : {" + "href:'http://www.example.org/somecontent'," + "body:'POSTBODY'," + "authz: 'signed' }" + "}}"); HttpRequest httpRequest = new HttpRequest(Uri.parse("http://www.example.org/somecontent")); httpRequest.setMethod("POST"); httpRequest.setAuthType(AuthType.SIGNED); httpRequest.setOAuthArguments( new OAuthArguments(AuthType.SIGNED, ImmutableMap.<String, String>of())); httpRequest.setPostBody("POSTBODY".getBytes()); expect(pipeline.execute(eqRequest(httpRequest))).andReturn(builder.create()).anyTimes(); replay(); RpcHandler operation = registry.getRpcHandler(request); HttpRequestHandler.HttpApiResponse httpApiResponse = (HttpRequestHandler.HttpApiResponse)operation.execute(emptyFormItems, token, converter).get(); verify(); JsonAssert.assertJsonEquals("{ headers : {}, status : 200, content : 'CONTENT', token : updated }}", converter.convertToString(httpApiResponse)); assertTrue(rewriter.responseWasRewritten()); }
@Test public void testSignedPostAndUpdateSecurityToken() throws Exception { token.setUpdatedToken("updated"); JSONObject request = new JSONObject("{method:http.post, id:req1, params : {" + "href:'http://www.example.org/somecontent'," + "body:'POSTBODY'," + "authz: 'signed' }" + "}}"); HttpRequest httpRequest = new HttpRequest(Uri.parse("http://www.example.org/somecontent")); httpRequest.setMethod("POST"); httpRequest.setAuthType(AuthType.SIGNED); httpRequest.setOAuthArguments( new OAuthArguments(AuthType.SIGNED, ImmutableMap.<String, String>of())); httpRequest.setPostBody("POSTBODY".getBytes()); expect(pipeline.execute(eqRequest(httpRequest))).andReturn(builder.create()).anyTimes(); replay(); RpcHandler operation = registry.getRpcHandler(request); HttpRequestHandler.HttpApiResponse httpApiResponse = (HttpRequestHandler.HttpApiResponse)operation.execute(emptyFormItems, token, converter).get(); verify(); JsonAssert.assertJsonEquals("{ headers : {}, status : 200, content : 'CONTENT', token : updated }}", converter.convertToString(httpApiResponse)); assertTrue(rewriter.responseWasRewritten()); }