private void setNoSpecOptions(MakeRequestClient client) { client.getBaseArgs().setRequestOption(OAuthArguments.PROGRAMMATIC_CONFIG_PARAM, "true"); client.getBaseArgs().setRequestOption(OAuthArguments.PARAM_LOCATION_PARAM, "uri-query"); client.getBaseArgs().setRequestOption(OAuthArguments.REQUEST_METHOD_PARAM, "GET"); client.getBaseArgs().setRequestOption(OAuthArguments.REQUEST_TOKEN_URL_PARAM, FakeOAuthServiceProvider.REQUEST_TOKEN_URL); client.getBaseArgs().setRequestOption(OAuthArguments.ACCESS_TOKEN_URL_PARAM, FakeOAuthServiceProvider.ACCESS_TOKEN_URL); client.getBaseArgs().setRequestOption(OAuthArguments.AUTHORIZATION_URL_PARAM, FakeOAuthServiceProvider.APPROVAL_URL); }
private void setNoSpecOptions(MakeRequestClient client) { client.getBaseArgs().setRequestOption(OAuthArguments.PROGRAMMATIC_CONFIG_PARAM, "true"); client.getBaseArgs().setRequestOption(OAuthArguments.PARAM_LOCATION_PARAM, "uri-query"); client.getBaseArgs().setRequestOption(OAuthArguments.REQUEST_METHOD_PARAM, "GET"); client.getBaseArgs().setRequestOption(OAuthArguments.REQUEST_TOKEN_URL_PARAM, FakeOAuthServiceProvider.REQUEST_TOKEN_URL); client.getBaseArgs().setRequestOption(OAuthArguments.ACCESS_TOKEN_URL_PARAM, FakeOAuthServiceProvider.ACCESS_TOKEN_URL); client.getBaseArgs().setRequestOption(OAuthArguments.AUTHORIZATION_URL_PARAM, FakeOAuthServiceProvider.APPROVAL_URL); }
private void setNoSpecOptions(MakeRequestClient client) { client.getBaseArgs().setRequestOption(OAuthArguments.PROGRAMMATIC_CONFIG_PARAM, "true"); client.getBaseArgs().setRequestOption(OAuthArguments.PARAM_LOCATION_PARAM, "uri-query"); client.getBaseArgs().setRequestOption(OAuthArguments.REQUEST_METHOD_PARAM, "GET"); client.getBaseArgs().setRequestOption(OAuthArguments.REQUEST_TOKEN_URL_PARAM, FakeOAuthServiceProvider.REQUEST_TOKEN_URL); client.getBaseArgs().setRequestOption(OAuthArguments.ACCESS_TOKEN_URL_PARAM, FakeOAuthServiceProvider.ACCESS_TOKEN_URL); client.getBaseArgs().setRequestOption(OAuthArguments.AUTHORIZATION_URL_PARAM, FakeOAuthServiceProvider.APPROVAL_URL); }
@Test public void testCopyConstructor_options() throws Exception { HttpServletRequest req = makeDummyRequest(); OAuthArguments args = new OAuthArguments(AuthType.OAUTH, req); args = new OAuthArguments(args); args.setRequestOption("foo", "bar"); args.setRequestOption("quux", "baz"); assertEquals("bar", args.getRequestOption("foo")); assertEquals("baz", args.getRequestOption("quux")); }
@Test public void testCopyConstructor_options() throws Exception { HttpServletRequest req = makeDummyRequest(); OAuthArguments args = new OAuthArguments(AuthType.OAUTH, req); args = new OAuthArguments(args); args.setRequestOption("foo", "bar"); args.setRequestOption("quux", "baz"); assertEquals("bar", args.getRequestOption("foo")); assertEquals("baz", args.getRequestOption("quux")); }
@Test public void testCopyConstructor_options() throws Exception { HttpServletRequest req = makeDummyRequest(); OAuthArguments args = new OAuthArguments(AuthType.OAUTH, req); args = new OAuthArguments(args); args.setRequestOption("foo", "bar"); args.setRequestOption("quux", "baz"); assertEquals("bar", args.getRequestOption("foo")); assertEquals("baz", args.getRequestOption("quux")); }
@Test public void testSignedFetch_authHeader() throws Exception { serviceProvider.setParamLocation(OAuthParamLocation.AUTH_HEADER); MakeRequestClient client = makeSignedFetchClient("o", "v", "http://www.example.com/app"); client.getBaseArgs().setRequestOption(OAuthArguments.PROGRAMMATIC_CONFIG_PARAM, "true"); client.getBaseArgs().setRequestOption(OAuthArguments.PARAM_LOCATION_PARAM, "auth-header"); HttpResponse resp = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); String auth = resp.getHeader(FakeOAuthServiceProvider.AUTHZ_ECHO_HEADER); assertNotNull("Should have echoed authz header", auth); checkStringContains("should have opensocial params in header", auth, "opensocial_owner_id=\"o\""); }
@Test public void testSignedFetch_authHeader() throws Exception { serviceProvider.setParamLocation(OAuthParamLocation.AUTH_HEADER); MakeRequestClient client = makeSignedFetchClient("o", "v", "http://www.example.com/app"); client.getBaseArgs().setRequestOption(OAuthArguments.PROGRAMMATIC_CONFIG_PARAM, "true"); client.getBaseArgs().setRequestOption(OAuthArguments.PARAM_LOCATION_PARAM, "auth-header"); HttpResponse resp = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); String auth = resp.getHeader(FakeOAuthServiceProvider.AUTHZ_ECHO_HEADER); assertNotNull("Should have echoed authz header", auth); checkStringContains("should have opensocial params in header", auth, "opensocial_owner_id=\"o\""); }
@Test public void testSignedFetch_authHeader() throws Exception { serviceProvider.setParamLocation(OAuthParamLocation.AUTH_HEADER); MakeRequestClient client = makeSignedFetchClient("o", "v", "http://www.example.com/app"); client.getBaseArgs().setRequestOption(OAuthArguments.PROGRAMMATIC_CONFIG_PARAM, "true"); client.getBaseArgs().setRequestOption(OAuthArguments.PARAM_LOCATION_PARAM, "auth-header"); HttpResponse resp = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); String auth = resp.getHeader(FakeOAuthServiceProvider.AUTHZ_ECHO_HEADER); assertNotNull("Should have echoed authz header", auth); checkStringContains("should have opensocial params in header", auth, "opensocial_owner_id=\"o\""); }
@Test public void testOAuthFlow_noSpecPostBody() throws Exception { serviceProvider.setParamLocation(OAuthParamLocation.POST_BODY); fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base, null), clock, callbackGenerator, false); MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL); setNoSpecOptions(client); client.getBaseArgs().setRequestOption(OAuthArguments.REQUEST_METHOD_PARAM, "POST"); client.getBaseArgs().setRequestOption(OAuthArguments.PARAM_LOCATION_PARAM, "post-body"); HttpResponse response = client.sendFormPost(FakeOAuthServiceProvider.RESOURCE_URL, ""); assertEquals("", response.getResponseAsString()); client.approveToken("user_data=hello-oauth"); response = client.sendFormPost(FakeOAuthServiceProvider.RESOURCE_URL, ""); assertEquals("User data is hello-oauth", response.getResponseAsString()); checkEmptyLog(); }
@Test public void testOAuthFlow_noSpecPostBody() throws Exception { serviceProvider.setParamLocation(OAuthParamLocation.POST_BODY); fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base, null), clock, callbackGenerator, false); MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL); setNoSpecOptions(client); client.getBaseArgs().setRequestOption(OAuthArguments.REQUEST_METHOD_PARAM, "POST"); client.getBaseArgs().setRequestOption(OAuthArguments.PARAM_LOCATION_PARAM, "post-body"); HttpResponse response = client.sendFormPost(FakeOAuthServiceProvider.RESOURCE_URL, ""); assertEquals("", response.getResponseAsString()); client.approveToken("user_data=hello-oauth"); response = client.sendFormPost(FakeOAuthServiceProvider.RESOURCE_URL, ""); assertEquals("User data is hello-oauth", response.getResponseAsString()); checkEmptyLog(); }
@Test public void testOAuthFlow_noSpecPostBody() throws Exception { serviceProvider.setParamLocation(OAuthParamLocation.POST_BODY); fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base, null), clock, callbackGenerator, false); MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL); setNoSpecOptions(client); client.getBaseArgs().setRequestOption(OAuthArguments.REQUEST_METHOD_PARAM, "POST"); client.getBaseArgs().setRequestOption(OAuthArguments.PARAM_LOCATION_PARAM, "post-body"); HttpResponse response = client.sendFormPost(FakeOAuthServiceProvider.RESOURCE_URL, ""); assertEquals("", response.getResponseAsString()); client.approveToken("user_data=hello-oauth"); response = client.sendFormPost(FakeOAuthServiceProvider.RESOURCE_URL, ""); assertEquals("User data is hello-oauth", response.getResponseAsString()); checkEmptyLog(); }
@Test public void testOAuthFlow_noSpecPostBodyAndHeader() throws Exception { serviceProvider.setParamLocation(OAuthParamLocation.POST_BODY); serviceProvider.addParamLocation(OAuthParamLocation.AUTH_HEADER); fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base, null), clock, callbackGenerator, false); MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL); setNoSpecOptions(client); client.getBaseArgs().setRequestOption(OAuthArguments.REQUEST_METHOD_PARAM, "POST"); client.getBaseArgs().setRequestOption(OAuthArguments.PARAM_LOCATION_PARAM, "post-body"); HttpResponse response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); assertEquals("", response.getResponseAsString()); client.approveToken("user_data=hello-oauth"); response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); assertEquals("User data is hello-oauth", response.getResponseAsString()); checkEmptyLog(); }
@Test public void testOAuthFlow_noSpecBlankUrl() throws Exception { fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base, null), clock, null, false); MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL); setNoSpecOptions(client); client.getBaseArgs().setRequestOption(OAuthArguments.REQUEST_TOKEN_URL_PARAM, ""); HttpResponse response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); assertEquals("", response.getResponseAsString()); assertEquals(403, response.getHttpStatusCode()); assertEquals(OAuthError.INVALID_URL.name(), response.getMetadata().get("oauthError")); String errorText = response.getMetadata().get("oauthErrorText"); assertNotNull(errorText); checkStringContains("should report invalid url", errorText, "Invalid URL: "); }
@Test public void testOAuthFlow_noSpecBlankUrl() throws Exception { fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base, null), clock, null, false); MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL); setNoSpecOptions(client); client.getBaseArgs().setRequestOption(OAuthArguments.REQUEST_TOKEN_URL_PARAM, ""); HttpResponse response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); assertEquals("", response.getResponseAsString()); assertEquals(403, response.getHttpStatusCode()); assertEquals(OAuthError.INVALID_URL.name(), response.getMetadata().get("oauthError")); String errorText = response.getMetadata().get("oauthErrorText"); assertNotNull(errorText); checkStringContains("should report invalid url", errorText, "Invalid URL: "); }
@Test public void testOAuthFlow_noSpecInvalidUrl() throws Exception { fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base, null), clock, null, false); MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL); setNoSpecOptions(client); client.getBaseArgs().setRequestOption(OAuthArguments.REQUEST_TOKEN_URL_PARAM, "foo"); HttpResponse response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); assertEquals("", response.getResponseAsString()); assertEquals(403, response.getHttpStatusCode()); assertEquals(OAuthError.INVALID_URL.name(), response.getMetadata().get("oauthError")); String errorText = response.getMetadata().get("oauthErrorText"); assertNotNull(errorText); checkStringContains("should report invalid url", errorText, "Invalid URL: foo"); }
@Test public void testOAuthFlow_noSpecInvalidUrl() throws Exception { fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base, null), clock, null, false); MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL); setNoSpecOptions(client); client.getBaseArgs().setRequestOption(OAuthArguments.REQUEST_TOKEN_URL_PARAM, "foo"); HttpResponse response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); assertEquals("", response.getResponseAsString()); assertEquals(403, response.getHttpStatusCode()); assertEquals(OAuthError.INVALID_URL.name(), response.getMetadata().get("oauthError")); String errorText = response.getMetadata().get("oauthErrorText"); assertNotNull(errorText); checkStringContains("should report invalid url", errorText, "Invalid URL: foo"); }
@Test public void testOAuthFlow_noSpecAuthHeader() throws Exception { serviceProvider.setParamLocation(OAuthParamLocation.AUTH_HEADER); fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base, null), clock, callbackGenerator, false); MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL); setNoSpecOptions(client); client.getBaseArgs().setRequestOption(OAuthArguments.PARAM_LOCATION_PARAM, "auth-header"); HttpResponse response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); assertEquals("", response.getResponseAsString()); client.approveToken("user_data=hello-oauth"); response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); assertEquals("User data is hello-oauth", response.getResponseAsString()); checkEmptyLog(); }
@Test public void testOAuthFlow_noSpecAuthHeader() throws Exception { serviceProvider.setParamLocation(OAuthParamLocation.AUTH_HEADER); fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base, null), clock, callbackGenerator, false); MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL); setNoSpecOptions(client); client.getBaseArgs().setRequestOption(OAuthArguments.PARAM_LOCATION_PARAM, "auth-header"); HttpResponse response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); assertEquals("", response.getResponseAsString()); client.approveToken("user_data=hello-oauth"); response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); assertEquals("User data is hello-oauth", response.getResponseAsString()); checkEmptyLog(); }
@Test public void testOAuthFlow_noSpecAuthHeader() throws Exception { serviceProvider.setParamLocation(OAuthParamLocation.AUTH_HEADER); fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base, null), clock, callbackGenerator, false); MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL); setNoSpecOptions(client); client.getBaseArgs().setRequestOption(OAuthArguments.PARAM_LOCATION_PARAM, "auth-header"); HttpResponse response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); assertEquals("", response.getResponseAsString()); client.approveToken("user_data=hello-oauth"); response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); assertEquals("User data is hello-oauth", response.getResponseAsString()); checkEmptyLog(); }