use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DefaultSecurityLogicTests method setUp.
@Before
public void setUp() {
logic = new DefaultSecurityLogic();
context = MockWebContext.create();
sessionStore = new MockSessionStore();
config = new Config();
securityGrantedAccessAdapter = (context, sessionStore, profiles, parameters) -> {
nbCall++;
return null;
};
httpActionAdapter = (act, ctx) -> {
action = act;
return null;
};
clients = null;
authorizers = null;
matchers = null;
nbCall = 0;
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DefaultMatchingCheckerTests method testSecurityHeaders.
@Test
public void testSecurityHeaders() {
final var context = MockWebContext.create();
context.setScheme(SCHEME_HTTPS);
checker.matches(context, new MockSessionStore(), DefaultMatchers.SECURITYHEADERS, new HashMap<>(), new ArrayList<>());
assertNotNull(context.getResponseHeaders().get("Strict-Transport-Security"));
assertNotNull(context.getResponseHeaders().get("X-Content-Type-Options"));
assertNotNull(context.getResponseHeaders().get("X-Content-Type-Options"));
assertNotNull(context.getResponseHeaders().get("X-XSS-Protection"));
assertNotNull(context.getResponseHeaders().get("Cache-Control"));
assertNotNull(context.getResponseHeaders().get("Pragma"));
assertNotNull(context.getResponseHeaders().get("Expires"));
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DefaultMatchingCheckerTests method testCsrfTokenDefaultButIndirectClient.
@Test
public void testCsrfTokenDefaultButIndirectClient() {
final var context = MockWebContext.create();
final List<Client> clients = new ArrayList<>();
clients.add(new MockIndirectClient("test"));
assertTrue(checker.matches(context, new MockSessionStore(), "", new HashMap<>(), clients));
assertTrue(context.getRequestAttribute(Pac4jConstants.CSRF_TOKEN).isPresent());
assertNotNull(WebContextHelper.getCookie(context.getResponseCookies(), Pac4jConstants.CSRF_TOKEN));
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DefaultMatchingCheckerTests method testAllowAjaxRequests.
@Test
public void testAllowAjaxRequests() {
final var context = MockWebContext.create();
checker.matches(context, new MockSessionStore(), DefaultMatchers.ALLOW_AJAX_REQUESTS, new HashMap<>(), new ArrayList<>());
assertEquals("*", context.getResponseHeaders().get(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER));
assertEquals("true", context.getResponseHeaders().get(ACCESS_CONTROL_ALLOW_CREDENTIALS_HEADER));
final var methods = context.getResponseHeaders().get(ACCESS_CONTROL_ALLOW_METHODS_HEADER);
final var methodArray = Arrays.asList(methods.split(",")).stream().map(String::trim).collect(Collectors.toList());
assertTrue(methodArray.contains(HTTP_METHOD.POST.name()));
assertTrue(methodArray.contains(HTTP_METHOD.PUT.name()));
assertTrue(methodArray.contains(HTTP_METHOD.DELETE.name()));
assertTrue(methodArray.contains(HTTP_METHOD.OPTIONS.name()));
assertTrue(methodArray.contains(HTTP_METHOD.GET.name()));
}
use of org.pac4j.core.context.session.MockSessionStore in project pac4j by pac4j.
the class DefaultMatchingCheckerTests method testXssprotection.
@Test
public void testXssprotection() {
final var context = MockWebContext.create();
checker.matches(context, new MockSessionStore(), DefaultMatchers.XSSPROTECTION, new HashMap<>(), new ArrayList<>());
assertNotNull(context.getResponseHeaders().get("X-XSS-Protection"));
}
Aggregations