Search in sources :

Example 26 with MockSessionStore

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

the class BaseClientTests method testAlreadyTried.

@Test
public void testAlreadyTried() {
    final var client = new MockIndirectClient(TYPE, new FoundAction(LOGIN_URL), Optional.empty(), new CommonProfile());
    client.setCallbackUrl(CALLBACK_URL);
    final var context = MockWebContext.create();
    final SessionStore sessionStore = new MockSessionStore();
    sessionStore.set(context, client.getName() + IndirectClient.ATTEMPTED_AUTHENTICATION_SUFFIX, "true");
    final var e = (HttpAction) TestsHelper.expectException(() -> client.getRedirectionAction(context, sessionStore));
    assertEquals(401, e.getCode());
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) SessionStore(org.pac4j.core.context.session.SessionStore) MockSessionStore(org.pac4j.core.context.session.MockSessionStore) FoundAction(org.pac4j.core.exception.http.FoundAction) CommonProfile(org.pac4j.core.profile.CommonProfile) HttpAction(org.pac4j.core.exception.http.HttpAction) Test(org.junit.Test)

Example 27 with MockSessionStore

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

the class IsAnonymousAuthorizerTests method testAnonymousProfile.

@Test
public void testAnonymousProfile() {
    profiles.add(new AnonymousProfile());
    assertTrue(authorizer.isAuthorized(null, new MockSessionStore(), profiles));
}
Also used : AnonymousProfile(org.pac4j.core.profile.AnonymousProfile) MockSessionStore(org.pac4j.core.context.session.MockSessionStore) Test(org.junit.Test)

Example 28 with MockSessionStore

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

the class IsAnonymousAuthorizerTests method testCommonProfileRedirectionUrl.

@Test
public void testCommonProfileRedirectionUrl() {
    profiles.add(new CommonProfile());
    authorizer.setRedirectionUrl(PAC4J_URL);
    TestsHelper.expectException(() -> authorizer.isAuthorized(MockWebContext.create(), new MockSessionStore(), profiles), HttpAction.class, "Performing a 302 HTTP action");
}
Also used : MockSessionStore(org.pac4j.core.context.session.MockSessionStore) CommonProfile(org.pac4j.core.profile.CommonProfile) Test(org.junit.Test)

Example 29 with MockSessionStore

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

the class IsAnonymousAuthorizerTests method testAnonProfileTwoProfiles.

@Test
public void testAnonProfileTwoProfiles() {
    profiles.add(new AnonymousProfile());
    profiles.add(new CommonProfile());
    assertFalse(authorizer.isAuthorized(null, new MockSessionStore(), profiles));
}
Also used : AnonymousProfile(org.pac4j.core.profile.AnonymousProfile) MockSessionStore(org.pac4j.core.context.session.MockSessionStore) CommonProfile(org.pac4j.core.profile.CommonProfile) Test(org.junit.Test)

Example 30 with MockSessionStore

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

the class DefaultMatchingCheckerTests method testHsts.

@Test
public void testHsts() {
    final var context = MockWebContext.create();
    context.setScheme(SCHEME_HTTPS);
    checker.matches(context, new MockSessionStore(), DefaultMatchers.HSTS, new HashMap<>(), new ArrayList<>());
    assertNotNull(context.getResponseHeaders().get("Strict-Transport-Security"));
}
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