Skip to content

Commit

Permalink
Merge pull request #41 from pvsaidurga/develop
Browse files Browse the repository at this point in the history
[ES-722]
  • Loading branch information
ase-101 authored Jan 31, 2024
2 parents cdbda92 + e3a19fa commit f7b9413
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public class GenerateChallengeRequest {
private String locale;
private boolean regenerate;

@io.mosip.signup.validator.Purpose
private Purpose purpose;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class ErrorConstants {
public static final String INVALID_PASSWORD = "invalid_password";
public static final String INVALID_USERINFO = "invalid_username";
public static final String INVALID_CONSENT = "invalid_consent";
public static final String INVALID_PURPOSE ="invalid_purpose";
public static final String IDENTIFIER_MISMATCH = "identifier_mismatch";
public static final String CONSENT_REQUIRED = "consent_required";
public static final String INVALID_TRANSACTION="invalid_transaction";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.mosip.signup.validator;

import io.mosip.signup.util.ErrorConstants;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.TYPE_USE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Target({FIELD, TYPE_USE})
@Retention(RUNTIME)
@Constraint(validatedBy = PurposeValidator.class)
@Documented
public @interface Purpose {
String message() default ErrorConstants.INVALID_PURPOSE;
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.mosip.signup.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import io.mosip.signup.util.Purpose;

public class PurposeValidator implements ConstraintValidator<io.mosip.signup.validator.Purpose, Purpose> {
@Override
public boolean isValid(Purpose value, ConstraintValidatorContext context) {
if(value == null)
return false;
return value.equals(Purpose.REGISTRATION) || value.equals(Purpose.RESET_PASSWORD);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,23 @@ public void doGenerateChallenge_withRegistrationPurpose_thenPass() throws Except
.andExpect(jsonPath("$.errors").isEmpty());
}

@Test
public void doGenerateChallenge_withNullPurpose_returnErrorResponse() throws Exception {
String status = "SUCCESSFUL";
GenerateChallengeResponse generateChallengeResponse = new GenerateChallengeResponse(status);
generateChallengeRequest.setPurpose(null);
when(registrationService.generateChallenge(generateChallengeRequest, ""))
.thenReturn(generateChallengeResponse);

mockMvc.perform(post("/registration/generate-challenge")
.content(objectMapper.writeValueAsString(wrapper))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.response").isEmpty())
.andExpect(jsonPath("$.errors").isNotEmpty())
.andExpect(jsonPath("$.errors[0].errorCode").value(ErrorConstants.INVALID_PURPOSE));
}

@Test
public void doGenerateChallenge_withResetPasswordPurpose_thenPass() throws Exception {
String status = "SUCCESSFUL";
Expand Down

0 comments on commit f7b9413

Please sign in to comment.