@Before public void setUp() throws Exception { this.cache = new InMemoryCache(); Assert.assertNotNull(this.cache); Assert.assertTrue(OAuth2Cache.class.isInstance(this.cache)); this.cache.storeClient(MockUtils.getClient_Code_Confidential()); this.cache.storeClient(MockUtils.getClient_Code_Public()); this.cache.storeToken(MockUtils.getAccessToken()); this.cache.storeToken(MockUtils.getRefreshToken()); this.cache.storeOAuth2Accessor(MockUtils.getOAuth2Accessor_Code()); this.cache.storeOAuth2Accessor(MockUtils.getOAuth2Accessor_Error()); }
protected static OAuth2Accessor getOAuth2Accessor_BadMacToken() throws Exception { final BasicOAuth2Accessor accessor = MockUtils.getOAuth2AccessorCommon(); accessor.setAccessToken(MockUtils.getBadMacToken()); accessor.setRefreshToken(null); return accessor; }
@Before public void setUp() throws Exception { GadgetOAuth2TokenStoreTest.securityToken = MockUtils.getDummySecurityToken(MockUtils.USER, MockUtils.USER, MockUtils.GADGET_URI1); GadgetOAuth2TokenStoreTest.arguments = MockUtils.getDummyArguments(); final OAuth2Store store = MockUtils.getDummyStore(); final GadgetSpecFactory specFactory = MockUtils.getDummySpecFactory(); GadgetOAuth2TokenStoreTest.gts = new GadgetOAuth2TokenStore(store, specFactory); }
@Before public void setUp() throws Exception { CodeAuthorizationResponseHandlerTest.store = MockUtils.getDummyStore(); CodeAuthorizationResponseHandlerTest.carh = new CodeAuthorizationResponseHandler( MockUtils.getDummyMessageProvider(), MockUtils.getDummyClientAuthHandlers(), MockUtils.getDummyTokenEndpointResponseHandlers(), MockUtils.getDummyFetcher()); }
protected static JSONOAuth2Persister getDummyPersister() throws Exception { final JSONObject configFile = new JSONObject(MockUtils.getJSONString()); return new JSONOAuth2Persister(MockUtils.getDummyEncrypter(), MockUtils.getDummyAuthority(), MockUtils.REDIRECT_URI, "xxx", configFile); }
@Before public void setUp() throws Exception { OAuth2ClientTest.client1 = MockUtils.getClient_Code_Confidential(); OAuth2ClientTest.client2 = MockUtils.getClient_Code_Public(); }
@Test public void testGetEncrypter_1() throws Exception { final OAuth2Encrypter result = OAuth2ClientTest.client1.getEncrypter(); Assert.assertNotNull(result); Assert.assertEquals(MockUtils.getDummyEncrypter(), result); }
@Test public void testSetTokenForSharedClient() throws Exception { final OAuth2Cache cache = new InMemoryCache(); final OAuth2Persister persister = MockUtils.getDummyPersister(); final OAuth2Encrypter encrypter = MockUtils.getDummyEncrypter(); final BlobCrypter stateCrypter = MockUtils.getDummyStateCrypter(); OAuth2Token token = MockUtils.getAccessToken(); OAuth2Client client = MockUtils.getClient_Code_Confidential(); client.setSharedToken( true ); BasicOAuth2Store mockStore = createMockBuilder( BasicOAuth2Store.class ) .withConstructor( OAuth2Cache.class, OAuth2Persister.class, OAuth2Encrypter.class, String.class, Authority.class, String.class, BlobCrypter.class ) .withArgs( cache, persister, encrypter, MockUtils.REDIRECT_URI, (Authority)null, (String)null, stateCrypter ) .addMockedMethod( "getClient" ) .addMockedMethod( "getToken" ) .createMock(); expect( mockStore.getClient( eq(MockUtils.GADGET_URI1), eq(MockUtils.SERVICE_NAME) ) ).andReturn( client ); expect( mockStore.getToken( eq(token.getGadgetUri()), eq(token.getServiceName()), eq(token.getUser()), eq(token.getScope()), eq(token.getType() ) )).andReturn( token ); replay( mockStore ); mockStore.setToken( token ); verify( mockStore ); } }
private static BasicOAuth2Accessor getOAuth2AccessorCommon() throws Exception { final OAuth2Cache cache = new InMemoryCache(); final OAuth2Persister persister = MockUtils.getDummyPersister(); final OAuth2Encrypter encrypter = MockUtils.getDummyEncrypter(); final OAuth2Store store = MockUtils.getDummyStore(cache, persister, encrypter, MockUtils.REDIRECT_URI, null, null, MockUtils.stateCrypter); final BasicOAuth2Accessor accessor = new BasicOAuth2Accessor(MockUtils.GADGET_URI1, MockUtils.SERVICE_NAME, MockUtils.USER, MockUtils.SCOPE, true, store, MockUtils.REDIRECT_URI, null, null); accessor.setAccessToken(MockUtils.getAccessToken()); accessor.setAuthorizationUrl(MockUtils.AUTHORIZE_URL); accessor.setClientAuthenticationType(OAuth2Message.BASIC_AUTH_TYPE); accessor.setClientId(MockUtils.CLIENT_ID1); accessor.setClientSecret(MockUtils.CLIENT_SECRET1.getBytes("UTF-8")); accessor.setErrorUri(null); accessor.setGrantType(OAuth2Message.AUTHORIZATION); accessor.setRedirectUri(MockUtils.REDIRECT_URI); accessor.setRefreshToken(MockUtils.getRefreshToken()); accessor.setTokenUrl(MockUtils.TOKEN_URL); accessor.setType(OAuth2Accessor.Type.CONFIDENTIAL); accessor.setAuthorizationHeader(Boolean.TRUE); accessor.setRedirecting(Boolean.FALSE); accessor.setUrlParameter(Boolean.FALSE); return accessor; }
@Test public void testHandleRequest_verifyAnonymousTokenOnRequest() throws Exception { MockUtils.DummyHttpFetcher fetcher = (MockUtils.DummyHttpFetcher)MockUtils.getDummyFetcher(); CodeAuthorizationResponseHandler fixture = new CodeAuthorizationResponseHandler( MockUtils.getDummyMessageProvider(), MockUtils.getDummyClientAuthHandlers(), MockUtils.getDummyTokenEndpointResponseHandlers(), fetcher); final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Redirecting(); final HttpServletRequest request = new DummyHttpServletRequest(); final OAuth2HandlerError result = fixture.handleRequest(accessor, request); Assert.assertNull(result); final OAuth2Token accessToken = CodeAuthorizationResponseHandlerTest.store.getToken( accessor.getGadgetUri(), accessor.getServiceName(), accessor.getUser(), accessor.getScope(), OAuth2Token.Type.ACCESS); Assert.assertNotNull(accessToken); Assert.assertEquals("xxx", new String(accessToken.getSecret(), "UTF-8")); Assert.assertEquals(OAuth2Message.BEARER_TOKEN_TYPE, accessToken.getTokenType()); Assert.assertTrue(accessToken.getExpiresAt() > 1000); final OAuth2Token refreshToken = CodeAuthorizationResponseHandlerTest.store.getToken( accessor.getGadgetUri(), accessor.getServiceName(), accessor.getUser(), accessor.getScope(), OAuth2Token.Type.REFRESH); Assert.assertNotNull(refreshToken); Assert.assertEquals("yyy", new String(refreshToken.getSecret(), "UTF-8")); Assert.assertNotNull( fetcher.request ); SecurityToken st = fetcher.request.getSecurityToken(); Assert.assertNotNull( st ); Assert.assertTrue( st.isAnonymous() ); Assert.assertEquals( accessor.getGadgetUri(), st.getAppUrl() ); }
protected static OAuth2Store getDummyStore() throws Exception { if (MockUtils.dummyStore == null) { final OAuth2Cache cache = new InMemoryCache(); final OAuth2Persister persister = MockUtils.getDummyPersister(); final OAuth2Encrypter encrypter = MockUtils.getDummyEncrypter(); final BlobCrypter stateCrypter = MockUtils.getDummyStateCrypter(); MockUtils.dummyStore = MockUtils.getDummyStore(cache, persister, encrypter, MockUtils.REDIRECT_URI, null, null, stateCrypter); } MockUtils.dummyStore.clearCache(); MockUtils.dummyStore.init(); return MockUtils.dummyStore; }
protected static OAuth2TokenPersistence getAccessToken() throws Exception { final OAuth2TokenPersistence accessToken = new OAuth2TokenPersistence( MockUtils.getDummyEncrypter()); MockUtils.setTokenCommons(accessToken); accessToken.setType(OAuth2Token.Type.ACCESS); return accessToken; }
protected static OAuth2Accessor getOAuth2Accessor_ClientCredentialsRedirecting() throws Exception { final OAuth2Cache cache = new InMemoryCache(); final OAuth2Persister persister = MockUtils.getDummyPersister(); final OAuth2Encrypter encrypter = MockUtils.getDummyEncrypter(); final OAuth2Store store = MockUtils.getDummyStore(cache, persister, encrypter, MockUtils.REDIRECT_URI, null, null, MockUtils.stateCrypter); final BasicOAuth2Accessor accessor = new BasicOAuth2Accessor(MockUtils.GADGET_URI1, MockUtils.SERVICE_NAME, MockUtils.USER, MockUtils.SCOPE, true, store, MockUtils.REDIRECT_URI, null, null); accessor.setGrantType(OAuth2Message.CLIENT_CREDENTIALS); accessor.setRedirecting(Boolean.TRUE); return accessor; }
@Before public void setUp() throws Exception { OAuth2TokenPersistenceTest.accessToken = MockUtils.getAccessToken(); OAuth2TokenPersistenceTest.refreshToken = MockUtils.getRefreshToken(); }
protected static List<TokenEndpointResponseHandler> getDummyTokenEndpointResponseHandlers() throws Exception { final List<TokenEndpointResponseHandler> ret = new ArrayList<TokenEndpointResponseHandler>(1); ret.add(new TokenAuthorizationResponseHandler(MockUtils.getDummyMessageProvider(), MockUtils .getDummyStore())); return ret; }
protected static OAuth2Client getClient_Code_Confidential() throws Exception { final OAuth2Client client = new OAuth2Client(MockUtils.getDummyEncrypter()); MockUtils.setClientCommons(client); client.setClientAuthenticationType(OAuth2Message.BASIC_AUTH_TYPE); client.setClientId(MockUtils.CLIENT_ID1); client.setClientSecret(MockUtils.CLIENT_SECRET1.getBytes("UTF-8")); client.setGadgetUri(MockUtils.GADGET_URI1); client.setType(OAuth2Accessor.Type.CONFIDENTIAL); client.setAllowModuleOverride(true); client.setAuthorizationHeader(true); client.setUrlParameter(false); return client; }
@Before public void setUp() throws Exception { OAuth2GadgetContextTest.securityToken = MockUtils.getDummySecurityToken(MockUtils.USER, MockUtils.USER, MockUtils.GADGET_URI1); OAuth2GadgetContextTest.arguments = MockUtils.getDummyArguments(); OAuth2GadgetContextTest.gadgetUri = Uri.parse(MockUtils.GADGET_URI1); }
@Before public void setUp() throws Exception { ClientCredentialsGrantTypeHandlerTest.ccgth = new ClientCredentialsGrantTypeHandler( MockUtils.getDummyClientAuthHandlers()); }
@Test public void testGetEncrypter_1() throws Exception { final OAuth2Encrypter result = OAuth2ClientTest.client1.getEncrypter(); Assert.assertNotNull(result); Assert.assertEquals(MockUtils.getDummyEncrypter(), result); }
@Before public void setUp() throws Exception { CodeAuthorizationResponseHandlerTest.store = MockUtils.getDummyStore(); CodeAuthorizationResponseHandlerTest.carh = new CodeAuthorizationResponseHandler( MockUtils.getDummyMessageProvider(), MockUtils.getDummyClientAuthHandlers(), MockUtils.getDummyTokenEndpointResponseHandlers(), MockUtils.getDummyFetcher()); }