use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintAuthenticationConfigTest method shouldCheckForRequiredAttributesWithNoneRequiredOrPresent.
@Test
public void shouldCheckForRequiredAttributesWithNoneRequiredOrPresent() {
//Given
addToConfigSet(DevicePrintAuthenticationConfig.FONTS_REQUIRED, "false");
addToConfigSet(DevicePrintAuthenticationConfig.GEO_LOCATION_REQUIRED, "false");
addToConfigSet(DevicePrintAuthenticationConfig.PLUGINS_REQUIRED, "false");
addToConfigSet(DevicePrintAuthenticationConfig.SCREEN_PARAMS_REQUIRED, "false");
addToConfigSet(DevicePrintAuthenticationConfig.TIMEZONE_REQUIRED, "false");
addToConfigSet(DevicePrintAuthenticationConfig.USER_AGENT_REQUIRED, "false");
DevicePrint devicePrint = mock(DevicePrint.class);
//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 shouldCheckForRequiredAttributesWithAllRequiredAndPresent.
@Test
public void shouldCheckForRequiredAttributesWithAllRequiredAndPresent() {
//Given
addToConfigSet(DevicePrintAuthenticationConfig.FONTS_REQUIRED, "true");
addToConfigSet(DevicePrintAuthenticationConfig.GEO_LOCATION_REQUIRED, "true");
addToConfigSet(DevicePrintAuthenticationConfig.PLUGINS_REQUIRED, "true");
addToConfigSet(DevicePrintAuthenticationConfig.SCREEN_PARAMS_REQUIRED, "true");
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.getTimezone()).willReturn("TIMEZONE");
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 DevicePrintAuthenticationServiceTest method shouldLoginSuccessfullyWhenValidMatchingStoredDevicePrintProfilesFound.
/**
* 3) first call ISAuthConstants.LOGIN_START - device print attr populated, with a valid stored profile - should return ISAuthConstants.LOGIN_SUCCEED
*/
@Test
public void shouldLoginSuccessfullyWhenValidMatchingStoredDevicePrintProfilesFound() throws AuthLoginException {
//Given
Callback[] callbacks = new Callback[1];
NameCallback devicePrintCallback = mock(NameCallback.class);
int state = ISAuthConstants.LOGIN_START;
DevicePrint devicePrint = mock(DevicePrint.class);
UserProfile validStoredMatchingProfile = mock(UserProfile.class);
UserProfile selectedUserProfile = validStoredMatchingProfile;
callbacks[0] = devicePrintCallback;
given(devicePrintCallback.getName()).willReturn("DEVICE_PRINT_INFO");
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
assertEquals(nextState, ISAuthConstants.LOGIN_SUCCEED);
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintServiceTest method shouldGetBestMatchingUserProfile.
@Test
public void shouldGetBestMatchingUserProfile() {
//Given
DevicePrint devicePrint = mock(DevicePrint.class);
List<UserProfile> userProfiles = new ArrayList<UserProfile>();
UserProfile userProfileOne = mock(UserProfile.class);
UserProfile userProfileTwo = mock(UserProfile.class);
UserProfile userProfileThree = mock(UserProfile.class);
DevicePrint userProfileOneDevicePrint = mock(DevicePrint.class);
DevicePrint userProfileTwoDevicePrint = mock(DevicePrint.class);
DevicePrint userProfileThreeDevicePrint = mock(DevicePrint.class);
ComparisonResult userProfileOneResult = new ComparisonResult(30L);
ComparisonResult userProfileThreeResult = new ComparisonResult(20L);
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(29));
given(userProfileOne.getDevicePrint()).willReturn(userProfileOneDevicePrint);
given(userProfileTwo.getDevicePrint()).willReturn(userProfileTwoDevicePrint);
given(userProfileThree.getDevicePrint()).willReturn(userProfileThreeDevicePrint);
given(devicePrintComparator.compare(devicePrint, userProfileOneDevicePrint, devicePrintAuthenticationConfig)).willReturn(userProfileOneResult);
given(devicePrintComparator.compare(devicePrint, userProfileThreeDevicePrint, devicePrintAuthenticationConfig)).willReturn(userProfileThreeResult);
given(devicePrintAuthenticationConfig.getLong(DevicePrintAuthenticationConfig.MAX_TOLERATED_PENALTY_POINTS)).willReturn(50L);
//When
UserProfile selectedUserProfile = devicePrintService.getBestMatchingUserProfile(devicePrint);
//Then
assertEquals(selectedUserProfile, userProfileThree);
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint in project OpenAM by OpenRock.
the class DevicePrintServiceTest method shouldGetBestMatchingUserProfileWithNoStoredProfiles.
@Test
public void shouldGetBestMatchingUserProfileWithNoStoredProfiles() {
//Given
DevicePrint devicePrint = mock(DevicePrint.class);
List<UserProfile> userProfiles = new ArrayList<UserProfile>();
given(userProfilesDao.getProfiles()).willReturn(userProfiles);
//When
UserProfile selectedUserProfile = devicePrintService.getBestMatchingUserProfile(devicePrint);
//Then
assertNull(selectedUserProfile);
}
Aggregations