From 3485696c71989cd05977dfdd2ac03464e81edf0b Mon Sep 17 00:00:00 2001 From: Sudeep7353 <103890430+Sudeep7353@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:47:19 +0530 Subject: [PATCH] MOSIP-36810 Error message is not appropriate for mapping same device and same SBI details (#948) * MOSIP-36810: Error message is not appropriate for mapping same device and same SBI details Signed-off-by: sudeep * MOSIP-36810: Error message is not appropriate for mapping same device and same SBI details Signed-off-by: sudeep * MOSIP-36810: Error message is not appropriate for mapping same device and same SBI details Signed-off-by: sudeep --------- Signed-off-by: sudeep --- .../service/impl/DeviceDetailServiceImpl.java | 6 +++--- .../service/impl/PartnerServiceImplTest.java | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/DeviceDetailServiceImpl.java b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/DeviceDetailServiceImpl.java index 796b68ab63..5ad3404cb0 100644 --- a/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/DeviceDetailServiceImpl.java +++ b/partner/partner-management-service/src/main/java/io/mosip/pms/device/authdevice/service/impl/DeviceDetailServiceImpl.java @@ -437,9 +437,6 @@ public ResponseWrapperV2 inactiveMappingDeviceToSbi(SbiAndDeviceMapping ErrorCode.PARTNER_ID_NOT_ASSOCIATED_WITH_USER.getErrorMessage()); } - // validate sbi and device mapping - partnerHelper.validateSbiDeviceMapping(partnerId, sbiId, deviceDetailId); - DeviceDetailSBI deviceDetailSBI = deviceDetailSbiRepository.findByDeviceProviderIdAndSbiIdAndDeviceDetailId(partnerId, sbiId, deviceDetailId); if (Objects.nonNull(deviceDetailSBI)){ LOGGER.info("sessionId", "idType", "id", "SBI and Device mapping already exists in DB."); @@ -447,6 +444,9 @@ public ResponseWrapperV2 inactiveMappingDeviceToSbi(SbiAndDeviceMapping ErrorCode.SBI_DEVICE_MAPPING_ALREADY_EXIST.getErrorMessage()); } + // validate sbi and device mapping + partnerHelper.validateSbiDeviceMapping(partnerId, sbiId, deviceDetailId); + DeviceDetailSBI entity = new DeviceDetailSBI(); DeviceDetailSBIPK pk = new DeviceDetailSBIPK(); diff --git a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerServiceImplTest.java b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerServiceImplTest.java index 74611cfa8e..853973cd97 100644 --- a/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerServiceImplTest.java +++ b/partner/partner-management-service/src/test/java/io/mosip/pms/test/partner/service/impl/PartnerServiceImplTest.java @@ -4,6 +4,7 @@ import static org.mockito.Mockito.*; import java.io.IOException; +import java.lang.reflect.Method; import java.security.cert.Certificate; import java.sql.Timestamp; import java.time.LocalDateTime; @@ -19,6 +20,7 @@ import io.mosip.pms.partner.dto.UploadCertificateRequestDto; import io.mosip.pms.partner.request.dto.*; import io.mosip.pms.partner.response.dto.*; +import io.mosip.pms.partner.util.PartnerHelper; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -34,6 +36,8 @@ import org.springframework.data.domain.PageImpl; import org.springframework.http.MediaType; import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.test.context.support.WithMockUser; @@ -133,6 +137,8 @@ public class PartnerServiceImplTest { UserDetailUtil userDetailUtil; @MockBean AuditUtil auditUtil; + @MockBean + PartnerHelper partnerHelper; @Mock FilterHelper filterHelper; @@ -222,8 +228,15 @@ private io.mosip.kernel.openid.bridge.model.MosipUserDto getMosipUserDto() { public void getPartnerCertificate_Test() throws Exception{ io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = getMosipUserDto(); AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123"); + Collection newAuthorities = List.of( + new SimpleGrantedAuthority("ROLE_USER") + ); + Method addAuthoritiesMethod = AuthUserDetails.class.getDeclaredMethod("addAuthorities", Collection.class, String.class); + addAuthoritiesMethod.setAccessible(true); + addAuthoritiesMethod.invoke(authUserDetails, newAuthorities, null); SecurityContextHolder.setContext(securityContext); when(authentication.getPrincipal()).thenReturn(authUserDetails); + when(partnerHelper.isPartnerAdmin(authentication.getAuthorities().toString())).thenReturn(true); when(securityContext.getAuthentication()).thenReturn(authentication); List partnerList = new ArrayList<>();