use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileServiceImplTest method getTenant1ProfileNoAttributes.
private Profile getTenant1ProfileNoAttributes() {
Profile profile = getTenant1Profile();
profile.getAttributes().clear();
return profile;
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class VerificationServiceImplTest method testSendEmail.
@Test
public void testSendEmail() throws Exception {
Profile profile = new Profile();
profile.setId(PROFILE_ID);
profile.setEmail(PROFILE_EMAIL);
VerificationToken token = new VerificationToken();
token.setId(TOKEN_ID);
verificationService.sendEmail(token, profile, VERIFICATION_BASE_URL, FROM, SUBJECT, TEMPLATE_NAME);
verify(emailFactory).getEmail(FROM, TO, null, null, SUBJECT, TEMPLATE_NAME, VERIFICATION_TEMPLATE_ARGS, true);
verify(email).send();
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class VerificationServiceImplTest method testCreateToken.
@Test
public void testCreateToken() throws Exception {
Profile profile = new Profile();
profile.setId(PROFILE_ID);
profile.setTenant(TENANT_NAME);
VerificationToken token = verificationService.createToken(profile);
assertEquals(TOKEN_ID, token.getId());
assertEquals(TENANT_NAME, token.getTenant());
assertEquals(PROFILE_ID.toString(), token.getProfileId());
assertNotNull(token.getTimestamp());
verify(tokenRepository).insert(any(VerificationToken.class));
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class AddSecurityCookiesProcessorTest method testAddCookiesLoggedIn.
@Test
public void testAddCookiesLoggedIn() throws Exception {
String ticket = new ObjectId().toString();
Date lastModified = new Date();
Profile profile = new Profile();
profile.setLastModified(lastModified);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
RequestContext context = new RequestContext(request, response, null);
RequestSecurityProcessor flushResponseProcessor = new RequestSecurityProcessor() {
@Override
public void processRequest(RequestContext context, RequestSecurityProcessorChain processorChain) throws Exception {
context.getResponse().getOutputStream().flush();
}
};
RequestSecurityProcessorChain chain = new RequestSecurityProcessorChainImpl(Arrays.asList(processor, flushResponseProcessor).iterator());
Authentication auth = new DefaultAuthentication(ticket, profile);
SecurityUtils.setAuthentication(request, auth);
processor.processRequest(context, chain);
Cookie ticketCookie = response.getCookie(SecurityUtils.TICKET_COOKIE_NAME);
assertNotNull(ticketCookie);
assertEquals(ticket, ticketCookie.getValue());
Cookie profileLastModifiedCookie = response.getCookie(SecurityUtils.PROFILE_LAST_MODIFIED_COOKIE_NAME);
assertNotNull(profileLastModifiedCookie);
assertEquals(profile.getLastModified().getTime(), Long.parseLong(profileLastModifiedCookie.getValue()));
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class LoginProcessorTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
DefaultTenantsResolver resolver = new DefaultTenantsResolver();
resolver.setDefaultTenantNames(TENANTS);
processor = new LoginProcessor();
processor.setTenantsResolver(resolver);
processor.setAuthenticationManager(authenticationManager);
processor.setLoginSuccessHandler(loginSuccessHandler);
processor.setLoginFailureHandler(loginFailureHandler);
processor.setRememberMeManager(rememberMeManager);
Profile profile = new Profile();
profile.setUsername(USERNAME);
when(authenticationManager.authenticateUser(TENANTS, USERNAME, VALID_PASSWORD)).thenReturn(new DefaultAuthentication(TICKET, profile));
doThrow(BadCredentialsException.class).when(authenticationManager).authenticateUser(TENANTS, USERNAME, INVALID_PASSWORD);
}
Aggregations