Skip to content

Commit

Permalink
MOSIP-36810 Error message is not appropriate for mapping same device …
Browse files Browse the repository at this point in the history
…and same SBI details (#948)

* MOSIP-36810: Error message is not appropriate for mapping same device and same SBI details

Signed-off-by: sudeep <[email protected]>

* MOSIP-36810: Error message is not appropriate for mapping same device and same SBI details

Signed-off-by: sudeep <[email protected]>

* MOSIP-36810: Error message is not appropriate for mapping same device and same SBI details

Signed-off-by: sudeep <[email protected]>

---------

Signed-off-by: sudeep <[email protected]>
  • Loading branch information
Sudeep7353 authored Oct 23, 2024
1 parent e6eaa38 commit 3485696
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,16 +437,16 @@ public ResponseWrapperV2<Boolean> 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.");
throw new PartnerServiceException(ErrorCode.SBI_DEVICE_MAPPING_ALREADY_EXIST.getErrorCode(),
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -133,6 +137,8 @@ public class PartnerServiceImplTest {
UserDetailUtil userDetailUtil;
@MockBean
AuditUtil auditUtil;
@MockBean
PartnerHelper partnerHelper;

@Mock
FilterHelper filterHelper;
Expand Down Expand Up @@ -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<GrantedAuthority> 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<Partner> partnerList = new ArrayList<>();
Expand Down

0 comments on commit 3485696

Please sign in to comment.