use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintServiceTest method shouldCreateNewProfileAndDeleteOlderOnes.
@Test
public void shouldCreateNewProfileAndDeleteOlderOnes() throws NotUniqueUserProfileException {
//Given
DevicePrint devicePrint = mock(DevicePrint.class);
List<UserProfile> userProfiles = spy(new ArrayList<UserProfile>());
UserProfile userProfileOne = mock(UserProfile.class);
UserProfile userProfileTwo = mock(UserProfile.class);
UserProfile userProfileThree = mock(UserProfile.class);
userProfiles.add(userProfileOne);
userProfiles.add(userProfileTwo);
userProfiles.add(userProfileThree);
given(userProfilesDao.getProfiles()).willReturn(userProfiles);
given(userProfileOne.getLastSelectedDate()).willReturn(getDate(10));
given(userProfileTwo.getLastSelectedDate()).willReturn(getDate(31));
given(userProfileThree.getLastSelectedDate()).willReturn(getDate(30));
//When
devicePrintService.createNewProfile(devicePrint);
//Then
verify(userProfilesDao).removeProfile(anyString());
verify(userProfiles).remove(userProfileTwo);
verify(userProfiles).remove(userProfileThree);
ArgumentCaptor<UserProfile> userProfileCaptor = ArgumentCaptor.forClass(UserProfile.class);
verify(userProfilesDao).addProfile(userProfileCaptor.capture());
UserProfile userProfile = userProfileCaptor.getValue();
assertEquals(userProfile.getDevicePrint(), devicePrint);
verify(userProfilesDao).saveProfiles();
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintAuthenticationServiceTest method shouldAutoSaveProfilePageWhenSubmittedOTPWithCorrectCodeWithAuthSaveProp.
/**
* 5a) third call, using OPT, 2 - OPT code submitted, with correct code - with Auth Save Profile prop set to "true"
*/
@Test
public void shouldAutoSaveProfilePageWhenSubmittedOTPWithCorrectCodeWithAuthSaveProp() throws AuthLoginException {
//Given
Callback[] callbacks = new Callback[2];
PasswordCallback smsOTPCallback = mock(PasswordCallback.class);
ConfirmationCallback confirmationCallback = mock(ConfirmationCallback.class);
int state = 2;
String otpCode = "OTPCODE";
callbacks[0] = smsOTPCallback;
callbacks[1] = confirmationCallback;
given(smsOTPCallback.getPassword()).willReturn(otpCode.toCharArray());
given(confirmationCallback.getSelectedIndex()).willReturn(0);
given(hotpService.isValidHOTP("OTPCODE")).willReturn(true);
given(devicePrintService.hasRequiredAttributes(Matchers.<DevicePrint>anyObject())).willReturn(true);
given(devicePrintAuthenticationConfig.getBoolean(DevicePrintAuthenticationConfig.AUTO_STORE_PROFILES)).willReturn(true);
//When
int nextState = devicePrintAuthenticationService.process(callbacks, state);
//Then
assertEquals(nextState, ISAuthConstants.LOGIN_SUCCEED);
verify(devicePrintService).createNewProfile(Matchers.<DevicePrint>anyObject());
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintAuthenticationServiceTest method shouldNotSaveProfileIfRequiredAttributesNotSet.
@Test
public void shouldNotSaveProfileIfRequiredAttributesNotSet() throws AuthLoginException {
//Given
Callback[] callbacks = new Callback[2];
PasswordCallback smsOTPCallback = mock(PasswordCallback.class);
ConfirmationCallback confirmationCallback = mock(ConfirmationCallback.class);
int state = 2;
String otpCode = "OTPCODE";
callbacks[0] = smsOTPCallback;
callbacks[1] = confirmationCallback;
given(smsOTPCallback.getPassword()).willReturn(otpCode.toCharArray());
given(confirmationCallback.getSelectedIndex()).willReturn(0);
given(hotpService.isValidHOTP("OTPCODE")).willReturn(true);
given(devicePrintService.hasRequiredAttributes(Matchers.<DevicePrint>anyObject())).willReturn(false);
given(devicePrintAuthenticationConfig.getBoolean(DevicePrintAuthenticationConfig.AUTO_STORE_PROFILES)).willReturn(true);
//When
int nextState = devicePrintAuthenticationService.process(callbacks, state);
//Then
assertEquals(nextState, ISAuthConstants.LOGIN_SUCCEED);
verify(devicePrintService, never()).createNewProfile(Matchers.<DevicePrint>anyObject());
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintAuthenticationServiceTest method shouldSendOTPWhenDevicePrintInfoNotSufficient.
/*
1) first call ISAuthConstants.LOGIN_START - device print attr populated, device print info not sufficient - should return ISAuthConstants.LOGIN_SUCCEED
2) first call ISAuthConstants.LOGIN_START - device print attr populated, with invalid stored profiles using OTP - should return 2
3) first call ISAuthConstants.LOGIN_START - device print attr populated, with a valid stored profile - should return ISAuthConstants.LOGIN_SUCCEED
4) second call, using OPT, 2 - request OPT to be sent - should return 2
5) third call, using OPT, 2 - OPT code submitted, with correct code - should return 3
6) third call, using OPT, 2 - OPT code submitted, with incorrect code - should throw exception
7) fourth call, 3 - don't save profile - should return ISAuthConstants.LOGIN_SUCCEED, with no profile saved
8) fourth call, 3 - save profile, having no valid previous profiles - should create new profile, return ISAuthConstants.LOGIN_SUCCEED
9) fourth call, 3 - save profile, having a valid previous profile - should update previous profile, return ISAuthConstants.LOGIN_SUCCEED
*/
/**
* 1) first call ISAuthConstants.LOGIN_START - device print attr populated, device print info not sufficient - should return 2 (SEND_OPT)
*/
@Test
public void shouldSendOTPWhenDevicePrintInfoNotSufficient() throws AuthLoginException {
//Given
Callback[] callbacks = new Callback[1];
NameCallback devicePrintCallback = mock(NameCallback.class);
int state = ISAuthConstants.LOGIN_START;
DevicePrint devicePrint = mock(DevicePrint.class);
callbacks[0] = devicePrintCallback;
given(devicePrintCallback.getName()).willReturn("DEVICE_PRINT_INFO");
given(devicePrintService.getDevicePrint(request)).willReturn(devicePrint);
given(devicePrintService.hasRequiredAttributes(devicePrint)).willReturn(false);
//When
int nextState = devicePrintAuthenticationService.process(callbacks, state);
//Then
assertEquals(nextState, 2);
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintServiceTest method shouldCreateNewProfile.
@Test
public void shouldCreateNewProfile() throws NotUniqueUserProfileException {
//Given
DevicePrint devicePrint = mock(DevicePrint.class);
given(userProfilesDao.getProfiles()).willReturn(new ArrayList<UserProfile>());
//When
devicePrintService.createNewProfile(devicePrint);
//Then
verify(userProfilesDao).removeProfile(anyString());
ArgumentCaptor<UserProfile> userProfileCaptor = ArgumentCaptor.forClass(UserProfile.class);
verify(userProfilesDao).addProfile(userProfileCaptor.capture());
UserProfile userProfile = userProfileCaptor.getValue();
assertEquals(userProfile.getDevicePrint(), devicePrint);
verify(userProfilesDao).saveProfiles();
}
Aggregations