GuestAuthenticator implements Authenticator { GuestSession getExpiredSession(Response response) { final Headers headers = response.request().headers(); final String auth = headers.get(OAuthConstants.HEADER_AUTHORIZATION); final String guest = headers.get(OAuthConstants.HEADER_GUEST_TOKEN); if (auth != null && guest != null) { final GuestAuthToken token = new GuestAuthToken("bearer", auth.replace("bearer ", ""), guest); return new GuestSession(token); } return null; } GuestAuthenticator(GuestSessionProvider guestSessionProvider); @Override Request authenticate(Route route, Response response);  }
@Test public void testGetExpiredToken() { final GuestSession session = authenticator.getExpiredSession(response); final GuestAuthToken token = session.getAuthToken(); assertEquals(TEST_GUEST_TOKEN, token.getGuestToken()); assertEquals(TEST_ACCESS_TOKEN, token.getAccessToken()); }
@Test public void testGetExpiredToken_emptyHeaders() { request = new Request.Builder() .url(TEST_URL) .build(); response = new Response.Builder() .code(401) .message("Unauthorized") .protocol(Protocol.HTTP_1_1) .request(request) .build(); final GuestSession session = authenticator.getExpiredSession(response); assertNull(session); }