Package org.apache.shindig.gadgets.oauth.testing

Examples of org.apache.shindig.gadgets.oauth.testing.MakeRequestClient


  @Test(expected=RuntimeException.class)
  public void testAccessTokenData_noDirectRequest() throws Exception {
    serviceProvider.setReturnAccessTokenData(true);

    MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL);

    HttpResponse response = client.sendGet(FakeOAuthServiceProvider.ACCESS_TOKEN_URL);
    assertEquals("", response.getResponseAsString());
    client.approveToken("user_data=hello-oauth");

    response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL);
    assertEquals("User data is hello-oauth", response.getResponseAsString());

    client.sendGet(FakeOAuthServiceProvider.ACCESS_TOKEN_URL);
    fail("Service provider should have rejected bogus request to access token URL");
  }
View Full Code Here


  }

  @Test
  public void testNextFetchReturnsNull() throws Exception {
    serviceProvider.setReturnNull(true);
    MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL);
    HttpResponse response = client.sendGet(FakeOAuthServiceProvider.ACCESS_TOKEN_URL);
    assertEquals("MISSING_SERVER_RESPONSE", response.getMetadata().get("oauthError"));
    assertEquals("", response.getResponseAsString());
    String oauthErrorText = response.getMetadata().get("oauthErrorText");
    checkStringContains("should say no response", oauthErrorText, "No response from server");
    checkStringContains("should show request", oauthErrorText,
View Full Code Here

  @Test
  public void testNextFetchThrowsGadgetException() throws Exception {
    serviceProvider.setThrow(
        new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, "mildly wrong"));
    MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL);
    HttpResponse response = client.sendGet(FakeOAuthServiceProvider.ACCESS_TOKEN_URL);
    assertEquals("MISSING_SERVER_RESPONSE", response.getMetadata().get("oauthError"));
    assertEquals("", response.getResponseAsString());
    String oauthErrorText = response.getMetadata().get("oauthErrorText");
    checkStringContains("should say no response", oauthErrorText, "No response from server");
    checkStringContains("should show request", oauthErrorText,
View Full Code Here

  }

  @Test
  public void testNextFetchThrowsRuntimeException() throws Exception {
    serviceProvider.setThrow(new RuntimeException("very, very wrong"));
    MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL);
    try {
      client.sendGet(FakeOAuthServiceProvider.ACCESS_TOKEN_URL);
      fail("Should have thrown");
    } catch (RuntimeException e) {
      // good
    }
    //checkLogContains("OAuth fetch unexpected fatal erro");
View Full Code Here

  }

  @Test
  public void testTrustedParams() throws Exception {
    serviceProvider.setCheckTrustedParams(true);
    MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL);
    client.setTrustedParam("oauth_magic", "foo");
    client.setTrustedParam("opensocial_magic", "bar");
    client.setTrustedParam("xoauth_magic", "quux");

    client.setTrustedParam("opensocial_owner_id", "overridden_opensocial_owner_id");

    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());
    assertEquals(12, serviceProvider.getTrustedParamCount());
  }
View Full Code Here

   * 3) trusted parameter can override existing parameter.
   */
  @Test
  public void testTrustedParamsMisc() throws Exception {
    serviceProvider.setCheckTrustedParams(true);
    MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL);
    client.setTrustedParam("oauth_magic", "foo");
    client.setTrustedParam("opensocial_magic", "bar");

    client.setTrustedParam("xoauth_magic", "quux_overridden");
    client.setTrustedParam("xoauth_magic", "quux");

    client.setTrustedParam("opensocial_owner_id", "overridden_opensocial_owner_id");

    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());
    assertEquals(12, serviceProvider.getTrustedParamCount());
  }
View Full Code Here

   * are false.
   */
  @Test
  public void testAlwaysAppendTrustedParams() throws Exception {
    serviceProvider.setCheckTrustedParams(true);
    MakeRequestClient client = makeStrictNonSocialClient("owner", "owner", GADGET_URL);
    client.setTrustedParam("oauth_magic", "foo");
    client.setTrustedParam("opensocial_magic", "bar");
    client.setTrustedParam("xoauth_magic", "quux");

    client.setTrustedParam("opensocial_owner_id", "overridden_opensocial_owner_id");

    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());
    assertEquals(12, serviceProvider.getTrustedParamCount());
  }
View Full Code Here

   * Test invalid trusted parameters which are not prefixed with 'oauth' 'xoauth' or 'opensocial'.
   */
  @Test
  public void testTrustedParamsInvalidParameter() throws Exception {
    serviceProvider.setCheckTrustedParams(true);
    MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL);
    client.setTrustedParam("oauth_magic", "foo");
    client.setTrustedParam("opensocial_magic", "bar");
    client.setTrustedParam("xoauth_magic", "quux");
    client.setTrustedParam("opensocial_owner_id", "overridden_opensocial_owner_id");
    client.setTrustedParam("invalid_trusted_parameter", "invalid");

    HttpResponse response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL);
    assertEquals(HttpResponse.SC_FORBIDDEN, response.getHttpStatusCode());
  }
View Full Code Here

        getOAuthStore(base),
        clock,
        callbackGenerator,
        true);

    MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL);

    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());

    MakeRequestClient friend = makeNonSocialClient("owner", "friend", GADGET_URL);
    response = friend.sendGet(FakeOAuthServiceProvider.RESOURCE_URL);
    assertEquals("", response.getResponseAsString());
    assertEquals(200, response.getHttpStatusCode());
  }
View Full Code Here

  }

  @Test
  public void testParamsInHeader() throws Exception {
    serviceProvider.setParamLocation(OAuthParamLocation.AUTH_HEADER);
    MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL_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());

    String aznHeader = response.getHeader(FakeOAuthServiceProvider.AUTHZ_ECHO_HEADER);
    assertNotNull(aznHeader);
    Assert.assertNotSame("azn header: " + aznHeader, aznHeader.indexOf("OAuth"), -1);
View Full Code Here

TOP

Related Classes of org.apache.shindig.gadgets.oauth.testing.MakeRequestClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.