use of org.motechproject.security.domain.PasswordRecovery in project motech by motech.
the class PasswordRecoveryServiceBundleIT method shouldFindRecoveryByTokenAndUserName.
@Test
public void shouldFindRecoveryByTokenAndUserName() throws UserNotFoundException {
String token = passwordRecoveryService.passwordRecoveryRequest(EMAIL, EXPIRATION, true);
PasswordRecovery recovery = recoveriesDataService.findForToken(token);
verifyDefaultRecovery(recovery, token);
recovery = recoveriesDataService.findForUser(USERNAME);
verifyDefaultRecovery(recovery, token);
}
use of org.motechproject.security.domain.PasswordRecovery in project motech by motech.
the class PasswordRecoveryServiceBundleIT method shouldRemoveOldRecovery.
@Test
public void shouldRemoveOldRecovery() throws UserNotFoundException {
// Given
PasswordRecovery recovery1 = new PasswordRecovery();
recovery1.setEmail(EMAIL);
recovery1.setToken(TOKEN);
recovery1.setLocale(Locale.ENGLISH);
recovery1.setUsername(USERNAME);
recovery1.setExpirationDate(EXPIRATION);
recoveriesDataService.create(recovery1);
PasswordRecovery recovery2 = new PasswordRecovery();
recovery2.setEmail(OTHER_EMAIL);
recovery2.setToken(OTHER_TOKEN);
recovery2.setLocale(Locale.ENGLISH);
recovery2.setUsername(OTHER_USERNAME);
recovery2.setExpirationDate(EXPIRATION.minusHours(2));
recoveriesDataService.create(recovery2);
List<PasswordRecovery> recoveries = recoveriesDataService.retrieveAll();
assertEquals(2, recoveries.size());
// When
passwordRecoveryService.cleanUpExpiredRecoveries();
// Then
recoveries = recoveriesDataService.retrieveAll();
// The expired recovery should no longer be present, the non-expired recovery should still be available
assertEquals(1, recoveries.size());
verifyDefaultRecovery(recoveries.get(0), TOKEN);
}
use of org.motechproject.security.domain.PasswordRecovery in project motech by motech.
the class PasswordRecoveryServiceTest method shouldCreateRecoveryWithoutNotification.
@Test
public void shouldCreateRecoveryWithoutNotification() throws UserNotFoundException {
final DateTime now = DateTime.now();
final int expiration = EXPIRATION_HOURS;
testCreateRecoveryTemplate(now, EMAIL, now.plusHours(expiration), false);
ArgumentCaptor<PasswordRecovery> captor = ArgumentCaptor.forClass(PasswordRecovery.class);
verify(passwordRecoveriesDataService).create(captor.capture());
PasswordRecovery createdRecovery = captor.getValue();
assertEquals(USERNAME, createdRecovery.getUsername());
assertEquals(EMAIL, createdRecovery.getEmail());
assertEquals(now.plusHours(expiration), createdRecovery.getExpirationDate());
assertEquals(Locale.ENGLISH, createdRecovery.getLocale());
assertEquals(60, createdRecovery.getToken().length());
verifyZeroInteractions(emailSender);
}
use of org.motechproject.security.domain.PasswordRecovery in project motech by motech.
the class PasswordRecoveryServiceTest method shouldCreateRecoveryAndSendEmail.
@Test
public void shouldCreateRecoveryAndSendEmail() throws UserNotFoundException {
final DateTime now = DateTime.now();
final int expiration = EXPIRATION_HOURS;
testCreateRecoveryTemplate(now, EMAIL, now.plusHours(expiration), true);
ArgumentCaptor<PasswordRecovery> captor = ArgumentCaptor.forClass(PasswordRecovery.class);
verify(passwordRecoveriesDataService).create(captor.capture());
PasswordRecovery createdRecovery = captor.getValue();
assertEquals(USERNAME, createdRecovery.getUsername());
assertEquals(EMAIL, createdRecovery.getEmail());
assertEquals(now.plusHours(expiration), createdRecovery.getExpirationDate());
assertEquals(Locale.ENGLISH, createdRecovery.getLocale());
assertEquals(60, createdRecovery.getToken().length());
verify(emailSender).sendRecoveryEmail(createdRecovery);
}
use of org.motechproject.security.domain.PasswordRecovery in project motech by motech.
the class PasswordRecoveryServiceTest method shouldCreateRecoveryWithDefaultExpirationTimeIfNoneWasProvided.
@Test
public void shouldCreateRecoveryWithDefaultExpirationTimeIfNoneWasProvided() throws UserNotFoundException {
final DateTime now = DateTime.now();
testCreateRecoveryTemplate(now, EMAIL, null, true);
ArgumentCaptor<PasswordRecovery> captor = ArgumentCaptor.forClass(PasswordRecovery.class);
verify(passwordRecoveriesDataService).create(captor.capture());
PasswordRecovery createdRecovery = captor.getValue();
assertEquals(USERNAME, createdRecovery.getUsername());
assertEquals(EMAIL, createdRecovery.getEmail());
// 3 is the default set in PasswordRecoveryServiceImpl
assertEquals(now.plusHours(3), createdRecovery.getExpirationDate());
assertEquals(Locale.ENGLISH, createdRecovery.getLocale());
assertEquals(60, createdRecovery.getToken().length());
verify(emailSender).sendRecoveryEmail(createdRecovery);
}
Aggregations