diff --git a/esignet-core/src/main/java/io/mosip/esignet/core/constants/ErrorConstants.java b/esignet-core/src/main/java/io/mosip/esignet/core/constants/ErrorConstants.java index d60d1dc55..005d12968 100644 --- a/esignet-core/src/main/java/io/mosip/esignet/core/constants/ErrorConstants.java +++ b/esignet-core/src/main/java/io/mosip/esignet/core/constants/ErrorConstants.java @@ -84,4 +84,5 @@ public class ErrorConstants { public static final String PROOF_HEADER_INVALID_ALG = "proof_header_invalid_alg"; public static final String PROOF_HEADER_INVALID_KEY = "proof_header_invalid_key"; public static final String PROOF_HEADER_AMBIGUOUS_KEY = "proof_header_ambiguous_key"; + public static final String INVALID_CHALLENGE_FORMAT_FOR_AUTH_FACTOR_TYPE = "invalid_challenge_format_for_auth_factor_type"; } diff --git a/esignet-core/src/main/java/io/mosip/esignet/core/dto/ClientDetailCreateRequestV2.java b/esignet-core/src/main/java/io/mosip/esignet/core/dto/ClientDetailCreateRequestV2.java index 569daf42b..15ebc69a0 100644 --- a/esignet-core/src/main/java/io/mosip/esignet/core/dto/ClientDetailCreateRequestV2.java +++ b/esignet-core/src/main/java/io/mosip/esignet/core/dto/ClientDetailCreateRequestV2.java @@ -6,6 +6,7 @@ package io.mosip.esignet.core.dto; import io.mosip.esignet.core.constants.ErrorConstants; +import io.mosip.esignet.core.validator.ClientNameLang; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -22,7 +23,7 @@ public class ClientDetailCreateRequestV2 extends ClientDetailCreateRequest { @NotEmpty(message = ErrorConstants.INVALID_CLIENT_NAME) - private Map<@Size(message= ErrorConstants.INVALID_CLIENT_NAME_MAP_KEY, min=3, max=3) String, + private Map<@ClientNameLang String, @NotBlank(message = ErrorConstants.INVALID_CLIENT_NAME_MAP_VALUE) String> clientNameLangMap; public ClientDetailCreateRequestV2(String clientId, String clientName, Map publicKey, String relyingPartyId, diff --git a/esignet-core/src/main/java/io/mosip/esignet/core/dto/ClientDetailUpdateRequestV2.java b/esignet-core/src/main/java/io/mosip/esignet/core/dto/ClientDetailUpdateRequestV2.java index 52f770c86..08483f915 100644 --- a/esignet-core/src/main/java/io/mosip/esignet/core/dto/ClientDetailUpdateRequestV2.java +++ b/esignet-core/src/main/java/io/mosip/esignet/core/dto/ClientDetailUpdateRequestV2.java @@ -6,6 +6,7 @@ package io.mosip.esignet.core.dto; import io.mosip.esignet.core.constants.ErrorConstants; +import io.mosip.esignet.core.validator.ClientNameLang; import lombok.Data; import lombok.NoArgsConstructor; @@ -18,7 +19,7 @@ public class ClientDetailUpdateRequestV2 extends ClientDetailUpdateRequest { @NotEmpty(message = ErrorConstants.INVALID_CLIENT_NAME) - private Map<@Size(message = ErrorConstants.INVALID_CLIENT_NAME_MAP_KEY, min = 3, max = 3) String, + private Map<@ClientNameLang String, @NotBlank(message = ErrorConstants.INVALID_CLIENT_NAME_MAP_VALUE) String> clientNameLangMap; public ClientDetailUpdateRequestV2(String logUri, List redirectUris, List userClaims, List authContextRefs, String status, List grantTypes, String clientName, List clientAuthMethods, Map clientNameLangMap){ diff --git a/esignet-core/src/main/java/io/mosip/esignet/core/validator/ClientNameLang.java b/esignet-core/src/main/java/io/mosip/esignet/core/validator/ClientNameLang.java new file mode 100644 index 000000000..f1a4e1607 --- /dev/null +++ b/esignet-core/src/main/java/io/mosip/esignet/core/validator/ClientNameLang.java @@ -0,0 +1,24 @@ +package io.mosip.esignet.core.validator; + +import io.mosip.esignet.core.constants.ErrorConstants; + +import javax.validation.Constraint; +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 = ClientNameLangValidator.class) +@Documented +public @interface ClientNameLang { + String message() default ErrorConstants.INVALID_CLIENT_NAME_MAP_KEY; + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/esignet-core/src/main/java/io/mosip/esignet/core/validator/ClientNameLangValidator.java b/esignet-core/src/main/java/io/mosip/esignet/core/validator/ClientNameLangValidator.java new file mode 100644 index 000000000..69d6f9b59 --- /dev/null +++ b/esignet-core/src/main/java/io/mosip/esignet/core/validator/ClientNameLangValidator.java @@ -0,0 +1,22 @@ +package io.mosip.esignet.core.validator; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import java.util.Arrays; +import java.util.Locale; + +public class ClientNameLangValidator implements ConstraintValidator { + + private static final Locale[] availableLocales = Locale.getAvailableLocales(); + + @Override + public void initialize(ClientNameLang constraintAnnotation) { + } + + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + boolean isValid = Arrays.stream(availableLocales) + .anyMatch(locale -> value.equals(locale.getISO3Language())); + return isValid; + } +} \ No newline at end of file diff --git a/esignet-integration-api/src/main/java/io/mosip/esignet/api/dto/AuthChallenge.java b/esignet-integration-api/src/main/java/io/mosip/esignet/api/dto/AuthChallenge.java index 23efa919f..501b35455 100644 --- a/esignet-integration-api/src/main/java/io/mosip/esignet/api/dto/AuthChallenge.java +++ b/esignet-integration-api/src/main/java/io/mosip/esignet/api/dto/AuthChallenge.java @@ -6,11 +6,13 @@ package io.mosip.esignet.api.dto; import io.mosip.esignet.api.util.ErrorConstants; +import io.mosip.esignet.api.validator.TypeFormatMapping; import lombok.Data; import javax.validation.constraints.NotBlank; @Data +@TypeFormatMapping public class AuthChallenge { @NotBlank(message = ErrorConstants.INVALID_AUTH_FACTOR_TYPE) diff --git a/esignet-integration-api/src/main/java/io/mosip/esignet/api/util/ErrorConstants.java b/esignet-integration-api/src/main/java/io/mosip/esignet/api/util/ErrorConstants.java index 9accf4665..919958801 100644 --- a/esignet-integration-api/src/main/java/io/mosip/esignet/api/util/ErrorConstants.java +++ b/esignet-integration-api/src/main/java/io/mosip/esignet/api/util/ErrorConstants.java @@ -15,6 +15,7 @@ public class ErrorConstants { public static final String INVALID_AUTH_FACTOR_TYPE="invalid_auth_factor_type"; public static final String INVALID_CHALLENGE="invalid_challenge"; public static final String INVALID_CHALLENGE_FORMAT = "invalid_challenge_format"; + public static final String INVALID_CHALLENGE_FORMAT_FOR_AUTH_FACTOR_TYPE = "invalid_challenge_format_for_auth_factor_type"; public static final String BINDING_AUTH_FAILED = "binding_auth_failed"; public static final String VCI_EXCHANGE_FAILED = "vci_exchange_failed"; public static final String NOT_IMPLEMENTED = "not_implemented"; diff --git a/esignet-integration-api/src/main/java/io/mosip/esignet/api/validator/TypeFormatMapping.java b/esignet-integration-api/src/main/java/io/mosip/esignet/api/validator/TypeFormatMapping.java new file mode 100644 index 000000000..1ff4a1ef8 --- /dev/null +++ b/esignet-integration-api/src/main/java/io/mosip/esignet/api/validator/TypeFormatMapping.java @@ -0,0 +1,25 @@ +package io.mosip.esignet.api.validator; + +import io.mosip.esignet.api.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 = TypeFormatMappingValidator.class) +@Documented +public @interface TypeFormatMapping { + String message() default ErrorConstants.INVALID_CHALLENGE_FORMAT_FOR_AUTH_FACTOR_TYPE; + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/esignet-integration-api/src/main/java/io/mosip/esignet/api/validator/TypeFormatMappingValidator.java b/esignet-integration-api/src/main/java/io/mosip/esignet/api/validator/TypeFormatMappingValidator.java new file mode 100644 index 000000000..98dee5c10 --- /dev/null +++ b/esignet-integration-api/src/main/java/io/mosip/esignet/api/validator/TypeFormatMappingValidator.java @@ -0,0 +1,30 @@ +package io.mosip.esignet.api.validator; + +import io.mosip.esignet.api.dto.AuthChallenge; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import java.util.Map; + +@Component +public class TypeFormatMappingValidator implements ConstraintValidator { + + @Value("#{${mosip.esignet.supported-formats}}") + private Map supportedFormats; + + @Override + public void initialize(TypeFormatMapping constraintAnnotation) { + } + + @Override + public boolean isValid(AuthChallenge authChallenge, ConstraintValidatorContext context) { + Object supportedFormatType = supportedFormats.get(authChallenge.getAuthFactorType()); + if (supportedFormatType != null ) { + String supportedFormat = (String) supportedFormatType; + return supportedFormat.equals(authChallenge.getFormat()); + } + return false; + } +} \ No newline at end of file diff --git a/esignet-service/src/main/resources/application-local.properties b/esignet-service/src/main/resources/application-local.properties index fa8634c88..13ad8f6e1 100644 --- a/esignet-service/src/main/resources/application-local.properties +++ b/esignet-service/src/main/resources/application-local.properties @@ -12,6 +12,7 @@ mosip.esignet.access-token-expire-seconds=3600 mosip.esignet.link-code-expire-in-secs=60 mosip.esignet.authentication-expire-in-secs=60 mosip.esignet.cnonce-expire-seconds=20 +mosip.esignet.supported-formats={'OTP': 'alpha-numeric', 'PWD': 'alpha-numeric', 'BIO': 'encoded-json', 'WLA': 'jwt', 'PIN': 'number', 'KBA': 'base64url-encoded-json'} mosip.esignet.header-filter.paths-to-validate={'${server.servlet.path}/authorization/send-otp', \ '${server.servlet.path}/authorization/authenticate', \ diff --git a/esignet-service/src/test/java/io/mosip/esignet/controllers/AuthorizationControllerTest.java b/esignet-service/src/test/java/io/mosip/esignet/controllers/AuthorizationControllerTest.java index f8bc1f194..2dfc69755 100644 --- a/esignet-service/src/test/java/io/mosip/esignet/controllers/AuthorizationControllerTest.java +++ b/esignet-service/src/test/java/io/mosip/esignet/controllers/AuthorizationControllerTest.java @@ -9,6 +9,7 @@ import io.mosip.esignet.api.dto.AuthChallenge; import io.mosip.esignet.api.spi.AuditPlugin; import io.mosip.esignet.core.dto.*; +import io.mosip.esignet.core.dto.Error; import io.mosip.esignet.core.dto.vci.ParsedAccessToken; import io.mosip.esignet.core.exception.EsignetException; import io.mosip.esignet.core.spi.AuthorizationService; @@ -18,6 +19,7 @@ import io.mosip.esignet.services.AuthorizationHelperService; import io.mosip.esignet.services.CacheUtilService; import io.mosip.esignet.vci.services.VCICacheService; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -27,6 +29,7 @@ import org.springframework.http.MediaType; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; import java.time.ZoneOffset; import java.time.ZonedDateTime; @@ -37,6 +40,7 @@ import java.util.List; import static io.mosip.esignet.core.constants.Constants.UTC_DATETIME_PATTERN; +import static io.mosip.esignet.core.constants.ErrorConstants.*; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -733,7 +737,7 @@ public void authenticateEndUser_withValidDetails_returnSuccessResponse() throws AuthChallenge authChallenge = new AuthChallenge(); authChallenge.setChallenge("12345"); authChallenge.setAuthFactorType("OTP"); - authChallenge.setFormat("numeric"); + authChallenge.setFormat("alpha-numeric"); List authChallengeList = new ArrayList<>(); authChallengeList.add(authChallenge); @@ -786,7 +790,165 @@ public void authenticateEndUser_withInvalidTimestamp_returnErrorResponse() throw } @Test - public void authenticateEndUser_withInvalidTransectionId_returnErrorResponse() throws Exception { + public void authenticateEndUser_withInvalidFormat_returnErrorResponse() throws Exception { + AuthRequest authRequest = new AuthRequest(); + authRequest.setIndividualId("1234567890"); + authRequest.setTransactionId("1234567890"); + + AuthChallenge authChallenge = new AuthChallenge(); + authChallenge.setChallenge("1234567890"); + authChallenge.setAuthFactorType("OTP"); + authChallenge.setFormat("jwt"); + + List authChallengeList = new ArrayList<>(); + authChallengeList.add(authChallenge); + + authRequest.setChallengeList(authChallengeList); + + RequestWrapper wrapper = new RequestWrapper<>(); + wrapper.setRequestTime(IdentityProviderUtil.getUTCDateTime()); + wrapper.setRequest(authRequest); + when(authorizationService.authenticateUserV2(authRequest)).thenReturn(new AuthResponseV2()); + mockMvc.perform(post("/authorization/v2/authenticate") + .content(objectMapper.writeValueAsString(wrapper)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.errors").isNotEmpty()) + .andExpect(jsonPath("$.errors[0].errorCode").value(ErrorConstants.INVALID_CHALLENGE_FORMAT_FOR_AUTH_FACTOR_TYPE)) + .andExpect(jsonPath("$.errors[0].errorMessage").value("request.challengeList[0]: invalid_challenge_format_for_auth_factor_type")); + } + + @Test + public void authenticateEndUser_withNullAuthFactorType_returnErrorResponse() throws Exception { + AuthRequest authRequest = new AuthRequest(); + authRequest.setIndividualId("1234567890"); + authRequest.setTransactionId("1234567890"); + + AuthChallenge authChallenge = new AuthChallenge(); + authChallenge.setChallenge("1234567890"); + authChallenge.setAuthFactorType(null); + authChallenge.setFormat("jwt"); + + List authChallengeList = new ArrayList<>(); + authChallengeList.add(authChallenge); + + authRequest.setChallengeList(authChallengeList); + + RequestWrapper wrapper = new RequestWrapper<>(); + wrapper.setRequestTime(IdentityProviderUtil.getUTCDateTime()); + wrapper.setRequest(authRequest); + when(authorizationService.authenticateUserV2(authRequest)).thenReturn(new AuthResponseV2()); + MvcResult mvcResult=mockMvc.perform(post("/authorization/v2/authenticate") + .content(objectMapper.writeValueAsString(wrapper)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andReturn(); + + List errorCodes = Arrays.asList(INVALID_AUTH_FACTOR_TYPE, INVALID_CHALLENGE_FORMAT_FOR_AUTH_FACTOR_TYPE); + ResponseWrapper responseWrapper = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), ResponseWrapper.class); + Assert.assertTrue(responseWrapper.getErrors().size() == 2); + Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(0)).getErrorCode())); + Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(1)).getErrorCode())); + } + + @Test + public void authenticateEndUser_withNullAuthChallenge_returnErrorResponse() throws Exception { + AuthRequest authRequest = new AuthRequest(); + authRequest.setIndividualId("1234567890"); + authRequest.setTransactionId("1234567890"); + + AuthChallenge authChallenge = new AuthChallenge(); + authChallenge.setChallenge("1234567890"); + authChallenge.setAuthFactorType(null); + authChallenge.setFormat(null); + + List authChallengeList = new ArrayList<>(); + authChallengeList.add(authChallenge); + + authRequest.setChallengeList(authChallengeList); + + RequestWrapper wrapper = new RequestWrapper<>(); + wrapper.setRequestTime(IdentityProviderUtil.getUTCDateTime()); + wrapper.setRequest(authRequest); + when(authorizationService.authenticateUserV2(authRequest)).thenReturn(new AuthResponseV2()); + when(authorizationService.authenticateUserV2(authRequest)).thenReturn(new AuthResponseV2()); + MvcResult mvcResult=mockMvc.perform(post("/authorization/v2/authenticate") + .content(objectMapper.writeValueAsString(wrapper)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andReturn(); + + List errorCodes = Arrays.asList(INVALID_AUTH_FACTOR_TYPE, INVALID_CHALLENGE_FORMAT_FOR_AUTH_FACTOR_TYPE,INVALID_CHALLENGE_FORMAT); + ResponseWrapper responseWrapper = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), ResponseWrapper.class); + Assert.assertTrue(responseWrapper.getErrors().size() == 3); + Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(0)).getErrorCode())); + Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(1)).getErrorCode())); + Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(0)).getErrorCode())); + } + + @Test + public void authenticateEndUser_withBlankFormat_returnErrorResponse() throws Exception { + AuthRequest authRequest = new AuthRequest(); + authRequest.setIndividualId("1234567890"); + authRequest.setTransactionId("1234567890"); + + AuthChallenge authChallenge = new AuthChallenge(); + authChallenge.setChallenge("1234567890"); + authChallenge.setAuthFactorType("OTP"); + authChallenge.setFormat(""); + + List authChallengeList = new ArrayList<>(); + authChallengeList.add(authChallenge); + + authRequest.setChallengeList(authChallengeList); + + RequestWrapper wrapper = new RequestWrapper<>(); + wrapper.setRequestTime(IdentityProviderUtil.getUTCDateTime()); + wrapper.setRequest(authRequest); + when(authorizationService.authenticateUserV2(authRequest)).thenReturn(new AuthResponseV2()); + MvcResult mvcResult=mockMvc.perform(post("/authorization/v2/authenticate") + .content(objectMapper.writeValueAsString(wrapper)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andReturn(); + List errorCodes = Arrays.asList(INVALID_CHALLENGE_FORMAT, INVALID_CHALLENGE_FORMAT_FOR_AUTH_FACTOR_TYPE); + ResponseWrapper responseWrapper = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), ResponseWrapper.class); + Assert.assertTrue(responseWrapper.getErrors().size() == 2); + Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(0)).getErrorCode())); + Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(1)).getErrorCode())); + + } + + @Test + public void authenticateEndUser_withNullFormat_returnErrorResponse() throws Exception { + AuthRequest authRequest = new AuthRequest(); + authRequest.setIndividualId("1234567890"); + authRequest.setTransactionId("1234567890"); + + AuthChallenge authChallenge = new AuthChallenge(); + authChallenge.setChallenge("1234567890"); + authChallenge.setAuthFactorType("OTP"); + authChallenge.setFormat(null); + + List authChallengeList = new ArrayList<>(); + authChallengeList.add(authChallenge); + + authRequest.setChallengeList(authChallengeList); + + RequestWrapper wrapper = new RequestWrapper<>(); + wrapper.setRequestTime(IdentityProviderUtil.getUTCDateTime()); + wrapper.setRequest(authRequest); + when(authorizationService.authenticateUserV2(authRequest)).thenReturn(new AuthResponseV2()); + MvcResult mvcResult=mockMvc.perform(post("/authorization/v2/authenticate") + .content(objectMapper.writeValueAsString(wrapper)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andReturn(); + List errorCodes = Arrays.asList(INVALID_CHALLENGE_FORMAT, INVALID_CHALLENGE_FORMAT_FOR_AUTH_FACTOR_TYPE); + ResponseWrapper responseWrapper = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), ResponseWrapper.class); + Assert.assertTrue(responseWrapper.getErrors().size() == 2); + Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(0)).getErrorCode())); + Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(1)).getErrorCode())); + } + + @Test + public void authenticateEndUser_withInvalidTransactionId_returnErrorResponse() throws Exception { AuthRequest authRequest = new AuthRequest(); authRequest.setIndividualId("1234567890"); @@ -857,7 +1019,7 @@ public void getAuthorizationCode_withValidDetails_thenSuccessResposne() throws E } @Test - public void getAuthorizationCode_withInValidAcceptedClaim_thenErrorResposne() throws Exception { + public void getAuthorizationCode_withInValidAcceptedClaim_thenErrorResponse() throws Exception { AuthCodeRequest authCodeRequest = new AuthCodeRequest(); authCodeRequest.setTransactionId("1234567890"); authCodeRequest.setAcceptedClaims(Arrays.asList("name","")); diff --git a/esignet-service/src/test/java/io/mosip/esignet/controllers/ClientMgmtControllerParameterizedTest.java b/esignet-service/src/test/java/io/mosip/esignet/controllers/ClientMgmtControllerParameterizedTest.java index 006b890ac..d4aaa5e01 100644 --- a/esignet-service/src/test/java/io/mosip/esignet/controllers/ClientMgmtControllerParameterizedTest.java +++ b/esignet-service/src/test/java/io/mosip/esignet/controllers/ClientMgmtControllerParameterizedTest.java @@ -114,6 +114,11 @@ public ClientMgmtControllerParameterizedTest(String title, ClientDetailCreateReq Arrays.asList("mosip:idp:acr:static-code"), "https://logo-url/png", Arrays.asList("https://logo-url/png"), Arrays.asList("authorization_code"), Arrays.asList("private_key_jwt"),new HashMap(){{put("eng", "clientname");}}), null, null, ErrorConstants.INVALID_CLIENT_NAME }, + { "With Invalid Language_code", new ClientDetailCreateRequestV2("client-id", "clientname", jwk, + "rp-id", Arrays.asList("given_name"), + Arrays.asList("mosip:idp:acr:static-code"), "https://logo-url/png", + Arrays.asList("https://logo-url/png"), Arrays.asList("authorization_code"), + Arrays.asList("private_key_jwt"),new HashMap(){{put("abc", "clientname");}}), null, null, ErrorConstants.INVALID_CLIENT_NAME_MAP_KEY }, { "With Invalid public key", new ClientDetailCreateRequestV2("client-id", "Test client", new HashMap<>(), "rp-id", Arrays.asList("given_name"), Arrays.asList("mosip:idp:acr:static-code"), "https://logo-url/png", @@ -184,6 +189,10 @@ public ClientMgmtControllerParameterizedTest(String title, ClientDetailCreateReq Arrays.asList("https://logo-url/png"),Arrays.asList("given_name"), Arrays.asList("mosip:idp:acr:static-code"), "ACTIVE", Arrays.asList("authorization_code"), "client-name#1", Arrays.asList("private_key_jwt"),new HashMap(){{put("eng", "clientname");}}), "cid#1", "invalid_client_id" }, + { "update with invalid language_code", null, new ClientDetailUpdateRequestV2("https://logo-url/png", + Arrays.asList("https://logo-url/png"),Arrays.asList("given_name"), + Arrays.asList("mosip:idp:acr:static-code"), "ACTIVE", Arrays.asList("authorization_code"), + "client-name", Arrays.asList("private_key_jwt"),new HashMap(){{put("abc", "clientname");}}), "cid#1", "invalid_language_code" }, { "update client-details", new ClientDetailCreateRequestV2("client-id-up1", "client-name", TestUtil.generateJWK_RSA().toPublicJWK().toJSONObject(), "rp-id", Arrays.asList("given_name"), diff --git a/esignet-service/src/test/java/io/mosip/esignet/controllers/KeyBindingControllerTest.java b/esignet-service/src/test/java/io/mosip/esignet/controllers/KeyBindingControllerTest.java index 4dbcea334..768ac54bd 100644 --- a/esignet-service/src/test/java/io/mosip/esignet/controllers/KeyBindingControllerTest.java +++ b/esignet-service/src/test/java/io/mosip/esignet/controllers/KeyBindingControllerTest.java @@ -263,12 +263,13 @@ public void bindWallet_withAuthChallengeEmptyFactorAndEmptyChallenge_thenFail() .andExpect(status().isOk()) .andExpect(jsonPath("$.errors").isNotEmpty()).andReturn(); - List errorCodes = Arrays.asList(INVALID_AUTH_FACTOR_TYPE, INVALID_CHALLENGE, INVALID_CHALLENGE_FORMAT); + List errorCodes = Arrays.asList(INVALID_CHALLENGE_FORMAT,INVALID_AUTH_FACTOR_TYPE, INVALID_CHALLENGE_FORMAT_FOR_AUTH_FACTOR_TYPE,INVALID_CHALLENGE); ResponseWrapper responseWrapper = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), ResponseWrapper.class); - Assert.assertTrue(responseWrapper.getErrors().size() == 3); + Assert.assertTrue(responseWrapper.getErrors().size() == 4); Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(0)).getErrorCode())); Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(1)).getErrorCode())); Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(2)).getErrorCode())); + Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(3)).getErrorCode())); } /*@Test diff --git a/esignet-service/src/test/java/io/mosip/esignet/controllers/LinkedAuthorizationControllerTest.java b/esignet-service/src/test/java/io/mosip/esignet/controllers/LinkedAuthorizationControllerTest.java index fad6dad2d..2517b4a11 100644 --- a/esignet-service/src/test/java/io/mosip/esignet/controllers/LinkedAuthorizationControllerTest.java +++ b/esignet-service/src/test/java/io/mosip/esignet/controllers/LinkedAuthorizationControllerTest.java @@ -1,16 +1,6 @@ package io.mosip.esignet.controllers; -import static io.mosip.esignet.core.constants.ErrorConstants.INVALID_AUTH_FACTOR_TYPE; -import static io.mosip.esignet.core.constants.ErrorConstants.INVALID_CHALLENGE; -import static io.mosip.esignet.core.constants.ErrorConstants.INVALID_CHALLENGE_FORMAT; -import static io.mosip.esignet.core.constants.ErrorConstants.INVALID_IDENTIFIER; -import static io.mosip.esignet.core.constants.ErrorConstants.INVALID_LINK_CODE; -import static io.mosip.esignet.core.constants.ErrorConstants.INVALID_OTP_CHANNEL; -import static io.mosip.esignet.core.constants.ErrorConstants.INVALID_TRANSACTION_ID; -import static io.mosip.esignet.core.constants.ErrorConstants.RESPONSE_TIMEOUT; -import static io.mosip.esignet.core.constants.ErrorConstants.INVALID_ACCEPTED_CLAIM; -import static io.mosip.esignet.core.constants.ErrorConstants.INVALID_PERMITTED_SCOPE; -import static io.mosip.esignet.core.constants.ErrorConstants.INVALID_SIGNATURE_FORMAT; +import static io.mosip.esignet.core.constants.ErrorConstants.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -295,7 +285,7 @@ public void authenticate_withValidRequest_thenPass() throws Exception { LinkedKycAuthRequest linkedKycAuthRequest = new LinkedKycAuthRequest(); linkedKycAuthRequest.setLinkedTransactionId("link-transaction-id"); AuthChallenge authChallenge = new AuthChallenge(); - authChallenge.setFormat("format"); + authChallenge.setFormat("alpha-numeric"); authChallenge.setAuthFactorType("OTP"); authChallenge.setChallenge("challenge"); linkedKycAuthRequest.setChallengeList(Arrays.asList(authChallenge)); @@ -319,7 +309,7 @@ public void authenticate_withException_thenFail() throws Exception { LinkedKycAuthRequest linkedKycAuthRequest = new LinkedKycAuthRequest(); linkedKycAuthRequest.setLinkedTransactionId("link-transaction-id"); AuthChallenge authChallenge = new AuthChallenge(); - authChallenge.setFormat("format"); + authChallenge.setFormat("alpha-numeric"); authChallenge.setAuthFactorType("OTP"); authChallenge.setChallenge("challenge"); linkedKycAuthRequest.setChallengeList(Arrays.asList(authChallenge)); @@ -342,7 +332,7 @@ public void authenticate_withInvalidTransactionId_thenFail() throws Exception { LinkedKycAuthRequest linkedKycAuthRequest = new LinkedKycAuthRequest(); linkedKycAuthRequest.setLinkedTransactionId(" "); AuthChallenge authChallenge = new AuthChallenge(); - authChallenge.setFormat("format"); + authChallenge.setFormat("alpha-numeric"); authChallenge.setAuthFactorType("OTP"); authChallenge.setChallenge("challenge"); linkedKycAuthRequest.setChallengeList(Arrays.asList(authChallenge)); @@ -364,7 +354,7 @@ public void authenticate_withInvalidIndividualId_thenFail() throws Exception { LinkedKycAuthRequest linkedKycAuthRequest = new LinkedKycAuthRequest(); linkedKycAuthRequest.setLinkedTransactionId("txn-id"); AuthChallenge authChallenge = new AuthChallenge(); - authChallenge.setFormat("format"); + authChallenge.setFormat("alpha-numeric"); authChallenge.setAuthFactorType("OTP"); authChallenge.setChallenge("challenge"); linkedKycAuthRequest.setChallengeList(Arrays.asList(authChallenge)); @@ -410,12 +400,13 @@ public void authenticate_withInvalidChallengeList_thenFail() throws Exception { .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andReturn(); - List errorCodes = Arrays.asList(INVALID_AUTH_FACTOR_TYPE, INVALID_CHALLENGE, INVALID_CHALLENGE_FORMAT); + List errorCodes = Arrays.asList(INVALID_CHALLENGE_FORMAT,INVALID_AUTH_FACTOR_TYPE, INVALID_CHALLENGE_FORMAT_FOR_AUTH_FACTOR_TYPE,INVALID_CHALLENGE); ResponseWrapper responseWrapper = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), ResponseWrapper.class); - Assert.assertTrue(responseWrapper.getErrors().size() == 3); + Assert.assertTrue(responseWrapper.getErrors().size() == 4); Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(0)).getErrorCode())); Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(1)).getErrorCode())); Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(2)).getErrorCode())); + Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(3)).getErrorCode())); } @Test @@ -662,7 +653,7 @@ public void authenticateV2_withValidRequest_thenPass() throws Exception { LinkedKycAuthRequest linkedKycAuthRequest = new LinkedKycAuthRequest(); linkedKycAuthRequest.setLinkedTransactionId("link-transaction-id"); AuthChallenge authChallenge = new AuthChallenge(); - authChallenge.setFormat("format"); + authChallenge.setFormat("alpha-numeric"); authChallenge.setAuthFactorType("OTP"); authChallenge.setChallenge("challenge"); linkedKycAuthRequest.setChallengeList(Arrays.asList(authChallenge)); @@ -686,7 +677,7 @@ public void authenticateV2_withException_thenFail() throws Exception { LinkedKycAuthRequest linkedKycAuthRequest = new LinkedKycAuthRequest(); linkedKycAuthRequest.setLinkedTransactionId("link-transaction-id"); AuthChallenge authChallenge = new AuthChallenge(); - authChallenge.setFormat("format"); + authChallenge.setFormat("alpha-numeric"); authChallenge.setAuthFactorType("OTP"); authChallenge.setChallenge("challenge"); linkedKycAuthRequest.setChallengeList(Arrays.asList(authChallenge)); @@ -709,7 +700,7 @@ public void authenticateV2_withInvalidTransactionId_thenFail() throws Exception LinkedKycAuthRequest linkedKycAuthRequest = new LinkedKycAuthRequest(); linkedKycAuthRequest.setLinkedTransactionId(" "); AuthChallenge authChallenge = new AuthChallenge(); - authChallenge.setFormat("format"); + authChallenge.setFormat("alpha-numeric"); authChallenge.setAuthFactorType("OTP"); authChallenge.setChallenge("challenge"); linkedKycAuthRequest.setChallengeList(Arrays.asList(authChallenge)); @@ -731,7 +722,7 @@ public void authenticateV2_withInvalidIndividualId_thenFail() throws Exception { LinkedKycAuthRequest linkedKycAuthRequest = new LinkedKycAuthRequest(); linkedKycAuthRequest.setLinkedTransactionId("txn-id"); AuthChallenge authChallenge = new AuthChallenge(); - authChallenge.setFormat("format"); + authChallenge.setFormat("alpha-numeric"); authChallenge.setAuthFactorType("OTP"); authChallenge.setChallenge("challenge"); linkedKycAuthRequest.setChallengeList(Arrays.asList(authChallenge)); @@ -777,12 +768,13 @@ public void authenticateV2_withInvalidChallengeList_thenFail() throws Exception .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andReturn(); - List errorCodes = Arrays.asList(INVALID_AUTH_FACTOR_TYPE, INVALID_CHALLENGE, INVALID_CHALLENGE_FORMAT); + List errorCodes = Arrays.asList(INVALID_CHALLENGE_FORMAT,INVALID_AUTH_FACTOR_TYPE, INVALID_CHALLENGE_FORMAT_FOR_AUTH_FACTOR_TYPE,INVALID_CHALLENGE); ResponseWrapper responseWrapper = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), ResponseWrapper.class); - Assert.assertTrue(responseWrapper.getErrors().size() == 3); + Assert.assertTrue(responseWrapper.getErrors().size() == 4); Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(0)).getErrorCode())); Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(1)).getErrorCode())); Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(2)).getErrorCode())); + Assert.assertTrue(errorCodes.contains(((Error)responseWrapper.getErrors().get(3)).getErrorCode())); } @Test diff --git a/esignet-service/src/test/resources/application-test.properties b/esignet-service/src/test/resources/application-test.properties index d4c1843c6..7e53ef823 100644 --- a/esignet-service/src/test/resources/application-test.properties +++ b/esignet-service/src/test/resources/application-test.properties @@ -10,6 +10,7 @@ mosip.esignet.supported-id-regex=\\S* mosip.esignet.id-token-expire-seconds=3600 mosip.esignet.access-token.expire.seconds=3600 mosip.esignet.link-code-expire-in-secs=60 +mosip.esignet.supported-formats={'OTP': 'alpha-numeric', 'PWD': 'alpha-numeric', 'BIO': 'encoded-json', 'WLA': 'jwt', 'PIN': 'number', 'KBA': 'base64url-encoded-json'} mosip.esignet.header-filter.paths-to-validate={'${server.servlet.path}/authorization/send-otp', \ '${server.servlet.path}/authorization/authenticate', \