@Before public void setUp() throws Exception { control = EasyMock.createNiceControl(); processor = control.createMock(Processor.class); lockedDomainService = control.createMock(LockedDomainService.class); oauthUriManager = control.createMock(OAuthUriManager.class); stateCrypter = new BasicBlobCrypter("1111111111111111111".getBytes()); securityToken = new BasicSecurityToken("viewer", "viewer", "app", "container.com", "gadget", "0", "default", MAKE_REQUEST_URL, null); gadget = control.createMock(Gadget.class); fetcherConfig = new OAuthFetcherConfig(null, null, null, null, false); responseParams = new OAuthResponseParams(null, null, null); }
@Before public void setUp() throws Exception { control = EasyMock.createNiceControl(); processor = control.createMock(Processor.class); lockedDomainService = control.createMock(LockedDomainService.class); oauthUriManager = control.createMock(OAuthUriManager.class); stateCrypter = new BasicBlobCrypter("1111111111111111111".getBytes()); securityToken = new BasicSecurityToken("viewer", "viewer", "app", "container.com", "gadget", "0", "default", MAKE_REQUEST_URL, null); gadget = control.createMock(Gadget.class); fetcherConfig = new OAuthFetcherConfig(null, null, null, null, false); responseParams = new OAuthResponseParams(null, null, null); }
@Before public void setUp() throws Exception { control = EasyMock.createNiceControl(); processor = control.createMock(Processor.class); lockedDomainService = control.createMock(LockedDomainService.class); oauthUriManager = control.createMock(OAuthUriManager.class); stateCrypter = new BasicBlobCrypter("1111111111111111111".getBytes()); securityToken = new BasicSecurityToken("viewer", "viewer", "app", "container.com", "gadget", "0", "default", MAKE_REQUEST_URL, null); gadget = control.createMock(Gadget.class); fetcherConfig = new OAuthFetcherConfig(null, null, null, null, false); responseParams = new OAuthResponseParams(null, null, null); }
@Test public void testOAuthFlow_noViewer() throws Exception { for (boolean secureOwner : Arrays.asList(true, false)) { // Test both with/without secure owner pages fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base), clock, callbackGenerator, secureOwner); MakeRequestClient client = makeNonSocialClient("owner", null, GADGET_URL); HttpResponse response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); assertEquals("", response.getResponseAsString()); assertEquals(403, response.getHttpStatusCode()); assertEquals(-1, response.getCacheTtl()); assertEquals(OAuthError.UNAUTHENTICATED.name(), response.getMetadata().get("oauthError")); } }
@Test public void testOAuthFlow_noViewer() throws Exception { for (boolean secureOwner : Arrays.asList(true, false)) { // Test both with/without secure owner pages fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base), clock, callbackGenerator, secureOwner); MakeRequestClient client = makeNonSocialClient("owner", null, GADGET_URL); HttpResponse response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL); assertEquals("", response.getResponseAsString()); assertEquals(403, response.getHttpStatusCode()); assertEquals(-1, response.getCacheTtl()); assertEquals(OAuthError.UNAUTHENTICATED.name(), response.getMetadata().get("oauthError")); } }
@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_noSpec() throws Exception { fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base, null), clock, callbackGenerator, false); MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL); setNoSpecOptions(client); 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_withCallbackVerifier() throws Exception { fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base), clock, createRealCallbackGenerator(), false); 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()); checkEmptyLog(); }
@Test public void testOAuthFlow_noSpec() throws Exception { fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base, null), clock, callbackGenerator, false); MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL); setNoSpecOptions(client); 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_withCallbackVerifier() throws Exception { fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base), clock, createRealCallbackGenerator(), false); 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()); checkEmptyLog(); }
@Test public void testOAuthFlow_noSpec() throws Exception { fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base, null), clock, callbackGenerator, false); MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL); setNoSpecOptions(client); 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_withCallbackVerifier() throws Exception { fetcherConfig = new OAuthFetcherConfig( new BasicBlobCrypter("abcdefghijklmnop".getBytes()), getOAuthStore(base), clock, createRealCallbackGenerator(), false); 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()); 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_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 testOAuthFetcherConfig() { BlobCrypter crypter = mock(BlobCrypter.class); mock(HttpCache.class); GadgetOAuthTokenStore tokenStore = mock(GadgetOAuthTokenStore.class); OAuthCallbackGenerator callbackGenerator = mock(OAuthCallbackGenerator.class); OAuthFetcherConfig config = new OAuthFetcherConfig(crypter, tokenStore, new TimeSource(), callbackGenerator, false); assertEquals(crypter, config.getStateCrypter()); assertEquals(tokenStore, config.getTokenStore()); assertEquals(callbackGenerator, config.getOAuthCallbackGenerator()); assertFalse(config.isViewerAccessTokensEnabled()); } }
@Test public void testOAuthFetcherConfig() { BlobCrypter crypter = mock(BlobCrypter.class); mock(HttpCache.class); GadgetOAuthTokenStore tokenStore = mock(GadgetOAuthTokenStore.class); OAuthCallbackGenerator callbackGenerator = mock(OAuthCallbackGenerator.class); OAuthFetcherConfig config = new OAuthFetcherConfig(crypter, tokenStore, new TimeSource(), callbackGenerator, false); assertEquals(crypter, config.getStateCrypter()); assertEquals(tokenStore, config.getTokenStore()); assertEquals(callbackGenerator, config.getOAuthCallbackGenerator()); assertFalse(config.isViewerAccessTokensEnabled()); } }
@Test public void testOAuthFetcherConfig() { BlobCrypter crypter = mock(BlobCrypter.class); mock(HttpCache.class); GadgetOAuthTokenStore tokenStore = mock(GadgetOAuthTokenStore.class); OAuthCallbackGenerator callbackGenerator = mock(OAuthCallbackGenerator.class); OAuthFetcherConfig config = new OAuthFetcherConfig(crypter, tokenStore, new TimeSource(), callbackGenerator, false); assertEquals(crypter, config.getStateCrypter()); assertEquals(tokenStore, config.getTokenStore()); assertEquals(callbackGenerator, config.getOAuthCallbackGenerator()); assertFalse(config.isViewerAccessTokensEnabled()); } }