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