Search in sources :

Example 1 with DevicePrintAuthenticationConfig

use of org.forgerock.openam.authentication.modules.deviceprint.DevicePrintAuthenticationConfig in project OpenAM by OpenRock.

the class DevicePrintComparatorTest method shouldCompareDevicePrints.

@Test
public void shouldCompareDevicePrints() {
    //Given
    DevicePrint currentDevicePrint = mock(DevicePrint.class);
    DevicePrint storedDevicePrint = mock(DevicePrint.class);
    DevicePrintAuthenticationConfig config = mock(DevicePrintAuthenticationConfig.class);
    given(currentDevicePrint.getUserAgent()).willReturn("USER_AGENT");
    given(storedDevicePrint.getUserAgent()).willReturn("USER_AGENT");
    given(config.getLong(DevicePrintAuthenticationConfig.USER_AGENT_PENALTY_POINTS)).willReturn(100L);
    given(config.getBoolean(DevicePrintAuthenticationConfig.IGNORE_VERSION_IN_USER_AGENT)).willReturn(false);
    given(currentDevicePrint.getInstalledFonts()).willReturn("INSTALLED_FONTS");
    given(storedDevicePrint.getInstalledFonts()).willReturn("INSTALLED_FONTS");
    given(config.getInt(DevicePrintAuthenticationConfig.MAX_TOLERATED_DIFFS_IN_INSTALLED_FONTS)).willReturn(5);
    given(config.getInt(DevicePrintAuthenticationConfig.MAX_TOLERATED_PERCENTAGE_TO_MARK_AS_DIFFERENT_INSTALLED_FONTS)).willReturn(10);
    given(config.getLong(DevicePrintAuthenticationConfig.INSTALLED_FONTS_PENALTY_POINTS)).willReturn(100L);
    given(currentDevicePrint.getInstalledPlugins()).willReturn("INSTALLED_PLUGINS");
    given(storedDevicePrint.getInstalledPlugins()).willReturn("INSTALLED_PLUGINS");
    given(config.getInt(DevicePrintAuthenticationConfig.MAX_TOLERATED_DIFFS_IN_INSTALLED_PLUGINS)).willReturn(5);
    given(config.getInt(DevicePrintAuthenticationConfig.MAX_TOLERATED_PERCENTAGE_TO_MARK_AS_DIFFERENT_PLUGINS)).willReturn(10);
    given(config.getLong(DevicePrintAuthenticationConfig.INSTALLED_PLUGINS_PENALTY_POINTS)).willReturn(100L);
    given(currentDevicePrint.getScreenColourDepth()).willReturn("SCREEN_COLOUR_DEPTH");
    given(storedDevicePrint.getScreenColourDepth()).willReturn("SCREEN_COLOUR_DEPTH");
    given(config.getLong(DevicePrintAuthenticationConfig.SCREEN_COLOUR_DEPTH_PENALTY_POINTS)).willReturn(100L);
    given(currentDevicePrint.getTimezone()).willReturn("TIMEZONE");
    given(storedDevicePrint.getTimezone()).willReturn("TIMEZONE");
    given(config.getLong(DevicePrintAuthenticationConfig.TIMEZONE_PENALTY_POINTS)).willReturn(100L);
    given(currentDevicePrint.getScreenWidth()).willReturn("SCREEN_WIDTH");
    given(storedDevicePrint.getScreenWidth()).willReturn("SCREEN_WIDTH");
    given(currentDevicePrint.getScreenHeight()).willReturn("SCREEN_HEIGHT");
    given(storedDevicePrint.getScreenHeight()).willReturn("SCREEN_HEIGHT");
    given(config.getLong(DevicePrintAuthenticationConfig.SCREEN_RESOLUTION_PENALTY_POINTS)).willReturn(100L);
    given(currentDevicePrint.getLatitude()).willReturn(2.0);
    given(storedDevicePrint.getLatitude()).willReturn(2.0);
    given(currentDevicePrint.getLongitude()).willReturn(3.0);
    given(storedDevicePrint.getLongitude()).willReturn(3.0);
    given(config.getLong(DevicePrintAuthenticationConfig.LOCATION_ALLOWED_RANGE)).willReturn(100L);
    given(config.getLong(DevicePrintAuthenticationConfig.LOCATION_PENALTY_POINTS)).willReturn(100L);
    ComparisonResult cr = new ComparisonResult(10L);
    given(multiValueAttributeComparator.compare(anyString(), anyString(), anyInt(), anyInt(), anyLong())).willReturn(cr);
    given(colocationComparator.compare(anyDouble(), anyDouble(), anyDouble(), anyDouble(), anyLong(), anyLong())).willReturn(cr);
    //When
    ComparisonResult comparisonResult = devicePrintComparator.compare(currentDevicePrint, storedDevicePrint, config);
    //Then
    verify(multiValueAttributeComparator, times(2)).compare(anyString(), anyString(), anyInt(), anyInt(), anyLong());
    verify(colocationComparator).compare(anyDouble(), anyDouble(), anyDouble(), anyDouble(), anyLong(), anyLong());
    assertEquals((long) comparisonResult.getPenaltyPoints(), 30L);
    assertFalse(comparisonResult.getAdditionalInfoInCurrentValue());
}
Also used : DevicePrint(org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint) DevicePrintAuthenticationConfig(org.forgerock.openam.authentication.modules.deviceprint.DevicePrintAuthenticationConfig) Test(org.testng.annotations.Test)

Aggregations

DevicePrintAuthenticationConfig (org.forgerock.openam.authentication.modules.deviceprint.DevicePrintAuthenticationConfig)1 DevicePrint (org.forgerock.openam.authentication.modules.deviceprint.model.DevicePrint)1 Test (org.testng.annotations.Test)1