GuestAuthInterceptor implements Interceptor { static void addAuthHeaders(Request.Builder builder, GuestAuthToken token) { final String authHeader = token.getTokenType() + " " + token.getAccessToken(); builder.header(OAuthConstants.HEADER_AUTHORIZATION, authHeader); builder.header(OAuthConstants.HEADER_GUEST_TOKEN, token.getGuestToken()); } GuestAuthInterceptor(GuestSessionProvider guestSessionProvider); @Override Response intercept(Chain chain);  }
@Test public void testAddAuthHeaders() { final Request.Builder builder = new Request.Builder().url(TEST_URL); GuestAuthInterceptor.addAuthHeaders(builder, mockAuthToken); final Request request = builder.build(); assertEquals(TEST_HEADER_AUTHORIZATION, request.header(OAuthConstants.HEADER_AUTHORIZATION)); assertEquals(TEST_GUEST_TOKEN, request.header(OAuthConstants.HEADER_GUEST_TOKEN)); }
@Test public void testAddAuthHeaders_removesOldHeaders() { final Request.Builder builder = new Request.Builder().url(TEST_URL); builder.header(OAuthConstants.HEADER_AUTHORIZATION, "23233"); builder.header(OAuthConstants.HEADER_GUEST_TOKEN, "djfhjASEfjvncdjfhdkjASjshdj"); builder.header(TEST_HEADER, TEST_HEADER); GuestAuthInterceptor.addAuthHeaders(builder, mockAuthToken); final Request request = builder.build(); assertEquals(TEST_HEADER_AUTHORIZATION, request.header(OAuthConstants.HEADER_AUTHORIZATION)); assertEquals(TEST_GUEST_TOKEN, request.header(OAuthConstants.HEADER_GUEST_TOKEN)); assertEquals(TEST_HEADER, request.header(TEST_HEADER)); }