Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INJICERT-499] Added JsonObject in place of HashMap for identity data #74

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.mosip.kernel.keymanagerservice.entity.KeyAlias;
import io.mosip.kernel.keymanagerservice.helper.KeymanagerDBHelper;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand Down Expand Up @@ -65,7 +66,7 @@ public class MockIdaDataProviderPlugin implements DataProviderPlugin {
private boolean storeIndividualId;

@Override
public Map<String, Object> fetchData(Map<String, Object> identityDetails) throws DataProviderExchangeException {
public JSONObject fetchData(Map<String, Object> identityDetails) throws DataProviderExchangeException {
try {
OIDCTransaction transaction = mockTransactionHelper.getUserInfoTransaction(identityDetails.get(ACCESS_TOKEN_HASH).toString());
String individualId = getIndividualId(transaction);
Expand All @@ -74,21 +75,21 @@ public Map<String, Object> fetchData(Map<String, Object> identityDetails) throws
getIdentityUrl + "/" + individualId,
HashMap.class);
res = (Map<String, Object>) res.get("response");
Map<String, Object> ret = new HashMap<>();
ret.put("vcVer", "VC-V1");
ret.put("id", getIdentityUrl + "/" + individualId);
ret.put("UIN", individualId);
ret.put("fullName", res.get("fullName"));
ret.put("gender", res.get("gender"));
ret.put("dateOfBirth", res.get("dateOfBirth"));
ret.put("email", res.get("email"));
ret.put("phone", res.get("phone"));
ret.put("addressLine1", res.get("streetAddress"));
ret.put("province", res.get("locality"));
ret.put("region", res.get("region"));
ret.put("postalCode", res.get("postalCode"));
ret.put("face", res.get("encodedPhoto"));
return ret;
JSONObject jsonRes = new JSONObject();
jsonRes.put("vcVer", "VC-V1");
jsonRes.put("id", getIdentityUrl + "/" + individualId);
jsonRes.put("UIN", individualId);
jsonRes.put("fullName", res.get("fullName"));
jsonRes.put("gender", res.get("gender"));
jsonRes.put("dateOfBirth", res.get("dateOfBirth"));
jsonRes.put("email", res.get("email"));
jsonRes.put("phone", res.get("phone"));
jsonRes.put("addressLine1", res.get("streetAddress"));
jsonRes.put("province", res.get("locality"));
jsonRes.put("region", res.get("region"));
jsonRes.put("postalCode", res.get("postalCode"));
jsonRes.put("face", res.get("encodedPhoto"));
return jsonRes;
}
} catch (Exception e) {
log.error("Failed to fetch json data for from data provider plugin", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import io.mosip.certify.api.exception.DataProviderExchangeException;
import io.mosip.esignet.core.dto.OIDCTransaction;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -70,8 +72,8 @@ public void setup() throws DataProviderExchangeException {
}

@Test
public void getJSONDataWithValidDetails_thenPass() throws DataProviderExchangeException {
Map<String, Object> jsonData = mockDataProviderPlugin.fetchData(Map.of("accessTokenHash","ACCESS_TOKEN_HASH","client_id","CLIENT_ID"));
public void getJSONDataWithValidDetails_thenPass() throws DataProviderExchangeException, JSONException {
JSONObject jsonData = mockDataProviderPlugin.fetchData(Map.of("accessTokenHash","ACCESS_TOKEN_HASH","client_id","CLIENT_ID"));
Assert.assertNotNull(jsonData);
Assert.assertNotNull(jsonData.get("fullName"));
Assert.assertEquals("fullName" ,jsonData.get("fullName"));
Expand Down
Loading