Skip to content

Commit

Permalink
[MOSIP-25539] made corrections in api body. Task 5 (#673)
Browse files Browse the repository at this point in the history
* [MOSIP-24670] Updated API correction id and version

* [MOSIP-24670] Updated API body correction

* [MOSIP-22640] Fixed Sonar Bugs

* updated PR

* updated PR

* updated review code

* [MOSIP-22640] Fixed sonar bugs

* updated PR

* updated PR

* [MOSIP-22639] Resolved security hotspots in code

* [MOSIP-24630] Fixed Security Vulnerability in code

* added error for isValidUrl method

* renamed vaildateURL method

* updated PR

* updated PR

* [MOSIP-24670] Made corrections in  id and version

* resolved conflicts

* updated PR

* updated PR

* [MOSIP-24670] Made corrections n API body, response code

* updated PR

* updated PR

* updated dateTime

* updated PR

* [MOSIP-25539] Made corrections in API body, response code

* [MOSIP-25539] made corrections in API body

* updated error message

* updated error code

* updated trasactionid dto change

* added equals

* [MOSIP-25539] made corrections in api body
  • Loading branch information
aihamh authored Jan 13, 2023
1 parent c74a1b2 commit f3fe329
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import reactor.util.function.Tuple2;
import java.util.Map;

@RestController
@Tag(name = "resident-controller", description = "Resident Controller")
Expand Down Expand Up @@ -492,9 +493,15 @@ private String getIdType(String id) {
public ResponseWrapper<AidStatusResponseDTO> checkAidStatus(@RequestBody RequestWrapper<AidStatusRequestDTO> reqDto)
throws ResidentServiceCheckedException, ApisResourceAccessException, OtpValidationFailedException {
logger.debug("ResidentController::getAidStatus()::entry");
AidStatusResponseDTO resp = new AidStatusResponseDTO();
try {
validator.validateAidStatusRequestDto(reqDto);
audit.setAuditRequestDto(EventEnum.AID_STATUS);
AidStatusResponseDTO resp = residentService.getAidStatus(reqDto.getRequest());
resp = residentService.getAidStatus(reqDto.getRequest());
} catch (ResidentServiceCheckedException | ApisResourceAccessException | OtpValidationFailedException e ) {
throw new ResidentServiceException( e.getErrorCode(), e.getErrorText(), e,
Map.of(ResidentConstants.REQ_RES_ID, checkStatusId));
}
audit.setAuditRequestDto(EventEnum.AID_STATUS_SUCCESS);
logger.debug("ResidentController::getAidStatus()::exit");
ResponseWrapper<AidStatusResponseDTO> responseWrapper = new ResponseWrapper<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import io.mosip.resident.constant.ResidentConstants;
import io.mosip.resident.constant.ResidentErrorCode;
import io.mosip.resident.dto.IndividualIdOtpRequestDTO;
import io.mosip.resident.dto.OtpRequestDTO;
import io.mosip.resident.dto.OtpResponseDTO;
import io.mosip.resident.exception.ApisResourceAccessException;
import io.mosip.resident.exception.ResidentServiceCheckedException;
import io.mosip.resident.exception.ResidentServiceException;
import io.mosip.resident.service.ResidentOtpService;
import io.mosip.resident.util.AuditUtil;
import io.mosip.resident.util.EventEnum;
Expand All @@ -23,6 +25,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.Map;

@RestController
@Tag(name = "resident-otp-controller", description = "Resident Otp Controller")
Expand Down Expand Up @@ -65,10 +68,20 @@ public OtpResponseDTO reqOtp(@RequestBody OtpRequestDTO otpRequestDto) throws Re
@ApiResponse(responseCode = "404", description = "Not Found" ,content = @Content(schema = @Schema(hidden = true)))})
public OtpResponseDTO reqOtpForIndividualId(@RequestBody IndividualIdOtpRequestDTO otpRequestDto) throws ResidentServiceCheckedException, NoSuchAlgorithmException, ApisResourceAccessException {
audit.setAuditRequestDto(EventEnum.OTP_INDIVIDUALID_GEN);
OtpResponseDTO otpResponseDTO = new OtpResponseDTO();
try {
if(otpRequestDto.getIndividualId() == null) {
throw new ResidentServiceCheckedException(ResidentErrorCode.INVALID_INPUT.getErrorCode(), ResidentErrorCode.INVALID_INPUT.getErrorMessage() + "individualId");
}
OtpResponseDTO otpResponseDTO = residentOtpService.generateOtpForIndividualId(otpRequestDto);
otpResponseDTO = residentOtpService.generateOtpForIndividualId(otpRequestDto);
} catch (ResidentServiceCheckedException | ApisResourceAccessException e ) {
throw new ResidentServiceException( e.getErrorCode(), e.getErrorText(), e,
Map.of(ResidentConstants.REQ_RES_ID,otpRequestId));
}
catch(ResidentServiceException e) {
e.setMetadata(Map.of(ResidentConstants.REQ_RES_ID,otpRequestId));
throw e ;
}
audit.setAuditRequestDto(EventEnum.OTP_INDIVIDUALID_GEN_SUCCESS);
otpResponseDTO.setId(otpRequestId);
otpResponseDTO.setVersion(otpRequestVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@Data
public class AidStatusRequestDTO {

private String aid;
private String individualId;
private String otp;
private String transactionId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ private ResponseEntity<ResponseWrapper<ServiceError>> createResponseEntity(
if (((ObjectWithMetadata) e).getMetadata().containsKey(ResidentConstants.EVENT_ID)) {
headers.add(ResidentConstants.EVENT_ID,
(String) ((ObjectWithMetadata) e).getMetadata().get(ResidentConstants.EVENT_ID));
} else if (((ObjectWithMetadata) e).getMetadata().containsKey(ResidentConstants.HTTP_STATUS_CODE)) {
}
if (((ObjectWithMetadata) e).getMetadata().containsKey(ResidentConstants.HTTP_STATUS_CODE)) {
httpStatus = (HttpStatus) ((ObjectWithMetadata) e).getMetadata().get(ResidentConstants.HTTP_STATUS_CODE);
} else if (((ObjectWithMetadata) e).getMetadata().containsKey(ResidentConstants.REQ_RES_ID)) {
}
if (((ObjectWithMetadata) e).getMetadata().containsKey(ResidentConstants.REQ_RES_ID)) {
errorResponse.setId((String) ((ObjectWithMetadata) e).getMetadata().get(ResidentConstants.REQ_RES_ID));
}
errorResponse.setVersion(env.getProperty(ResidentConstants.REQ_RES_VERSION));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ public AidStatusResponseDTO getAidStatus(AidStatusRequestDTO reqDto)
public AidStatusResponseDTO getAidStatus(AidStatusRequestDTO reqDto, boolean performOtpValidation)
throws ResidentServiceCheckedException, ApisResourceAccessException, OtpValidationFailedException {
try {
String individualId = identityServiceImpl.getIndividualIdForAid(reqDto.getAid());
String individualId = identityServiceImpl.getIndividualIdForAid(reqDto.getIndividualId());
boolean validStatus = individualId != null;
if (performOtpValidation) {
validStatus = idAuthServiceImpl.validateOtp(reqDto.getTransactionId(), individualId, reqDto.getOtp());
Expand All @@ -1958,7 +1958,7 @@ public AidStatusResponseDTO getAidStatus(AidStatusRequestDTO reqDto, boolean per
"ResidentServiceImpl::getAidStatus()::" + e.getClass().getSimpleName() + " :" + e.getMessage());
RegStatusCheckResponseDTO ridStatus = null;
try {
ridStatus = getRidStatus(reqDto.getAid());
ridStatus = getRidStatus(reqDto.getIndividualId());
} catch (RIDInvalidException ex) {
throw new ResidentServiceCheckedException(ResidentErrorCode.AID_NOT_FOUND);
}
Expand All @@ -1979,7 +1979,7 @@ public String checkAidStatus(String aid) throws ResidentServiceCheckedException
throw new ResidentServiceCheckedException(ResidentErrorCode.AID_NOT_FOUND);
}
AidStatusRequestDTO aidStatusRequestDTO = new AidStatusRequestDTO();
aidStatusRequestDTO.setAid(aid);
aidStatusRequestDTO.setIndividualId(aid);
AidStatusResponseDTO aidStatusResponseDTO = getAidStatus(aidStatusRequestDTO, false);
return aidStatusResponseDTO.getAidStatus();
} catch (ApisResourceAccessException | OtpValidationFailedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ private boolean validateIndividualIdvIdWithoutIdType(String individualId) {
public void validateAidStatusRequestDto(RequestWrapper<AidStatusRequestDTO> reqDto) throws ResidentServiceCheckedException {
validateAidStatusRequest(reqDto, RequestIdType.CHECK_STATUS);

if(reqDto.getRequest().getAid() == null) {
if(reqDto.getRequest().getIndividualId() == null) {
throw new InvalidInputException("individualId");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public void testDownloadCardIndividualId() throws Exception {
@WithUserDetails("reg-admin")
public void testCheckAidStatus() throws Exception {
AidStatusRequestDTO aidStatusRequestDTO = new AidStatusRequestDTO();
aidStatusRequestDTO.setAid("8251649601");
aidStatusRequestDTO.setIndividualId("8251649601");
aidStatusRequestDTO.setOtp("111111");
aidStatusRequestDTO.setTransactionId("1234567890");
RequestWrapper<AidStatusRequestDTO> requestWrapper = new RequestWrapper<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.security.test.context.support.WithUserDetails;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
Expand All @@ -32,7 +33,7 @@
import io.mosip.resident.dto.IndividualIdOtpRequestDTO;
import io.mosip.resident.dto.OtpRequestDTO;
import io.mosip.resident.dto.OtpResponseDTO;
import io.mosip.resident.exception.ResidentServiceCheckedException;
import io.mosip.resident.exception.ResidentServiceException;
import io.mosip.resident.handler.service.ResidentUpdateService;
import io.mosip.resident.handler.service.UinCardRePrintService;
import io.mosip.resident.helper.ObjectStoreHelper;
Expand Down Expand Up @@ -120,6 +121,7 @@ public void setup() throws Exception {
otpRequestDTO.setIndividualId("123456");
otpRequestDTO.setTransactionID("1234327890");
reqJson = gson.toJson(otpRequestDTO);
ReflectionTestUtils.setField(residentOtpController, "otpRequestId", "mosip.identity.otp.internal");
}

@Test
Expand Down Expand Up @@ -152,8 +154,8 @@ public void reqOtpForAidTest() throws Exception {
MockMvcRequestBuilders.post("/req/individualId/otp").contentType(MediaType.APPLICATION_JSON).content(json))
.andExpect(status().isOk());// .andExpect(jsonPath("$.response.vid", is("12345")))
}

@Test(expected = ResidentServiceCheckedException.class)
@Test(expected = ResidentServiceException.class)
@WithUserDetails("resident")
public void reqOtpForAidNullTest() throws Exception {
IndividualIdOtpRequestDTO aidOtpRequestDTO = new IndividualIdOtpRequestDTO();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void testServiceHistoryWithDifferentParameters() throws ResidentServiceCh
@Test
public void testGetAidStatus() throws OtpValidationFailedException, ResidentServiceCheckedException, ApisResourceAccessException {
AidStatusRequestDTO aidStatusRequestDTO = new AidStatusRequestDTO();
aidStatusRequestDTO.setAid("10087100401001420220929210144");
aidStatusRequestDTO.setIndividualId("10087100401001420220929210144");
aidStatusRequestDTO.setOtp("111111");
aidStatusRequestDTO.setTransactionId("1234567890");
Mockito.when(idAuthServiceImpl.validateOtp(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(true);
Expand All @@ -243,7 +243,7 @@ public void testGetAidStatus() throws OtpValidationFailedException, ResidentServ
@Test
public void testGetAidStatusOtpValidationFalse() throws OtpValidationFailedException, ResidentServiceCheckedException, ApisResourceAccessException {
AidStatusRequestDTO aidStatusRequestDTO = new AidStatusRequestDTO();
aidStatusRequestDTO.setAid("10087100401001420220929210144");
aidStatusRequestDTO.setIndividualId("10087100401001420220929210144");
aidStatusRequestDTO.setOtp("111111");
aidStatusRequestDTO.setTransactionId("1234567890");
Mockito.when(idAuthServiceImpl.validateOtp(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ public void testValidateAidStatusRequestDto() throws Exception{
@Test(expected = InvalidInputException.class)
public void testValidateAidStatusRequestDtoAidNull() throws Exception{
AidStatusRequestDTO aidStatusRequestDTO = new AidStatusRequestDTO();
aidStatusRequestDTO.setAid(null);
aidStatusRequestDTO.setIndividualId(null);
RequestWrapper<AidStatusRequestDTO> requestWrapper = new RequestWrapper<>();
requestWrapper.setRequesttime(DateUtils.getUTCCurrentDateTimeString(pattern));
requestWrapper.setId("mosip.resident.checkstatus");
Expand All @@ -1416,7 +1416,7 @@ public void testValidateAidStatusRequestDtoAidNull() throws Exception{
@Test
public void testValidateAidStatusRequestDtoSuccess() throws Exception{
AidStatusRequestDTO aidStatusRequestDTO = new AidStatusRequestDTO();
aidStatusRequestDTO.setAid("17");
aidStatusRequestDTO.setIndividualId("17");
RequestWrapper<AidStatusRequestDTO> requestWrapper = new RequestWrapper<>();
requestWrapper.setRequesttime(DateUtils.getUTCCurrentDateTimeString(pattern));
requestWrapper.setId("mosip.resident.checkstatus");
Expand Down

0 comments on commit f3fe329

Please sign in to comment.