Skip to content

Commit

Permalink
Changed name of plugin to mock-ida-dataprovider-plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Piyush7034 <piyushshukla2100@gmail.com>
  • Loading branch information
Piyush7034 committed Oct 17, 2024
1 parent 8e38643 commit 4522c7d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 19 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/push-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,44 @@ jobs:
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

build-maven-mock-ida-dataprovider-plugin:
uses: mosip/kattu/.github/workflows/maven-build.yml@master-java21
with:
SERVICE_LOCATION: mock-ida-dataprovider-plugin
BUILD_ARTIFACT: mock-ida-dataprovider-plugin
secrets:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

publish_to_nexus_mock-ida-dataprovider-plugin:
if: "${{ !contains(github.ref, 'master') && github.event_name != 'pull_request' && github.event_name != 'release' && github.event_name != 'prerelease' && github.event_name != 'publish' }}"
needs: build-maven-mock-ida-dataprovider-plugin
uses: mosip/kattu/.github/workflows/maven-publish-to-nexus.yml@master-java21
with:
SERVICE_LOCATION: ./mock-ida-dataprovider-plugin
secrets:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
OSSRH_URL: ${{ secrets.OSSRH_SNAPSHOT_URL }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

sonar_analysis_mock-ida-dataprovider-plugin:
needs: build-maven-mock-ida-dataprovider-plugin
if: "${{ github.event_name != 'pull_request' }}"
uses: mosip/kattu/.github/workflows/maven-sonar-analysis.yml@master-java21
with:
SERVICE_LOCATION: ./mock-ida-dataprovider-plugin
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
ORG_KEY: ${{ secrets.ORG_KEY }}
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<modelVersion>4.0.0</modelVersion>

<groupId>io.mosip.certify</groupId>
<artifactId>mock-data-provider-plugin</artifactId>
<artifactId>mock-ida-dataprovider-plugin</artifactId>
<version>0.3.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>mock-data-provider-plugin</name>
<name>mock-ida-dataprovider-plugin</name>
<description>Mockup of a data provider plugin implementation that is used to showcase the integration with certify</description>
<url>https://github.com/mosip/digital-credential-plugins</url>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.mosip.certify.mockdataprovider.integration.service;
package io.mosip.certify.mockidadataprovider.integration.service;


import io.mosip.certify.api.exception.DataProviderExchangeException;
Expand All @@ -12,7 +12,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

Expand All @@ -24,9 +24,10 @@
import java.time.format.DateTimeFormatter;
import java.util.*;

@ConditionalOnProperty(value = "mosip.certify.integration.data-provider-plugin", havingValue = "MockIdaDataProviderPlugin")
@Component
@Slf4j
public class MockDataProviderPlugin implements DataProviderPlugin {
public class MockIdaDataProviderPlugin implements DataProviderPlugin {
private static final String AES_CIPHER_FAILED = "aes_cipher_failed";
private static final String NO_UNIQUE_ALIAS = "no_unique_alias";

Expand Down Expand Up @@ -58,11 +59,14 @@ public class MockDataProviderPlugin implements DataProviderPlugin {
private String aesECBTransformation;

@Value("${mosip.certify.cache.secure.individual-id}")
private boolean secureIndividualId;
private boolean isIndividualIDEncrypted;

@Value("${mosip.certify.cache.store.individual-id}")
private boolean storeIndividualId;

@Value("${mosip.certify.mockdp.vciplugin.issuer}")
private String getIssuerUrl;

@Override
public Map<String, Object> fetchData(Map<String, Object> identityDetails) throws DataProviderExchangeException {
try {
Expand All @@ -87,11 +91,12 @@ public Map<String, Object> fetchData(Map<String, Object> identityDetails) throws
ret.put("region", res.get("region"));
ret.put("postalCode", res.get("postalCode"));
ret.put("face", res.get("encodedPhoto"));
ret.put("issuer", getIdentityUrl + "/" + individualId);
ret.put("issuer", getIssuerUrl);
return ret;
}
} catch (Exception e) {
log.error("Failed to fetch json data for from data provider plugin", e);
throw new DataProviderExchangeException("ERROR_FETCHING_IDENTITY_DATA");
}

throw new DataProviderExchangeException("INVALID_ACCESS_TOKEN");
Expand All @@ -100,7 +105,7 @@ public Map<String, Object> fetchData(Map<String, Object> identityDetails) throws
protected String getIndividualId(OIDCTransaction transaction) {
if (!storeIndividualId)
return null;
return secureIndividualId ? decryptIndividualId(transaction.getIndividualId()) : transaction.getIndividualId();
return isIndividualIDEncrypted ? decryptIndividualId(transaction.getIndividualId()) : transaction.getIndividualId();
}

private String decryptIndividualId(String encryptedIndividualId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.mosip.certify.mockdataprovider.integration.service;
package io.mosip.certify.mockidadataprovider.integration.service;

import io.mosip.certify.api.exception.DataProviderExchangeException;
import io.mosip.esignet.core.dto.OIDCTransaction;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.mosip.certify.mockdataprovider.integration.service;
package io.mosip.certify.mockidadataprovider.integration.service;

import io.mosip.certify.api.exception.DataProviderExchangeException;
import io.mosip.esignet.core.dto.OIDCTransaction;
Expand All @@ -13,17 +13,14 @@
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.support.NoOpCache;
import org.springframework.http.ResponseEntity;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RunWith(MockitoJUnitRunner.class)
public class MockDataProviderPluginTest {
public class MockIdaDataProviderPluginTest {
@Mock
CacheManager cacheManager;

Expand All @@ -37,15 +34,16 @@ public class MockDataProviderPluginTest {
RestTemplate restTemplate;

@InjectMocks
MockDataProviderPlugin mockDataProviderPlugin;
MockIdaDataProviderPlugin mockDataProviderPlugin;

@Before
public void setup() throws DataProviderExchangeException {
ReflectionTestUtils.setField(mockDataProviderPlugin,"getIdentityUrl","http://example.com");
ReflectionTestUtils.setField(mockDataProviderPlugin,"cacheSecretKeyRefId","cacheSecretKeyRefId");
ReflectionTestUtils.setField(mockDataProviderPlugin,"aesECBTransformation","AES/ECB/PKCS5Padding");
ReflectionTestUtils.setField(mockDataProviderPlugin,"storeIndividualId",true);
ReflectionTestUtils.setField(mockDataProviderPlugin,"secureIndividualId",false);
ReflectionTestUtils.setField(mockDataProviderPlugin,"isIndividualIDEncrypted",false);
ReflectionTestUtils.setField(mockDataProviderPlugin,"getIssuerUrl","http://example.issuer.com");

OIDCTransaction oidcTransaction = new OIDCTransaction();
oidcTransaction.setTransactionId("test");
Expand Down Expand Up @@ -79,15 +77,15 @@ public void getJSONDataWithValidDetails_thenPass() throws DataProviderExchangeEx
Assert.assertEquals("fullName" ,jsonData.get("fullName"));
Assert.assertEquals("individualId", jsonData.get("UIN"));
Assert.assertNotNull(jsonData.get("issuer"));
Assert.assertEquals("http://example.com/individualId", jsonData.get("issuer"));
Assert.assertEquals("http://example.issuer.com", jsonData.get("issuer"));
}

@Test
public void getJSONDataWithInValidDetails_thenFail() throws DataProviderExchangeException {
try {
mockDataProviderPlugin.fetchData(Map.of("accessTokenHash","test","client_id","CLIENT_ID"));
} catch (Exception e) {
Assert.assertEquals("INVALID_ACCESS_TOKEN", e.getMessage());
Assert.assertEquals("ERROR_FETCHING_IDENTITY_DATA", e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.mosip.certify.mockdataprovider.integration.service;
package io.mosip.certify.mockidadataprovider.integration.service;

import io.mosip.certify.api.exception.DataProviderExchangeException;
import io.mosip.esignet.core.dto.OIDCTransaction;
Expand Down

0 comments on commit 4522c7d

Please sign in to comment.