Search in sources :

Example 11 with SimpleTestTokenAuthenticator

use of org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator in project pac4j by pac4j.

the class IpClientTests method testAuthentication.

@Test
public void testAuthentication() {
    final IpClient client = new IpClient(new SimpleTestTokenAuthenticator());
    final MockWebContext context = MockWebContext.create();
    context.setRemoteAddress(IP);
    final TokenCredentials credentials = client.getCredentials(context);
    final CommonProfile profile = client.getUserProfile(credentials, context);
    assertEquals(IP, profile.getId());
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) CommonProfile(org.pac4j.core.profile.CommonProfile) SimpleTestTokenAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 12 with SimpleTestTokenAuthenticator

use of org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator in project pac4j by pac4j.

the class ParameterClientTests method testMissingProfileCreator.

@Test
public void testMissingProfileCreator() {
    final ParameterClient client = new ParameterClient(PARAMETER_NAME, new SimpleTestTokenAuthenticator(), null);
    TestsHelper.expectException(() -> client.getUserProfile(new TokenCredentials(TOKEN), MockWebContext.create()), TechnicalException.class, "profileCreator cannot be null");
}
Also used : SimpleTestTokenAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 13 with SimpleTestTokenAuthenticator

use of org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator in project pac4j by pac4j.

the class ParameterClientTests method testHasDefaultProfileCreator.

@Test
public void testHasDefaultProfileCreator() {
    final ParameterClient client = new ParameterClient(null, new SimpleTestTokenAuthenticator());
    client.setParameterName(PARAMETER_NAME);
    client.init();
}
Also used : SimpleTestTokenAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator) Test(org.junit.Test)

Example 14 with SimpleTestTokenAuthenticator

use of org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator in project pac4j by pac4j.

the class ParameterClientTests method testAuthentication.

@Test
public void testAuthentication() {
    final ParameterClient client = new ParameterClient(PARAMETER_NAME, new SimpleTestTokenAuthenticator());
    client.setSupportGetRequest(SUPPORT_GET);
    client.setSupportPostRequest(SUPPORT_POST);
    final MockWebContext context = MockWebContext.create();
    context.addRequestParameter(PARAMETER_NAME, VALUE);
    context.setRequestMethod(HttpConstants.HTTP_METHOD.GET.name());
    final TokenCredentials credentials = client.getCredentials(context);
    final CommonProfile profile = client.getUserProfile(credentials, context);
    assertEquals(VALUE, profile.getId());
}
Also used : MockWebContext(org.pac4j.core.context.MockWebContext) CommonProfile(org.pac4j.core.profile.CommonProfile) SimpleTestTokenAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 15 with SimpleTestTokenAuthenticator

use of org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator in project pac4j by pac4j.

the class CookieClientTests method testMissingProfileCreator.

@Test
public void testMissingProfileCreator() {
    final CookieClient cookieClient = new CookieClient("testcookie", new SimpleTestTokenAuthenticator());
    cookieClient.setProfileCreator(null);
    TestsHelper.expectException(() -> cookieClient.getUserProfile(new TokenCredentials(TOKEN), MockWebContext.create()), TechnicalException.class, "profileCreator cannot be null");
}
Also used : SimpleTestTokenAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)17 SimpleTestTokenAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator)17 TokenCredentials (org.pac4j.core.credentials.TokenCredentials)8 MockWebContext (org.pac4j.core.context.MockWebContext)4 CommonProfile (org.pac4j.core.profile.CommonProfile)4 Cookie (org.pac4j.core.context.Cookie)1 DigestCredentials (org.pac4j.http.credentials.DigestCredentials)1