use of com.enonic.xp.session.SessionMock in project xp by enonic.
the class LoginHandlerTest method initialize.
@Override
public void initialize() throws Exception {
super.initialize();
this.securityService = Mockito.mock(SecurityService.class);
addService(SecurityService.class, this.securityService);
ContextAccessor.current().getLocalScope().setSession(new SessionMock());
}
use of com.enonic.xp.session.SessionMock in project xp by enonic.
the class LoginHandlerTest method testSessionInvalidatedOnLogin.
@Test
public void testSessionInvalidatedOnLogin() {
final AuthenticationInfo authInfo = TestDataFixtures.createAuthenticationInfo();
final IdProviders idProviders = IdProviders.from(IdProvider.create().displayName("system").key(IdProviderKey.from("system")).build());
Mockito.when(this.securityService.authenticate(Mockito.any())).thenReturn(authInfo);
Mockito.when(this.securityService.getIdProviders()).thenReturn(idProviders);
final SessionMock session = Mockito.spy(new SessionMock());
ContextAccessor.current().getLocalScope().setSession(session);
runScript("/lib/xp/examples/auth/login.js");
verify(session, times(5)).invalidate();
}
use of com.enonic.xp.session.SessionMock in project xp by enonic.
the class IdProviderRequestWrapperTest method isUserInRole.
@Test
void isUserInRole() {
final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.createDefault(), "userId")).login("usr").build();
final AuthenticationInfo authenticationInfo = AuthenticationInfo.create().user(user).principals(RoleKeys.ADMIN).build();
final Context context = ContextBuilder.create().build();
final Session session = new SessionMock();
context.getLocalScope().setSession(session);
session.setAttribute(authenticationInfo);
final Boolean isAdmin = context.callWith(() -> new IdProviderRequestWrapper(request).isUserInRole(RoleKeys.ADMIN.getId()));
assertTrue(isAdmin);
verifyNoInteractions(request);
}
use of com.enonic.xp.session.SessionMock in project xp by enonic.
the class IdProviderRequestWrapperTest method getUserPrincipal.
@Test
void getUserPrincipal() {
final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.createDefault(), "userId")).login("usr").build();
final AuthenticationInfo authenticationInfo = AuthenticationInfo.create().user(user).build();
final Context context = ContextBuilder.create().build();
final Session session = new SessionMock();
context.getLocalScope().setSession(session);
session.setAttribute(authenticationInfo);
final Principal principal = context.callWith(() -> new IdProviderRequestWrapper(request).getUserPrincipal());
assertEquals(principal, user);
verifyNoInteractions(request);
}
use of com.enonic.xp.session.SessionMock in project xp by enonic.
the class HasRoleHandlerTest method initialize.
@Override
public void initialize() throws Exception {
super.initialize();
this.session = new SessionMock();
ContextAccessor.current().getLocalScope().setSession(session);
}
Aggregations