use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class RecentLoginHistoryTestCase method testDecodeMalformedSuccessObject.
/**
* Tests the behavior when trying to decode a JSON object with a malformed
* set of successful attempts when the malformed attempt is an object.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeMalformedSuccessObject() throws Exception {
final JSONObject o = new JSONObject(new JSONField("successful-attempts", new JSONArray(new JSONObject(new JSONField("malformed", true)))));
new RecentLoginHistory(o);
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class RecentLoginHistoryTestCase method testDecodeMalformedFailureNotObject.
/**
* Tests the behavior when trying to decode a JSON object with a malformed
* set of failed attempts when the malformed attempt is not an object.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeMalformedFailureNotObject() throws Exception {
final JSONObject o = new JSONObject(new JSONField("failed-attempts", new JSONArray(new JSONString("malformed"))));
new RecentLoginHistory(o);
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class PasswordPolicyStateJSONTestCase method testGraceLogins.
/**
* Tests the behavior for the properties related to grace logins.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGraceLogins() throws Exception {
PasswordPolicyStateJSON state = createState(StaticUtils.mapOf(MAXIMUM_GRACE_LOGIN_COUNT, 5, USED_GRACE_LOGIN_COUNT, 0, REMAINING_GRACE_LOGIN_COUNT, 5, GRACE_LOGIN_USE_TIMES, Collections.emptyList()));
assertNotNull(state.getMaximumGraceLoginCount());
assertEquals(state.getMaximumGraceLoginCount().intValue(), 5);
assertNotNull(state.getUsedGraceLoginCount());
assertEquals(state.getUsedGraceLoginCount().intValue(), 0);
assertNotNull(state.getRemainingGraceLoginCount());
assertEquals(state.getRemainingGraceLoginCount().intValue(), 5);
assertNotNull(state.getGraceLoginUseTimes());
assertTrue(state.getGraceLoginUseTimes().isEmpty());
final Date currentDate = new Date();
final Date threeMinutesAgo = new Date(currentDate.getTime() - 3_000L);
final Date twoMinutesAgo = new Date(currentDate.getTime() - 2_000L);
final Date oneMinuteAgo = new Date(currentDate.getTime() - 1_000L);
final List<Date> graceLoginUseTimes = Arrays.asList(threeMinutesAgo, twoMinutesAgo, oneMinuteAgo);
state = createState(StaticUtils.mapOf(MAXIMUM_GRACE_LOGIN_COUNT, 5, USED_GRACE_LOGIN_COUNT, 3, REMAINING_GRACE_LOGIN_COUNT, 2, GRACE_LOGIN_USE_TIMES, graceLoginUseTimes));
assertNotNull(state.getMaximumGraceLoginCount());
assertEquals(state.getMaximumGraceLoginCount().intValue(), 5);
assertNotNull(state.getUsedGraceLoginCount());
assertEquals(state.getUsedGraceLoginCount().intValue(), 3);
assertNotNull(state.getRemainingGraceLoginCount());
assertEquals(state.getRemainingGraceLoginCount().intValue(), 2);
assertNotNull(state.getGraceLoginUseTimes());
assertFalse(state.getGraceLoginUseTimes().isEmpty());
assertEquals(state.getGraceLoginUseTimes(), graceLoginUseTimes);
final JSONObject o = new JSONObject(new JSONField(GRACE_LOGIN_USE_TIMES.getFieldName(), new JSONArray(new JSONString("malformed-timestamp"))));
final Entry entry = new Entry("dn: uid=test.user,ou=People,dc=example,dc=com", "objectClass: top", "objectClass: person", "objectClass: organizationalPerson", "objectClass: inetOrgPerson", "uid: test.user", "givenName: Test", "sn: User", "cn: Test User");
entry.addAttribute("ds-pwp-state-json", o.toSingleLineString());
state = PasswordPolicyStateJSON.get(entry);
assertNotNull(state);
assertNotNull(state.getGraceLoginUseTimes());
assertTrue(state.getGraceLoginUseTimes().isEmpty());
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class PasswordPolicyStateJSONTestCase method testGetPasswordQualityRequirementsPropertyMissingValue.
/**
* Tests the behavior when trying to retrieve password quality requirements
* when the properties array has an object without a value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testGetPasswordQualityRequirementsPropertyMissingValue() throws Exception {
final PasswordPolicyStateJSON state = createState(StaticUtils.mapOf(PASSWORD_QUALITY_REQUIREMENTS, new JSONArray(new JSONObject(new JSONField("description", "description"), new JSONField("client-side-validation-type", "type"), new JSONField("client-side-validation-properties", new JSONArray(new JSONObject(new JSONField("name", "foo")))), new JSONField("applies-to-add", true)))));
assertNotNull(state.getAddPasswordQualityRequirements());
assertFalse(state.getAddPasswordQualityRequirements().isEmpty());
assertEquals(state.getAddPasswordQualityRequirements().size(), 1);
final PasswordQualityRequirement r = state.getAddPasswordQualityRequirements().get(0);
assertEquals(r.getDescription(), "description");
assertEquals(r.getClientSideValidationType(), "type");
assertNotNull(r.getClientSideValidationProperties());
assertTrue(r.getClientSideValidationProperties().isEmpty());
}
use of com.unboundid.util.json.JSONField in project ldapsdk by pingidentity.
the class PasswordPolicyStateJSONTestCase method testMalformedRecentLoginHistory.
/**
* Tests the behavior when trying to retrieve a malformed recent login
* history.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { LDAPException.class })
public void testMalformedRecentLoginHistory() throws Exception {
final PasswordPolicyStateJSON state = createState(StaticUtils.mapOf(RECENT_LOGIN_HISTORY, new JSONObject(new JSONField("successful-attempts", new JSONArray(new JSONObject(new JSONField("malformed", true))))), MAXIMUM_RECENT_LOGIN_HISTORY_SUCCESSFUL_AUTHENTICATION_COUNT, 50, MAXIMUM_RECENT_LOGIN_HISTORY_SUCCESSFUL_AUTHENTICATION_DURATION_SECONDS, (int) TimeUnit.DAYS.toSeconds(30L), MAXIMUM_RECENT_LOGIN_HISTORY_FAILED_AUTHENTICATION_COUNT, 20, MAXIMUM_RECENT_LOGIN_HISTORY_FAILED_AUTHENTICATION_DURATION_SECONDS, (int) TimeUnit.DAYS.toSeconds(10L)));
state.getRecentLoginHistory();
}
Aggregations