use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintAuthenticationServiceTest method shouldUpdateUserProfileWhenHasValidPreviousProfile.
/**
* 9) fourth call, 3 - save profile, having a valid previous profile - should update previous profile, return ISAuthConstants.LOGIN_SUCCEED
*/
@Test
public void shouldUpdateUserProfileWhenHasValidPreviousProfile() throws AuthLoginException {
//Given
NameCallback devicePrintCallback = mock(NameCallback.class);
Callback[] callbacks = new Callback[] { devicePrintCallback };
int state = ISAuthConstants.LOGIN_START;
DevicePrint devicePrint = mock(DevicePrint.class);
UserProfile validStoredMatchingProfile = mock(UserProfile.class);
UserProfile selectedUserProfile = validStoredMatchingProfile;
given(devicePrintService.getDevicePrint(request)).willReturn(devicePrint);
given(devicePrintService.hasRequiredAttributes(devicePrint)).willReturn(true);
given(devicePrintService.getBestMatchingUserProfile(devicePrint)).willReturn(selectedUserProfile);
//When
int nextState = devicePrintAuthenticationService.process(callbacks, state);
//Then
verify(devicePrintService).updateProfile(selectedUserProfile, devicePrint);
assertEquals(nextState, ISAuthConstants.LOGIN_SUCCEED);
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintServiceTest method shouldUpdateProfile.
@Test
public void shouldUpdateProfile() throws NotUniqueUserProfileException {
//Given
UserProfile userProfile = mock(UserProfile.class);
DevicePrint devicePrint = mock(DevicePrint.class);
given(userProfile.getUuid()).willReturn("USER_PROFILE_UUID");
given(userProfilesDao.getProfiles()).willReturn(new ArrayList<UserProfile>());
//When
devicePrintService.updateProfile(userProfile, devicePrint);
//Then
verify(userProfile).setSelectionCounter(anyLong());
verify(userProfile).setLastSelectedDate(Matchers.<Date>anyObject());
verify(userProfile).setDevicePrint(devicePrint);
verify(userProfilesDao).removeProfile(anyString());
verify(userProfilesDao).addProfile(userProfile);
verify(userProfilesDao).saveProfiles();
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintAuthenticationConfigTest method shouldCheckForRequiredAttributesWithSomeRequiredAndPresent.
@Test
public void shouldCheckForRequiredAttributesWithSomeRequiredAndPresent() {
//Given
addToConfigSet(DevicePrintAuthenticationConfig.FONTS_REQUIRED, "true");
addToConfigSet(DevicePrintAuthenticationConfig.GEO_LOCATION_REQUIRED, "false");
addToConfigSet(DevicePrintAuthenticationConfig.PLUGINS_REQUIRED, "true");
addToConfigSet(DevicePrintAuthenticationConfig.SCREEN_PARAMS_REQUIRED, "false");
addToConfigSet(DevicePrintAuthenticationConfig.TIMEZONE_REQUIRED, "false");
addToConfigSet(DevicePrintAuthenticationConfig.USER_AGENT_REQUIRED, "true");
DevicePrint devicePrint = mock(DevicePrint.class);
given(devicePrint.getInstalledFonts()).willReturn("INSTALLED_FONTS");
given(devicePrint.getLatitude()).willReturn(2.0);
given(devicePrint.getLongitude()).willReturn(3.0);
given(devicePrint.getInstalledPlugins()).willReturn("INSTALLED+PLUGINS");
given(devicePrint.getUserAgent()).willReturn("USER_AGENT");
//When
boolean value = devicePrintAuthenticationConfig.hasRequiredAttributes(devicePrint);
//Then
assertTrue(value);
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintAuthenticationConfigTest method shouldCheckForRequiredAttributesWithSomeRequiredButNotAllPresent.
@Test
public void shouldCheckForRequiredAttributesWithSomeRequiredButNotAllPresent() {
//Given
addToConfigSet(DevicePrintAuthenticationConfig.FONTS_REQUIRED, "true");
addToConfigSet(DevicePrintAuthenticationConfig.GEO_LOCATION_REQUIRED, "false");
addToConfigSet(DevicePrintAuthenticationConfig.PLUGINS_REQUIRED, "true");
addToConfigSet(DevicePrintAuthenticationConfig.SCREEN_PARAMS_REQUIRED, "false");
addToConfigSet(DevicePrintAuthenticationConfig.TIMEZONE_REQUIRED, "true");
addToConfigSet(DevicePrintAuthenticationConfig.USER_AGENT_REQUIRED, "true");
DevicePrint devicePrint = mock(DevicePrint.class);
given(devicePrint.getInstalledFonts()).willReturn("INSTALLED_FONTS");
given(devicePrint.getLatitude()).willReturn(2.0);
given(devicePrint.getLongitude()).willReturn(3.0);
given(devicePrint.getInstalledPlugins()).willReturn("INSTALLED+PLUGINS");
given(devicePrint.getScreenColourDepth()).willReturn("SCREEN_COLOUR_DEPTH");
given(devicePrint.getScreenHeight()).willReturn("SCREEN_HEIGHT");
given(devicePrint.getScreenWidth()).willReturn("SCREEN_WIDTH");
given(devicePrint.getUserAgent()).willReturn("USER_AGENT");
//When
boolean value = devicePrintAuthenticationConfig.hasRequiredAttributes(devicePrint);
//Then
assertFalse(value);
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintAuthenticationServiceTest method shouldCreateUserProfileWhenNoValidPreviousProfiles.
/**
* 8) fourth call, 3 - save profile, having no valid previous profiles - should create new profile, return ISAuthConstants.LOGIN_SUCCEED
*/
@Test
public void shouldCreateUserProfileWhenNoValidPreviousProfiles() throws AuthLoginException {
//Given
NameCallback devicePrintCallback = mock(NameCallback.class);
Callback[] callbacks = new Callback[] { devicePrintCallback };
int state = ISAuthConstants.LOGIN_START;
DevicePrint devicePrint = mock(DevicePrint.class);
given(devicePrintService.getDevicePrint(request)).willReturn(devicePrint);
given(devicePrintService.hasRequiredAttributes(devicePrint)).willReturn(false);
devicePrintAuthenticationService.process(callbacks, state);
callbacks = new Callback[1];
ChoiceCallback choiceCallback = mock(ChoiceCallback.class);
state = 3;
callbacks[0] = choiceCallback;
given(choiceCallback.getSelectedIndexes()).willReturn(new int[] { 0 });
//When
int nextState = devicePrintAuthenticationService.process(callbacks, state);
//Then
verify(devicePrintService).createNewProfile(devicePrint);
assertEquals(nextState, ISAuthConstants.LOGIN_SUCCEED);
}
Aggregations