Search in sources :

Example 36 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class FormClientTests method testGetCredentialsMissingPassword.

@Test
public void testGetCredentialsMissingPassword() {
    final var formClient = getFormClient();
    final var context = MockWebContext.create();
    final var action = (FoundAction) TestsHelper.expectException(() -> formClient.getCredentials(context.addRequestParameter(formClient.getPasswordParameter(), PASSWORD), new MockSessionStore()));
    assertEquals(302, action.getCode());
    assertEquals(LOGIN_URL + "?" + formClient.getUsernameParameter() + "=&" + FormClient.ERROR_PARAMETER + "=" + FormClient.MISSING_FIELD_ERROR, action.getLocation());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) FoundAction(org.pac4j.core.exception.http.FoundAction) Test(org.junit.Test)

Example 37 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class FormClientTests method testGetRightCredentials.

@Test
public void testGetRightCredentials() {
    final var formClient = getFormClient();
    final var credentials = (UsernamePasswordCredentials) formClient.getCredentials(MockWebContext.create().addRequestParameter(formClient.getUsernameParameter(), USERNAME).addRequestParameter(formClient.getPasswordParameter(), USERNAME), new MockSessionStore()).get();
    assertEquals(USERNAME, credentials.getUsername());
    assertEquals(USERNAME, credentials.getPassword());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Example 38 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class FormClientTests method testMissingProfileCreator.

@Test
public void testMissingProfileCreator() {
    final var formClient = new FormClient(LOGIN_URL, new SimpleTestUsernamePasswordAuthenticator());
    formClient.setCallbackUrl(CALLBACK_URL);
    formClient.setProfileCreator(null);
    TestsHelper.expectException(() -> formClient.getUserProfile(new UsernamePasswordCredentials(USERNAME, PASSWORD), MockWebContext.create(), new MockSessionStore()), TechnicalException.class, "profileCreator cannot be null");
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) SimpleTestUsernamePasswordAuthenticator(org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Test(org.junit.Test)

Example 39 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class IpRegexpAuthenticatorTests method testNoPattern.

@Test(expected = TechnicalException.class)
public void testNoPattern() {
    final var credentials = new TokenCredentials(GOOD_IP);
    var authenticator = new IpRegexpAuthenticator();
    authenticator.validate(credentials, null, new MockSessionStore());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 40 with MockSessionStore

use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.

the class DigestExtractorTests method testNotDigest.

@Test
public void testNotDigest() {
    final var context = MockWebContext.create();
    final var credentials = digestExtractor.extract(context, new MockSessionStore());
    assertFalse(credentials.isPresent());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) Test(org.junit.Test)

Aggregations

MockSessionStore (org.pac4j.core.context.session.MockSessionStore)164 Test (org.junit.Test)151 FoundAction (org.pac4j.core.exception.http.FoundAction)29 SessionStore (org.pac4j.core.context.session.SessionStore)22 CommonProfile (org.pac4j.core.profile.CommonProfile)20 TokenCredentials (org.pac4j.core.credentials.TokenCredentials)19 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)17 MockWebContext (org.pac4j.core.context.MockWebContext)15 WebContext (org.pac4j.core.context.WebContext)15 CasConfiguration (org.pac4j.cas.config.CasConfiguration)14 HttpAction (org.pac4j.core.exception.http.HttpAction)12 SimpleTestTokenAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestTokenAuthenticator)11 AnonymousProfile (org.pac4j.core.profile.AnonymousProfile)9 SimpleTestUsernamePasswordAuthenticator (org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator)7 CasProfile (org.pac4j.cas.profile.CasProfile)6 HashMap (java.util.HashMap)5 Authorizer (org.pac4j.core.authorization.authorizer.Authorizer)5 RequireAnyRoleAuthorizer (org.pac4j.core.authorization.authorizer.RequireAnyRoleAuthorizer)5 OkAction (org.pac4j.core.exception.http.OkAction)5 URL (java.net.URL)4