Search in sources :

Example 6 with Credentials

use of com.burgstaller.okhttp.digest.Credentials in project okhttp-digest by rburgst.

the class BasicAuthenticatorWithMockWebserverTest method setUp.

@Before
public void setUp() throws Exception {
    credentials = new Credentials("user1", "user1");
    sut = new BasicAuthenticator(credentials);
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    final Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>();
    HttpLoggingInterceptor logger = new HttpLoggingInterceptor(new StdOutLogger());
    logger.setLevel(HttpLoggingInterceptor.Level.HEADERS);
    spy = spy(sut);
    client = builder.authenticator(new CachingAuthenticatorDecorator(spy, authCache)).addInterceptor(new AuthenticationCacheInterceptor(authCache)).addNetworkInterceptor(logger).build();
    unauthorizedResponse = new MockResponse().setResponseCode(401).addHeader("WWW-Authenticate", "Basic realm=\"myrealm\"");
    successResponse = new MockResponse().setBody("OK");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) OkHttpClient(okhttp3.OkHttpClient) CachingAuthenticator(com.burgstaller.okhttp.digest.CachingAuthenticator) CachingAuthenticatorDecorator(com.burgstaller.okhttp.CachingAuthenticatorDecorator) AuthenticationCacheInterceptor(com.burgstaller.okhttp.AuthenticationCacheInterceptor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Credentials(com.burgstaller.okhttp.digest.Credentials) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Before(org.junit.Before)

Aggregations

Credentials (com.burgstaller.okhttp.digest.Credentials)6 BasicAuthenticator (com.burgstaller.okhttp.basic.BasicAuthenticator)5 Request (okhttp3.Request)4 DigestAuthenticator (com.burgstaller.okhttp.digest.DigestAuthenticator)3 AuthenticationCacheInterceptor (com.burgstaller.okhttp.AuthenticationCacheInterceptor)2 CachingAuthenticatorDecorator (com.burgstaller.okhttp.CachingAuthenticatorDecorator)2 CachingAuthenticator (com.burgstaller.okhttp.digest.CachingAuthenticator)2 Response (okhttp3.Response)2 Test (org.junit.Test)2 DispatchingAuthenticator (com.burgstaller.okhttp.DispatchingAuthenticator)1 InetSocketAddress (java.net.InetSocketAddress)1 Proxy (java.net.Proxy)1 Type (java.net.Proxy.Type)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Authenticator (okhttp3.Authenticator)1 CacheControl (okhttp3.CacheControl)1 OkHttpClient (okhttp3.OkHttpClient)1 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Before (org.junit.Before)1