Skip to content

Commit

Permalink
[Es-1985] Added validation for lower case (mosip#1047)
Browse files Browse the repository at this point in the history
Signed-off-by: pvsaidurga <[email protected]>
  • Loading branch information
pvsaidurga committed Jan 15, 2025
1 parent 3997d01 commit 536d2f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public boolean isValid(AuthChallenge authChallenge, ConstraintValidatorContext c
String authFactor = authChallenge.getAuthFactorType();
String format = environment.getProperty(String.format(FORMAT_KEY_PREFIX, authFactor),
String.class);
if( !StringUtils.hasText(authFactor) || !StringUtils.hasText(format)) {
if( !StringUtils.hasText(authFactor) || !StringUtils.hasText(format) || !authChallenge.getAuthFactorType().equals(authFactor.toUpperCase()) ) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(ErrorConstants.INVALID_AUTH_FACTOR_TYPE).addConstraintViolation();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ public void authChallengeFactorFormatValidator_invalidAuthFactorType_thenFail()
assertFalse(isValid);
}

@Test
public void authChallengeFactorFormatValidator_lowerCaseAuthFactorType_thenFail() {
AuthChallenge authChallenge = new AuthChallenge();
authChallenge.setAuthFactorType("otp");
authChallenge.setFormat("alpha-numeric");
authChallenge.setChallenge("111111");
Mockito.when(constraintValidatorContext.buildConstraintViolationWithTemplate(anyString()))
.thenReturn(mock(ConstraintValidatorContext.ConstraintViolationBuilder.class));
boolean isValid = authChallengeFactorFormatValidator.isValid(authChallenge, constraintValidatorContext);
Mockito.verify(constraintValidatorContext).buildConstraintViolationWithTemplate(ErrorConstants.INVALID_AUTH_FACTOR_TYPE);
assertFalse(isValid);
}

@Test
public void authChallengeFactorFormatValidator_invalidChallengeLength_theFail() {
AuthChallenge authChallenge = new AuthChallenge();
Expand Down

0 comments on commit 536d2f9

Please sign in to comment.