Search in sources :

Example 6 with SimpleTestTokenAuthenticator

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

the class CookieClientTests method testMissingCookieName.

@Test(expected = Exception.class)
public void testMissingCookieName() {
    final CookieClient cookieClient = new CookieClient(null, new SimpleTestTokenAuthenticator());
    cookieClient.init();
}
Also used : SimpleTestTokenAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator) Test(org.junit.Test)

Example 7 with SimpleTestTokenAuthenticator

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

the class CookieClientTests method testAuthentication.

@Test
public void testAuthentication() {
    final CookieClient client = new CookieClient(USERNAME, new SimpleTestTokenAuthenticator());
    final MockWebContext context = MockWebContext.create();
    final Cookie c = new Cookie(USERNAME, Base64.getEncoder().encodeToString(getClass().getName().getBytes(StandardCharsets.UTF_8)));
    context.getRequestCookies().add(c);
    final TokenCredentials credentials = client.getCredentials(context);
    final CommonProfile profile = client.getUserProfile(credentials, context);
    assertEquals(c.getValue(), profile.getId());
}
Also used : Cookie(org.pac4j.core.context.Cookie) 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 8 with SimpleTestTokenAuthenticator

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

the class HeaderClientTests method testMissingHeaderName.

@Test
public void testMissingHeaderName() {
    final HeaderClient client = new HeaderClient(null, new SimpleTestTokenAuthenticator());
    TestsHelper.initShouldFail(client, "headerName cannot be blank");
}
Also used : SimpleTestTokenAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator) Test(org.junit.Test)

Example 9 with SimpleTestTokenAuthenticator

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

the class HeaderClientTests method testAuthentication.

@Test
public void testAuthentication() {
    final HeaderClient client = new HeaderClient(HEADER_NAME, PREFIX_HEADER, new SimpleTestTokenAuthenticator());
    final MockWebContext context = MockWebContext.create();
    context.addRequestHeader(HEADER_NAME, PREFIX_HEADER + VALUE);
    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 10 with SimpleTestTokenAuthenticator

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

the class IpClientTests method testMissingProfileCreator.

@Test
public void testMissingProfileCreator() {
    final IpClient client = new IpClient(new SimpleTestTokenAuthenticator());
    client.setProfileCreator(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)

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