Search in sources :

Example 1 with CouchDbSessionAuthenticator

use of com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator in project cloudant-java-sdk by IBM.

the class DelegatingAuthenticatorFactoryTest method getAuthenticatorForSessionAuthType.

@Test
void getAuthenticatorForSessionAuthType() {
    Authenticator authenticator = DelegatingAuthenticatorFactory.getAuthenticator("test", getServicePropsWithAuthType(Authenticator.PROPNAME_AUTH_TYPE, "COUCHDB_SESSION"));
    assertTrue(authenticator instanceof CouchDbSessionAuthenticator, "Should return an " + "instance of CouchDbSessionAuthenticator");
}
Also used : CouchDbSessionAuthenticator(com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) CouchDbSessionAuthenticator(com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator) Test(org.testng.annotations.Test)

Example 2 with CouchDbSessionAuthenticator

use of com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator in project cloudant-java-sdk by IBM.

the class DelegatingAuthenticatorFactoryTest method getAuthenticatorForSessionAuthTypeAlias.

@Test
void getAuthenticatorForSessionAuthTypeAlias() {
    Authenticator authenticator = DelegatingAuthenticatorFactory.getAuthenticator("test", getServicePropsWithAuthType("AUTHTYPE", "COUCHDB_SESSION"));
    assertTrue(authenticator instanceof CouchDbSessionAuthenticator, "Should return an " + "instance of CouchDbSessionAuthenticator");
}
Also used : CouchDbSessionAuthenticator(com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) CouchDbSessionAuthenticator(com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator) Test(org.testng.annotations.Test)

Example 3 with CouchDbSessionAuthenticator

use of com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator in project cloudant-java-sdk by IBM.

the class DelegatingAuthenticatorFactoryTest method getAuthenticatorForOtherAuthType.

@Test
void getAuthenticatorForOtherAuthType() {
    Authenticator authenticator = DelegatingAuthenticatorFactory.getAuthenticator("test", getServicePropsWithAuthType(Authenticator.PROPNAME_AUTH_TYPE, "BASIC"));
    assertFalse(authenticator instanceof CouchDbSessionAuthenticator, "Should not return " + "an instance of CouchDbSessionAuthenticator");
}
Also used : CouchDbSessionAuthenticator(com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) CouchDbSessionAuthenticator(com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator) Test(org.testng.annotations.Test)

Example 4 with CouchDbSessionAuthenticator

use of com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator in project cloudant-java-sdk by IBM.

the class SdkTimeoutTest method testSessionAuthTimeout.

@Test
void testSessionAuthTimeout() throws NoSuchFieldException, IllegalAccessException {
    CouchDbSessionAuthenticator sessionAuth = (CouchDbSessionAuthenticator) CouchDbSessionAuthenticator.newAuthenticator("user", "pass");
    CloudantBaseService myService = createCloudantBaseService(sessionAuth, "http://" + mockedServer.getHostName() + ":" + mockedServer.getPort());
    Request testRequest = createTestRequest(myService);
    for (int i = 0; i < 2; i++) {
        setupSessionAuthRespones();
        if (i == 1) {
            setCustomTimeout(myService, testCases[i]);
        }
        RealCall testRequestCall = createServiceCall(myService, testRequest);
        assertEquals(TimeUnit.MILLISECONDS.toSeconds(testRequestCall.getClient().readTimeoutMillis()), testCases[i]);
        CouchDbSessionAuthenticator auth = (CouchDbSessionAuthenticator) myService.getAuthenticator();
        Field clientField = auth.getClass().getDeclaredField("client");
        clientField.setAccessible(true);
        OkHttpClient c = (OkHttpClient) clientField.get(auth);
        assertEquals(TimeUnit.MILLISECONDS.toSeconds(c.readTimeoutMillis()), authenticationTimeoutValue);
    }
}
Also used : RealCall(okhttp3.internal.connection.RealCall) Field(java.lang.reflect.Field) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) CouchDbSessionAuthenticator(com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator) Test(org.testng.annotations.Test)

Aggregations

CouchDbSessionAuthenticator (com.ibm.cloud.cloudant.security.CouchDbSessionAuthenticator)4 Test (org.testng.annotations.Test)4 Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)3 Field (java.lang.reflect.Field)1 OkHttpClient (okhttp3.OkHttpClient)1 Request (okhttp3.Request)1 RealCall (okhttp3.internal.connection.RealCall)1