Skip to content
Closed
10 changes: 5 additions & 5 deletions .github/workflows/push-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
secrets:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
OSSRH_URL: ${{ secrets.OSSRH_SNAPSHOT_URL }}
OSSRH_URL: ${{ secrets.OSSRH_CENTRAL_URL }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
secrets:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
OSSRH_URL: ${{ secrets.OSSRH_SNAPSHOT_URL }}
OSSRH_URL: ${{ secrets.OSSRH_CENTRAL_URL }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
Expand Down Expand Up @@ -126,7 +126,7 @@ jobs:
secrets:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
OSSRH_URL: ${{ secrets.OSSRH_SNAPSHOT_URL }}
OSSRH_URL: ${{ secrets.OSSRH_CENTRAL_URL }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:
secrets:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
OSSRH_URL: ${{ secrets.OSSRH_SNAPSHOT_URL }}
OSSRH_URL: ${{ secrets.OSSRH_CENTRAL_URL }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
Expand Down Expand Up @@ -208,7 +208,7 @@ jobs:
secrets:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
OSSRH_URL: ${{ secrets.OSSRH_SNAPSHOT_URL }}
OSSRH_URL: ${{ secrets.OSSRH_CENTRAL_URL }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
Expand Down
58 changes: 23 additions & 35 deletions mock-certify-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

<modelVersion>4.0.0</modelVersion>

<groupId>io.mosip.certify</groupId>
<groupId>io.inji.certify</groupId>
<artifactId>mock-certify-plugin</artifactId>
<version>0.4.0-SNAPSHOT</version>
<version>0.6.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>mock-certify-integration-impl</name>
<description>Mockup of a wrapper implementation that is used to showcase the integration with certify</description>
<url>https://github.com/mosip/digital-credential-plugins</url>
<url>https://github.com/inji/digital-credential-plugins</url>

<licenses>
<license>
Expand All @@ -24,17 +24,17 @@
</license>
</licenses>
<scm>
<connection>scm:git:git://github.com/mosip/digital-credential-plugins.git</connection>
<developerConnection>scm:git:ssh://github.com:mosip/digital-credential-plugins.git</developerConnection>
<url>https://github.com/mosip/digital-credential-plugins</url>
<connection>scm:git:git://github.com/inji/digital-credential-plugins.git</connection>
<developerConnection>scm:git:ssh://github.com:inji/digital-credential-plugins.git</developerConnection>
<url>https://github.com/inji/digital-credential-plugins</url>
<tag>HEAD</tag>
</scm>
<developers>
<developer>
<name>Mosip</name>
<email>[email protected]</email>
<organization>io.mosip</organization>
<organizationUrl>https://www.mosip.io</organizationUrl>
<organization>io.inji</organization>
<organizationUrl>https://inji.io</organizationUrl>
</developer>
</developers>

Expand All @@ -48,7 +48,7 @@
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
<maven-source-plugin>2.2.1</maven-source-plugin>
<nexus-staging-maven-plugin>6.1.0</nexus-staging-maven-plugin>
<central.publishing.maven.plugin.version>0.7.0</central.publishing.maven.plugin.version>
<git-commit-id-plugin.version>3.0.1</git-commit-id-plugin.version>
<maven.jacoco.version>0.8.11</maven.jacoco.version>
<maven-javadoc-plugin.version>3.6.3</maven-javadoc-plugin.version>
Expand All @@ -63,15 +63,15 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.mosip.certify</groupId>
<groupId>io.inji.certify</groupId>
<artifactId>certify-core</artifactId>
<version>0.11.0-SNAPSHOT</version>
<version>0.14.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.mosip.esignet</groupId>
<artifactId>esignet-core</artifactId>
<version>1.5.1</version>
<version>1.6.2</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
Expand All @@ -82,7 +82,7 @@
<dependency>
<groupId>io.mosip.esignet</groupId>
<artifactId>esignet-integration-api</artifactId>
<version>1.5.1</version>
<version>1.6.2</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
Expand Down Expand Up @@ -170,9 +170,9 @@

<repositories>
<repository>
<id>ossrh</id>
<name>CentralRepository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<id>ossrh-central</id>
<name>MavenCentralRepository</name>
<url>https://central.sonatype.com/repository/maven-snapshots</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
Expand Down Expand Up @@ -200,14 +200,13 @@
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
<url>https://central.sonatype.com/api/v1/publisher</url>
</repository>
</distributionManagement>

<build>
<plugins>
<!-- assembly-plugin -->
Expand Down Expand Up @@ -262,26 +261,15 @@
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.14</version>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>${central.publishing.maven.plugin.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
<publishingServerId>ossrh</publishingServerId>
<autoPublish>false</autoPublish>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class MDocMockVCIssuancePlugin implements VCIssuancePlugin {
private static final String ACCESS_TOKEN_HASH = "accessTokenHash";

public static final String CERTIFY_SERVICE_APP_ID = "CERTIFY_SERVICE";

@Autowired
private MdocGenerator mdocGenerator;

@Override
public VCResult<JsonLDObject> getVerifiableCredentialWithLinkedDataProof(VCRequestDto vcRequestDto, String holderId, Map<String, Object> identityDetails) throws VCIExchangeException {
Expand All @@ -84,7 +87,7 @@ public VCResult<String> getVerifiableCredential(VCRequestDto vcRequestDto, Strin
VCResult<String> vcResult = new VCResult<>();
String mdocVc;
try {
mdocVc = new MdocGenerator().generate(mockDataForMsoMdoc(documentNumber),holderId, issuerKeyAndCertificate);
mdocVc = mdocGenerator.generate(mockDataForMsoMdoc(documentNumber),holderId, issuerKeyAndCertificate);
} catch (Exception e) {
log.error("Exception on mdoc creation", e);
throw new VCIExchangeException(ErrorConstants.VCI_EXCHANGE_FAILED);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package io.mosip.certify.mock.integration.service;

import io.mosip.certify.api.dto.VCRequestDto;
import io.mosip.certify.api.dto.VCResult;
import io.mosip.certify.api.exception.VCIExchangeException;
import io.mosip.certify.constants.VCFormats;
import io.mosip.certify.core.exception.CertifyException;
import io.mosip.certify.mock.integration.mocks.MdocGenerator;
import io.mosip.esignet.core.dto.OIDCTransaction;
import io.mosip.kernel.core.keymanager.spi.KeyStore;
import io.mosip.kernel.keymanagerservice.entity.KeyAlias;
import io.mosip.kernel.keymanagerservice.helper.KeymanagerDBHelper;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.*;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.test.util.ReflectionTestUtils;

import java.security.Key;
import java.time.LocalDateTime;
import java.util.*;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

@RunWith(org.mockito.junit.MockitoJUnitRunner.class)
public class MDocMockVCIssuancePluginTest {

@InjectMocks
private MDocMockVCIssuancePlugin plugin;

@Mock
private CacheManager cacheManager;
@Mock
private KeyStore keyStore;
@Mock
private KeymanagerDBHelper dbHelper;
@Mock
private Cache cache;
@Mock
private Key key;
@Mock
private MdocGenerator mdocGenerator;

@Before
public void setUp() {
ReflectionTestUtils.setField(plugin, "issuerKeyAndCertificate", "empty");
ReflectionTestUtils.setField(plugin, "cacheSecretKeyRefId", "refId");
ReflectionTestUtils.setField(plugin, "aesECBTransformation", "AES/ECB/PKCS5Padding");
ReflectionTestUtils.setField(plugin, "storeIndividualId", true);
ReflectionTestUtils.setField(plugin, "secureIndividualId", false);
}

@Test
public void testGetVerifiableCredential_Success() throws Exception {
VCRequestDto dto = mock(VCRequestDto.class);
when(dto.getFormat()).thenReturn(VCFormats.MSO_MDOC);

Map<String, Object> identityDetails = new HashMap<>();
identityDetails.put("accessTokenHash", "tokenHash");

OIDCTransaction transaction = mock(OIDCTransaction.class);
when(transaction.getIndividualId()).thenReturn("docNum");

when(cacheManager.getCache(anyString())).thenReturn(cache);
when(cache.get(anyString(), eq(OIDCTransaction.class))).thenReturn(transaction);

when(mdocGenerator.generate(anyMap(), anyString(), anyString())).thenReturn("mockedMdoc");

VCResult<String> result = plugin.getVerifiableCredential(dto, "holderId", identityDetails);

assertNotNull(result);
assertEquals(VCFormats.MSO_MDOC, result.getFormat());
assertEquals("mockedMdoc", result.getCredential());
}

@Test(expected = VCIExchangeException.class)
public void testGetVerifiableCredential_NotImplemented() throws Exception {
VCRequestDto dto = mock(VCRequestDto.class);

Map<String, Object> identityDetails = new HashMap<>();
identityDetails.put("accessTokenHash", "tokenHash");

plugin.getVerifiableCredential(dto, "holderId", identityDetails);
}

@Test(expected = VCIExchangeException.class)
public void testGetVerifiableCredentialWithLinkedDataProof_NotImplemented() throws Exception {
VCRequestDto dto = mock(VCRequestDto.class);
plugin.getVerifiableCredentialWithLinkedDataProof(dto, "holderId", new HashMap<>());
}

@Test
public void testGetIndividualId_SecureFalse() {
OIDCTransaction transaction = mock(OIDCTransaction.class);
when(transaction.getIndividualId()).thenReturn("docNum");
ReflectionTestUtils.setField(plugin, "secureIndividualId", false);
ReflectionTestUtils.setField(plugin, "storeIndividualId", true);
String result = (String) ReflectionTestUtils.invokeMethod(plugin, "getIndividualId", transaction);
assertEquals("docNum", result);
}

@Test
public void testGetIndividualId_StoreFalse() {
OIDCTransaction transaction = mock(OIDCTransaction.class);
ReflectionTestUtils.setField(plugin, "storeIndividualId", false);
String result = (String) ReflectionTestUtils.invokeMethod(plugin, "getIndividualId", transaction);
assertNull(result);
}

@Test(expected = CertifyException.class)
public void testDecryptIndividualId_Exception() {
ReflectionTestUtils.setField(plugin, "aesECBTransformation", "invalid");
ReflectionTestUtils.invokeMethod(plugin, "decryptIndividualId", "invalid");
}

@Test(expected = CertifyException.class)
public void testGetSecretKeyFromHSM_NoAlias() {
when(dbHelper.getKeyAliases(anyString(), anyString(), any(LocalDateTime.class)))
.thenReturn(Collections.singletonMap("currentKeyAlias", new ArrayList<>()));
ReflectionTestUtils.invokeMethod(plugin, "getSecretKeyFromHSM");
}

@Test
public void testGetKeyAlias_Success() {
KeyAlias alias = mock(KeyAlias.class);
when(alias.getAlias()).thenReturn("alias");
List<KeyAlias> aliases = Collections.singletonList(alias);
Map<String, List<KeyAlias>> map = new HashMap<>();
map.put("currentKeyAlias", aliases);
when(dbHelper.getKeyAliases(anyString(), anyString(), any(LocalDateTime.class))).thenReturn(map);
String result = (String) ReflectionTestUtils.invokeMethod(plugin, "getKeyAlias", "appId", "refId");
assertEquals("alias", result);
}

@Test(expected = CertifyException.class)
public void testGetKeyAlias_NotUnique() {
List<KeyAlias> aliases = Arrays.asList(mock(KeyAlias.class), mock(KeyAlias.class));
Map<String, List<KeyAlias>> map = new HashMap<>();
map.put("currentKeyAlias", aliases);
when(dbHelper.getKeyAliases(anyString(), anyString(), any(LocalDateTime.class))).thenReturn(map);
ReflectionTestUtils.invokeMethod(plugin, "getKeyAlias", "appId", "refId");
}

@Test
public void testMockDataForMsoMdoc() {
String docNum = "12345";
@SuppressWarnings("unchecked")
Map<String, Object> data = (Map<String, Object>) ReflectionTestUtils.invokeMethod(plugin, "mockDataForMsoMdoc", docNum);
assertNotNull(data);
assertEquals("Agatha", data.get("family_name"));
assertEquals("Joseph", data.get("given_name"));
assertEquals("1994-11-06", data.get("birth_date"));
assertEquals("IN", data.get("issuing_country"));
assertEquals(docNum, data.get("document_number"));
assertTrue(data.get("driving_privileges") instanceof Map);
assertEquals("A", ((Map<?, ?>) data.get("driving_privileges")).get("vehicle_category_code"));
}

@Test
public void testGetUserInfoTransaction() {
String accessTokenHash = "tokenHash";
OIDCTransaction transaction = mock(OIDCTransaction.class);
when(cacheManager.getCache(anyString())).thenReturn(cache);
when(cache.get(eq(accessTokenHash), eq(OIDCTransaction.class))).thenReturn(transaction);

OIDCTransaction result = (OIDCTransaction) ReflectionTestUtils.invokeMethod(plugin, "getUserInfoTransaction", accessTokenHash);
assertNotNull(result);
assertEquals(transaction, result);
}
}
Loading
Loading