Skip to content

Commit

Permalink
[MOSIP-37899, MOSIP-38400, MOSIP-38393]: Bug fixes and Junit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Swetha K <[email protected]>
  • Loading branch information
Swetha K committed Dec 24, 2024
1 parent 7e5b18d commit 8a57fa9
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,6 @@ public void getCaCertificatesTest() throws Exception {
int pageNo = 0;
int pageSize = 8;
CaCertificateFilterDto filterDto = new CaCertificateFilterDto();
filterDto.setCaCertificateType("root");
filterDto.setCertificateId("123");
filterDto.setPartnerDomain("FTM");
filterDto.setIssuedTo("CA");
filterDto.setIssuedBy("CA");
ResponseWrapperV2<PageResponseV2Dto<CaCertificateSummaryDto>> responseWrapper = new ResponseWrapperV2<>();

Mockito.when(partnerManagementService.getCaCertificates(sortFieldName, sortType, pageNo, pageSize, filterDto))
Expand All @@ -467,4 +462,14 @@ public void getCaCertificatesTest() throws Exception {
.param("issuedBy", "CA"))
.andExpect(MockMvcResultMatchers.status().isOk());
}

@Test
@WithMockUser(roles = {"PARTNER_ADMIN"})
public void downloadRootCertificateTest() throws Exception {
ResponseWrapperV2<CACertificateResponseDto> responseWrapper = new ResponseWrapperV2<>();
Mockito.when(partnerManagementService.downloadRootCertificate(anyString())).thenReturn(responseWrapper);
mockMvc.perform(MockMvcRequestBuilders.get("/partners/download-root-certificate/{certificateId}", "123")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().isOk());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.security.core.Authentication;
Expand Down Expand Up @@ -128,6 +129,9 @@ public class PartnerManagementServiceImplTest {

@Mock
PartnerPolicyMappingRequestRepository partnerPolicyMappingRequestRepository;

@Mock
Environment environment;

@Before
public void setUp() {
Expand Down Expand Up @@ -1414,6 +1418,138 @@ public void getCaCertificatesExceptionTest() throws Exception {
partnerManagementImpl.getCaCertificates(sortFieldName, sortType, pageNo, pageSize, null);
}

@Test
public void downloadRootCertificateTest() throws Exception {
MosipUserDto mosipUserDto = getMosipUserDto();
AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123");
SecurityContextHolder.setContext(securityContext);
when(authentication.getPrincipal()).thenReturn(authUserDetails);
when(securityContext.getAuthentication()).thenReturn(authentication);

Map<String, Object> apiResponse = new HashMap<>();
Map<String, Object> response = new HashMap<>();
response.put("p7bFile", "-----BEGIN CERTIFICATE-----\n" +
"MIIFfTCCA2WgAwIBAgIUOVZNyD46U0OAEhaGC/Y7NXbu+OkwDQYJKoZIhvcNAQEL\n" +
"BQAwTjELMAkGA1UEBhMCSU4xCzAJBgNVBAgMAk1IMQswCQYDVQQHDAJQTjELMAkG\n" +
"A1UECgwCQ0ExCzAJBgNVBAsMAkNBMQswCQYDVQQDDAJDQTAeFw0yNDA1MDkwNzI1\n" +
"MDJaFw0yOTA1MDkwNzI1MDJaME4xCzAJBgNVBAYTAklOMQswCQYDVQQIDAJNSDEL\n" +
"MAkGA1UEBwwCUE4xCzAJBgNVBAoMAkNBMQswCQYDVQQLDAJDQTELMAkGA1UEAwwC\n" +
"Q0EwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCzdWD2DvhSnmLqU3fX\n" +
"RT3z8ikS6qHxn5Hu/a2ijkuZxAZj0UCUJ83kM20NwocJDHT1qx6+yjdl+BECsgoI\n" +
"ro9MXgFOsHCphyR5KiP4mY95qRlE03h7WBfr4wDn/6f5tCbqCcBqdXMAQxUp34D+\n" +
"Pro0EwkXNulHNMTvz5hpoCEiGyfXUP48I4q2nb8rMXaplhqz+vAYgA4rsK6K9IUh\n" +
"uJDxtZRHdIfxnvbfjxDbuPkN0ehOQ1u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jnktCLWoXjSb9\n" +
"JqOYF3yo6JQslQB0fQMyKmvsn/FplQBbU0PUrg9vpAg9nZlZf3UHO5z072pXD6ky\n" +
"5pKjh+q0JOk00Eln9AoU6YuIyPBQ9mI3X8iYB5UhUBbgAPeg1pwWCWhdt40f0D5t\n" +
"JkVnICy+Gh1ps8QPA6coEaajbIq14Uh6eYEwxFHPsxlbn7pzjoCJG2v7N8VwgfuL\n" +
"DdGs4hFikdUAfBT/Diug/n9/ZgfdN6Ctf4U/SM65vZvfRqtLIoTIs4PcF3YtKK04\n" +
"m0UA3Sxxre0vVWYO4GmmZUY=\n" +
"-----END CERTIFICATE-----");
apiResponse.put("response", response);

when(environment.getProperty("pmp.download.ca.certificate.get.rest.uri")).thenReturn("uri");
when(restUtil.getApi(anyString(), any(), eq(Map.class))).thenReturn(apiResponse);
partnerManagementImpl.downloadRootCertificate("123");
}

@Test
public void downloadRootCertificateExceptionTest1() throws Exception {
MosipUserDto mosipUserDto = getMosipUserDto();
AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123");
SecurityContextHolder.setContext(securityContext);
when(authentication.getPrincipal()).thenReturn(authUserDetails);
when(securityContext.getAuthentication()).thenReturn(authentication);
partnerManagementImpl.downloadRootCertificate("");
}

@Test
public void downloadRootCertificateExceptionTest2() throws Exception {
MosipUserDto mosipUserDto = getMosipUserDto();
AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123");
SecurityContextHolder.setContext(securityContext);
when(authentication.getPrincipal()).thenReturn(authUserDetails);
when(securityContext.getAuthentication()).thenReturn(authentication);
List<Map<String, Object>> errorList = new ArrayList<>();
Map<String, Object> error = new HashMap<>();
error.put("errorCode", "001");
error.put("message", "error occured");
errorList.add(error);
Map<String, Object> apiResponse = new HashMap<>();
apiResponse.put("response", null);
apiResponse.put("errors", errorList);

when(environment.getProperty("pmp.download.ca.certificate.get.rest.uri")).thenReturn("uri");
when(restUtil.getApi(anyString(), any(), eq(Map.class))).thenReturn(apiResponse);
partnerManagementImpl.downloadRootCertificate("123");
}

@Test
public void downloadRootCertificateExceptionTes3() throws Exception {
MosipUserDto mosipUserDto = getMosipUserDto();
AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123");
SecurityContextHolder.setContext(securityContext);
when(authentication.getPrincipal()).thenReturn(authUserDetails);
when(securityContext.getAuthentication()).thenReturn(authentication);
List<Map<String, Object>> errorList = new ArrayList<>();
Map<String, Object> apiResponse = new HashMap<>();
apiResponse.put("response", null);
apiResponse.put("errors", errorList);

when(environment.getProperty("pmp.download.ca.certificate.get.rest.uri")).thenReturn("uri");
when(restUtil.getApi(anyString(), any(), eq(Map.class))).thenReturn(apiResponse);
partnerManagementImpl.downloadRootCertificate("123");
}

@Test
public void downloadRootCertificateExceptionTest5() throws Exception {
MosipUserDto mosipUserDto = getMosipUserDto();
AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123");
SecurityContextHolder.setContext(securityContext);
when(authentication.getPrincipal()).thenReturn(authUserDetails);
when(securityContext.getAuthentication()).thenReturn(authentication);
List<Map<String, Object>> errorList = new ArrayList<>();
Map<String, Object> error = new HashMap<>();
error.put("errorCodes", "001");
error.put("messages", "error occured");
errorList.add(error);
Map<String, Object> apiResponse = new HashMap<>();
apiResponse.put("response", null);
apiResponse.put("errors", errorList);

when(environment.getProperty("pmp.download.ca.certificate.get.rest.uri")).thenReturn("uri");
when(restUtil.getApi(anyString(), any(), eq(Map.class))).thenReturn(apiResponse);
partnerManagementImpl.downloadRootCertificate("123");
}

@Test
public void downloadRootCertificateExceptionTes4() throws Exception {
MosipUserDto mosipUserDto = getMosipUserDto();
AuthUserDetails authUserDetails = new AuthUserDetails(mosipUserDto, "123");
SecurityContextHolder.setContext(securityContext);
when(authentication.getPrincipal()).thenReturn(authUserDetails);
when(securityContext.getAuthentication()).thenReturn(authentication);
Map<String, Object> apiResponse = new HashMap<>();
apiResponse.put("response", null);

when(environment.getProperty("pmp.download.ca.certificate.get.rest.uri")).thenReturn("uri");
when(restUtil.getApi(anyString(), any(), eq(Map.class))).thenReturn(apiResponse);
partnerManagementImpl.downloadRootCertificate("123");
}

private io.mosip.kernel.openid.bridge.model.MosipUserDto getMosipUserDto() {
io.mosip.kernel.openid.bridge.model.MosipUserDto mosipUserDto = new io.mosip.kernel.openid.bridge.model.MosipUserDto();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pmp.partner.certificaticate.get.rest.uri=https://localhost/v1/keymanager/getPart
pmp.partner.original.certificate.get.rest.uri=https://localhost/v1/keymanager/getPartnerSignedCertificate/{partnerCertId}
pmp-keymanager.upload.other.domain.cert.rest.uri=http://kernel-keymanager-service/v1/keymanager/uploadOtherDomainCertificate
pmp.ca.certificates.post.rest.uri=${mosip.kernel.keymanager.url}/v1/keymanager/getCaCertificates
pmp.download.ca.certificate.get.rest.uri=${mosip.kernel.keymanager.url}/v1/keymanager/getCACertificateTrustPath/{caCertId}
application.id=PARTNER
###############Keycloak configuration ##########################
mosip.iam.base-url=https://localhost/keycloak
Expand Down Expand Up @@ -328,6 +329,8 @@ mosip.role.pms.getpartnersftmchipdetails=PARTNER_ADMIN
mosip.role.pms.getallsbidetails=PARTNER_ADMIN
mosip.role.pms.getalldevicedetails=PARTNER_ADMIN
mosip.role.pms.getallcacertificates=PARTNER_ADMIN
mosip.role.pms.getdownloadrootcertificate=PARTNER_ADMIN
mosip.role.pms.getpartnersv4=DEVICE_PROVIDER,FTM_PROVIDER,PARTNER_ADMIN,AUTH_PARTNER,ABIS_PARTNER,SDK_PARTNER,CREDENTIAL_PARTNER,PARTNER_ADMIN,ONLINE_VERIFICATION_PARTNER

#id for the API
mosip.pms.api.id.oauth.clients.get=mosip.pms.oauth.clients.get
Expand Down Expand Up @@ -360,4 +363,5 @@ mosip.pms.api.id.partners.ftm.chip.details.get=mosip.pms.partners.ftm.chip.detai
mosip.pms.api.id.all.sbi.details.get=mosip.pms.all.sbi.details.get
mosip.pms.api.id.get.all.device.details.get=mosip.pms.get.all.device.details.get
mosip.pms.api.id.all.ca.certificates.get=mosip.pms.all.ca.certificates.get
mosip.pms.api.id.download.ca.certificate.get=mosip.pms.download.ca.certificate.get
mosip.pms.api.id.partners.v4.get=mosip.pms.partners.v4.get

0 comments on commit 8a57fa9

Please sign in to comment.