use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class CsrfAuthorizerTests method testParameterExpiredDate.
@Test
public void testParameterExpiredDate() {
final var expiredDate = new Date().getTime() - 1000;
final WebContext context = MockWebContext.create().addRequestParameter(Pac4jConstants.CSRF_TOKEN, VALUE);
final SessionStore sessionStore = new MockSessionStore();
sessionStore.set(context, Pac4jConstants.CSRF_TOKEN, VALUE);
sessionStore.set(context, Pac4jConstants.CSRF_TOKEN_EXPIRATION_DATE, expiredDate);
Assert.assertFalse(authorizer.isAuthorized(context, sessionStore, null));
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class CsrfAuthorizerTests method testHeaderOkNewName.
@Test
public void testHeaderOkNewName() {
final WebContext context = MockWebContext.create().addRequestHeader(NAME, VALUE);
final SessionStore sessionStore = new MockSessionStore();
sessionStore.set(context, Pac4jConstants.CSRF_TOKEN, VALUE);
sessionStore.set(context, Pac4jConstants.CSRF_TOKEN_EXPIRATION_DATE, expirationDate);
authorizer.setHeaderName(NAME);
Assert.assertTrue(authorizer.isAuthorized(context, sessionStore, null));
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class CsrfAuthorizerTests method internalTestNoTokenRequest.
private void internalTestNoTokenRequest(final HttpConstants.HTTP_METHOD method) {
final var context = MockWebContext.create();
final SessionStore sessionStore = new MockSessionStore();
sessionStore.set(context, Pac4jConstants.CSRF_TOKEN, VALUE);
sessionStore.set(context, Pac4jConstants.CSRF_TOKEN_EXPIRATION_DATE, expirationDate);
context.setRequestMethod(method.name());
Assert.assertFalse(authorizer.isAuthorized(context, sessionStore, null));
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class CsrfAuthorizerTests method testHeaderOkButNoTokenInSession.
@Test
public void testHeaderOkButNoTokenInSession() {
final WebContext context = MockWebContext.create().addRequestHeader(Pac4jConstants.CSRF_TOKEN, VALUE);
final SessionStore sessionStore = new MockSessionStore();
sessionStore.set(context, Pac4jConstants.CSRF_TOKEN_EXPIRATION_DATE, expirationDate);
Assert.assertFalse(authorizer.isAuthorized(context, sessionStore, null));
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class CsrfAuthorizerTests method testParameterOkPreviousToken.
@Test
public void testParameterOkPreviousToken() {
final WebContext context = MockWebContext.create().addRequestParameter(Pac4jConstants.CSRF_TOKEN, VALUE);
final SessionStore sessionStore = new MockSessionStore();
sessionStore.set(context, Pac4jConstants.PREVIOUS_CSRF_TOKEN, VALUE);
sessionStore.set(context, Pac4jConstants.CSRF_TOKEN, KEY);
sessionStore.set(context, Pac4jConstants.CSRF_TOKEN_EXPIRATION_DATE, expirationDate);
Assert.assertTrue(authorizer.isAuthorized(context, sessionStore, null));
Assert.assertFalse(sessionStore.get(context, Pac4jConstants.PREVIOUS_CSRF_TOKEN).isPresent());
}
Aggregations