Skip to content

Commit

Permalink
MOSIP-39220 - Syncing release branch with develop branch
Browse files Browse the repository at this point in the history
Signed-off-by: Mohanachandran S <[email protected]>
  • Loading branch information
mohanachandran-s committed Jan 24, 2025
1 parent d749656 commit 0380ab8
Show file tree
Hide file tree
Showing 29 changed files with 2,619 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jobs:
find ${{ env.SERVICE_LOCATION }} -path '*/target/*' -exec zip ${{ env.BUILD_ARTIFACT }}.zip {} +
- name: Upload the springboot jars
if: ${{ !contains(github.ref, 'master') || !contains(github.ref, 'main') }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v3
with:
name: ${{ env.BUILD_ARTIFACT }}
path: ${{ env.BUILD_ARTIFACT }}.zip
Expand Down
1 change: 1 addition & 0 deletions api-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,4 @@ To run the tests for both **Smoke** and **Regression**:
## License
This project is licensed under the terms of the [Mozilla Public License 2.0](https://github.com/mosip/mosip-platform/blob/master/LICENSE)
10 changes: 5 additions & 5 deletions api-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<name>apitest-prereg</name>
<description>Parent project of MOSIP Pre-Registration apitests</description>
<url>https://github.com/mosip/pre-registration</url>
<version>1.3.0-beta.1</version>
<version>1.3.0-SNAPSHOT</version>

<licenses>
<license>
Expand Down Expand Up @@ -49,14 +49,14 @@
<maven.source.plugin.version>2.2.1</maven.source.plugin.version>

<git.commit.id.plugin.version>3.0.1</git.commit.id.plugin.version>
<fileName>apitest-prereg-1.3.0-beta.1-jar-with-dependencies</fileName>
<fileName>apitest-prereg-1.3.0-SNAPSHOT-jar-with-dependencies</fileName>
</properties>

<dependencies>
<dependency>
<groupId>io.mosip.testrig.apitest.commons</groupId>
<artifactId>apitest-commons</artifactId>
<version>1.3.0</version>
<version>1.3.1-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -163,7 +163,7 @@
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>
io.mosip.testrig.apirig.testrunner.MosipTestRunner</mainClass>
io.mosip.testrig.apirig.prereg.testrunner.MosipTestRunner</mainClass>
</transformer>
</transformers>
<!-- add this to prevent some security issues when
Expand Down Expand Up @@ -265,4 +265,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
package io.mosip.testrig.apirig.prereg.testrunner;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.interfaces.RSAPublicKey;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.bouncycastle.openssl.jcajce.JcaPEMWriter;
import org.testng.TestNG;

import com.nimbusds.jose.jwk.KeyUse;
import com.nimbusds.jose.jwk.RSAKey;

import io.mosip.testrig.apirig.prereg.utils.PreRegConfigManager;
import io.mosip.testrig.apirig.testrunner.BaseTestCase;
import io.mosip.testrig.apirig.testrunner.ExtractResource;
import io.mosip.testrig.apirig.testrunner.HealthChecker;
import io.mosip.testrig.apirig.testrunner.OTPListener;
import io.mosip.testrig.apirig.utils.AdminTestUtil;
import io.mosip.testrig.apirig.utils.AuthTestsUtil;
import io.mosip.testrig.apirig.utils.CertsUtil;
import io.mosip.testrig.apirig.utils.ConfigManager;
import io.mosip.testrig.apirig.utils.GlobalConstants;
import io.mosip.testrig.apirig.utils.JWKKeyUtil;
import io.mosip.testrig.apirig.utils.KeyCloakUserAndAPIKeyGeneration;
import io.mosip.testrig.apirig.utils.KeycloakUserManager;
import io.mosip.testrig.apirig.utils.MispPartnerAndLicenseKeyGeneration;
import io.mosip.testrig.apirig.utils.OutputValidationUtil;
import io.mosip.testrig.apirig.utils.PartnerRegistration;
import io.mosip.testrig.apirig.utils.SkipTestCaseHandler;

/**
* Class to initiate mosip api test execution
*
* @author Vignesh
*
*/
public class MosipTestRunner {
private static final Logger LOGGER = Logger.getLogger(MosipTestRunner.class);
private static String cachedPath = null;

public static String jarUrl = MosipTestRunner.class.getProtectionDomain().getCodeSource().getLocation().getPath();
public static List<String> languageList = new ArrayList<>();

/**
* C Main method to start mosip test execution
*
* @param arg
*/
public static void main(String[] arg) {

try {

Map<String, String> envMap = System.getenv();
LOGGER.info("** ------------- Get ALL ENV varibales --------------------------------------------- **");
for (String envName : envMap.keySet()) {
LOGGER.info(String.format("ENV %s = %s%n", envName, envMap.get(envName)));
}
BaseTestCase.setRunContext(getRunType(), jarUrl);
ExtractResource.removeOldMosipTestTestResource();
if (getRunType().equalsIgnoreCase("JAR")) {
ExtractResource.extractCommonResourceFromJar();
} else {
ExtractResource.copyCommonResources();
}
AdminTestUtil.init();
PreRegConfigManager.init();
suiteSetup(getRunType());
SkipTestCaseHandler.loadTestcaseToBeSkippedList("testCaseSkippedList.txt");
setLogLevels();
AdminTestUtil.getRequiredField();

// For now we are not doing health check for qa-115.
if (BaseTestCase.isTargetEnvLTS()) {
HealthChecker healthcheck = new HealthChecker();
healthcheck.setCurrentRunningModule(BaseTestCase.currentModule);
Thread trigger = new Thread(healthcheck);
trigger.start();
}
KeycloakUserManager.removeUser();
KeycloakUserManager.createUsers();
KeycloakUserManager.closeKeycloakInstance();

// List<String> localDocCatCode =new ArrayList<>(BaseTestCase.getDocCatCode());

startTestRunner();
} catch (Exception e) {
LOGGER.error("Exception " + e.getMessage());
}

OTPListener.bTerminate = true;

if (BaseTestCase.isTargetEnvLTS())
HealthChecker.bTerminate = true;

System.exit(0);

}

public static void suiteSetup(String runType) {
if (ConfigManager.IsDebugEnabled())
LOGGER.setLevel(Level.ALL);
else
LOGGER.info("Test Framework for Mosip api Initialized");
BaseTestCase.initialize();
LOGGER.info("Done with BeforeSuite and test case setup! su TEST EXECUTION!\n\n");

if (!runType.equalsIgnoreCase("JAR")) {
AuthTestsUtil.removeOldMosipTempTestResource();
}

BaseTestCase.currentModule = GlobalConstants.PREREG;
AdminTestUtil.copyPreregTestResource();
BaseTestCase.otpListener = new OTPListener();
BaseTestCase.otpListener.run();
}

private static void setLogLevels() {
AdminTestUtil.setLogLevel();
OutputValidationUtil.setLogLevel();
PartnerRegistration.setLogLevel();
KeyCloakUserAndAPIKeyGeneration.setLogLevel();
MispPartnerAndLicenseKeyGeneration.setLogLevel();
JWKKeyUtil.setLogLevel();
CertsUtil.setLogLevel();
}

/**
* The method to start mosip testng execution
*
* @throws IOException
*/
public static void startTestRunner() {
File homeDir = null;
TestNG runner = new TestNG();
List<String> suitefiles = new ArrayList<>();
String os = System.getProperty("os.name");
LOGGER.info(os);
if (getRunType().contains("IDE") || os.toLowerCase().contains("windows")) {
homeDir = new File(System.getProperty("user.dir") + "/testNgXmlFiles");
LOGGER.info("IDE :" + homeDir);
} else {
File dir = new File(System.getProperty("user.dir"));
homeDir = new File(dir.getParent() + "/mosip/testNgXmlFiles");
LOGGER.info("ELSE :" + homeDir);
}
File[] files = homeDir.listFiles();
if (files != null) {
for (File file : files) {
if (file.getName().toLowerCase().contains("mastertestsuite")) {
BaseTestCase.setReportName(GlobalConstants.PREREG);
suitefiles.add(file.getAbsolutePath());
runner.setTestSuites(suitefiles);
System.getProperties().setProperty("testng.outpur.dir", "testng-report");
runner.setOutputDirectory("testng-report");
runner.run();
}
}
} else {
LOGGER.error("No files found in directory: " + homeDir);
}
}

public static String getGlobalResourcePath() {
if (cachedPath != null) {
return cachedPath;
}

String path = null;
if (getRunType().equalsIgnoreCase("JAR")) {
path = new File(jarUrl).getParentFile().getAbsolutePath() + "/MosipTestResource/MosipTemporaryTestResource";
} else if (getRunType().equalsIgnoreCase("IDE")) {
path = new File(MosipTestRunner.class.getClassLoader().getResource("").getPath()).getAbsolutePath()
+ "/MosipTestResource/MosipTemporaryTestResource";
if (path.contains(GlobalConstants.TESTCLASSES))
path = path.replace(GlobalConstants.TESTCLASSES, "classes");
}

if (path != null) {
cachedPath = path;
return path;
} else {
return "Global Resource File Path Not Found";
}
}

public static String getResourcePath() {
return getGlobalResourcePath();
}

public static String generatePulicKey() {
String publicKey = null;
try {
KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("RSA");
keyGenerator.initialize(2048, BaseTestCase.secureRandom);
final KeyPair keypair = keyGenerator.generateKeyPair();
publicKey = java.util.Base64.getEncoder().encodeToString(keypair.getPublic().getEncoded());
} catch (NoSuchAlgorithmException e) {
LOGGER.error(e.getMessage());
}
return publicKey;
}

public static KeyPairGenerator keyPairGen = null;

public static KeyPairGenerator getKeyPairGeneratorInstance() {
if (keyPairGen != null)
return keyPairGen;
try {
keyPairGen = KeyPairGenerator.getInstance("RSA");
keyPairGen.initialize(2048);

} catch (NoSuchAlgorithmException e) {
LOGGER.error(e.getMessage());
}

return keyPairGen;
}

public static String generatePublicKeyForMimoto() {

String vcString = "";
try {
KeyPairGenerator keyPairGenerator = getKeyPairGeneratorInstance();
KeyPair keyPair = keyPairGenerator.generateKeyPair();
PublicKey publicKey = keyPair.getPublic();
StringWriter stringWriter = new StringWriter();
try (JcaPEMWriter pemWriter = new JcaPEMWriter(stringWriter)) {
pemWriter.writeObject(publicKey);
pemWriter.flush();
vcString = stringWriter.toString();
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
vcString = vcString.replaceAll("\r\n", "\\\\n");
} else {
vcString = vcString.replaceAll("\n", "\\\\n");
}
} catch (Exception e) {
throw e;
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
return vcString;
}

public static String generateJWKPublicKey() {
try {
KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("RSA");
keyGenerator.initialize(2048, BaseTestCase.secureRandom);
final KeyPair keypair = keyGenerator.generateKeyPair();
RSAKey jwk = new RSAKey.Builder((RSAPublicKey) keypair.getPublic()).keyID("RSAKeyID")
.keyUse(KeyUse.SIGNATURE).privateKey(keypair.getPrivate()).build();

return jwk.toJSONString();
} catch (NoSuchAlgorithmException e) {
LOGGER.error(e.getMessage());
return null;
}
}

public static Properties getproperty(String path) {
Properties prop = new Properties();
FileInputStream inputStream = null;
try {
File file = new File(path);
inputStream = new FileInputStream(file);
prop.load(inputStream);
} catch (Exception e) {
LOGGER.error(GlobalConstants.EXCEPTION_STRING_2 + e.getMessage());
} finally {
AdminTestUtil.closeInputStream(inputStream);
}
return prop;
}

/**
* The method will return mode of application started either from jar or eclipse
* ide
*
* @return
*/
public static String getRunType() {
if (MosipTestRunner.class.getResource("MosipTestRunner.class").getPath().contains(".jar"))
return "JAR";
else
return "IDE";
}

}
Loading

0 comments on commit 0380ab8

Please sign in to comment.