Skip to content

Commit

Permalink
Merge pull request mosip#632 from GOKULRAJ136/patch-api
Browse files Browse the repository at this point in the history
MOSIP-30853 : Partner API testrig fix for "RequestAPIKeyCredentialPartner" scenario
  • Loading branch information
ckm007 authored Mar 13, 2024
2 parents d1b5440 + 5d514e5 commit 4106cdf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public enum ErrorCode {
API_NULL_RESPONSE_EXCEPTION("PMS_PRT_107","Responese from the api is null"),
UNABLE_TO_PROCESS("PMS_PRT_500","Unable to process the request."),
PARTNER_NOT_ACTIVE_EXCEPTION("PMS_PMP_016","Partner is not active."),
POLICY_GROUP_POLICY_NOT_EXISTS("PMS_PRT_098","Given policy under partner's policy group not exists."),
POLICY_GROUP_POLICY_NOT_EXISTS("PMS_PRT_098","Given policy doesn't exists under partner's policy group."),
POLICY_NOT_ACTIVE_EXCEPTION("PMS_PMP_019","Policy is not active."),
POLICY_GROUP_NOT_ACTIVE("PMS_PMP_023","Policy group is not active."),
POLICY_EXPIRED_EXCEPTION("PMS_PMP_018","Policy expired."),
Expand All @@ -61,7 +61,7 @@ public enum ErrorCode {
POLICY_GROUP_NOT_MAP_ACTIVE_PARTNER("PMS_PRT_050","Policy group cannot be updated for approved partner"),
POLICY_GROUP_NOT_MAPPED_PARTNER("PMS_PRT_054","Policy group not mapped for given partner"),
LOGGEDIN_USER_NOT_AUTHORIZED("PMS_PRT_055","User not authorized."),
PARTNER_POLICY_MAPPING_EXISTS("PMS_PRT_053","Mapping exists for given policy and partner and is in %s state."),
PARTNER_POLICY_MAPPING_EXISTS("PMS_PRT_053","Mapping exists for given policy and partner, and is in %s state."),
PARTNER_LANG_CODE_NOT_SUPPORTED("PMS_PRT_056","Given langCode is not supported"),
PARTNER_ID_CONTAINS_SPACES("PMS_PRT_066","PartnerId should not have any spaces"),
JSON_NOT_VALID("PMS_PRT_096","Json is not valid"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,18 @@ public PartnerResponse updatePartnerDetails(PartnerUpdateDto partnerUpdateReques
}

private AuthPolicy validatePolicyGroupAndPolicy(String policyGroupId, String policyName) {
List <AuthPolicy> authPoliciesFromDb = authPolicyRepository.findByPolicyNameAndIsDeletedFalseorIsDeletedIsNullAndIsActiveTrue(policyName);
if (authPoliciesFromDb.isEmpty() || authPoliciesFromDb == null){
auditUtil.setAuditRequestDto(PartnerServiceAuditEnum.SUBMIT_API_REQUEST_FAILURE, policyName, "policyName");
throw new PartnerServiceException(ErrorCode.POLICY_NOT_EXIST.getErrorCode(),
ErrorCode.POLICY_NOT_EXIST.getErrorMessage());
}
AuthPolicy authPolicyFromDb = authPolicyRepository.findByPolicyGroupIdAndName(policyGroupId, policyName);
for (AuthPolicy authPolicy: authPoliciesFromDb){
if (authPolicy.getPolicyGroup() != null && authPolicy.getPolicyGroup().getId().equals(policyGroupId)){
authPolicyFromDb = authPolicy;
}
}
if (authPolicyFromDb == null) {
auditUtil.setAuditRequestDto(PartnerServiceAuditEnum.SUBMIT_API_REQUEST_FAILURE, policyName, "policyName");
throw new PartnerServiceException(ErrorCode.POLICY_GROUP_POLICY_NOT_EXISTS.getErrorCode(),
Expand Down Expand Up @@ -1502,13 +1513,13 @@ private List<PartnerType> getAllPartnerTypes(){
public PartnerPolicyMappingResponseDto requestForPolicyMapping(PartnerPolicyMappingRequest partnerAPIKeyRequest, String partnerId) {
validateLoggedInUserAuthorization(partnerId);
Partner partner = getValidPartner(partnerId, false);
AuthPolicy authPolicy = validatePolicyGroupAndPolicy(partner.getPolicyGroupId(),
partnerAPIKeyRequest.getPolicyName());
if(partner.getPolicyGroupId() == null) {
auditUtil.setAuditRequestDto(PartnerServiceAuditEnum.SUBMIT_API_REQUEST_FAILURE, partnerId, "partnerId");
throw new PartnerServiceException(ErrorCode.PARTNER_NOT_MAPPED_TO_POLICY_GROUP.getErrorCode(),
ErrorCode.PARTNER_NOT_MAPPED_TO_POLICY_GROUP.getErrorMessage());
}
AuthPolicy authPolicy = validatePolicyGroupAndPolicy(partner.getPolicyGroupId(),
partnerAPIKeyRequest.getPolicyName());

List<PartnerPolicyRequest> mappingRequests = partnerPolicyRequestRepository
.findByPartnerIdAndPolicyId(partnerId, authPolicy.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ public void retrieveAllApiKeyRequestsSubmittedByPartnerTest_S3() {
pserviceImpl.retrieveAllApiKeyRequestsSubmittedByPartner(partnerId);
}

@Test
@Test(expected = PartnerServiceException.class)
public void mapPartnerPolicyCredentialType_001() {
Optional<Partner> partner = Optional.of(createPartner(true));
Mockito.when(partnerRepository.findById("12345")).thenReturn(partner);
Expand Down Expand Up @@ -876,7 +876,7 @@ public void getPartnerCredentialTypePolicy_003() throws JsonParseException, Json
pserviceImpl.getPartnerCredentialTypePolicy("euin", "12345");
}

@Test
@Test (expected = PartnerServiceException.class)
public void requestForPolicyMappingTest() {
PartnerPolicyMappingRequest request = new PartnerPolicyMappingRequest();
request.setPolicyName("policyName");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public interface AuthPolicyRepository extends JpaRepository<AuthPolicy, String>{

@Query(value = "select * from auth_policy ap where ap.name=? and (ap.is_deleted is null or ap.is_deleted = false) and ap.is_active = true",nativeQuery = true)
AuthPolicy findByPolicyName(String policyName);


@Query(value = "select * from auth_policy ap where ap.name=? and (ap.is_deleted is null or ap.is_deleted = false) and ap.is_active = true",nativeQuery = true)
List <AuthPolicy> findByPolicyNameAndIsDeletedFalseorIsDeletedIsNullAndIsActiveTrue(String policyName);

@Query(value="select * from auth_policy ap where lower(ap.name) like lower(concat('%', concat(?1, '%')))", nativeQuery = true)
List<AuthPolicy> findByNameIgnoreCase(String name);
}

0 comments on commit 4106cdf

Please sign in to comment.