From ad8587a1a6882bc1774dab9e46c07a1f54f9211f Mon Sep 17 00:00:00 2001 From: Nandhukumar Date: Mon, 2 Dec 2024 12:15:46 +0530 Subject: [PATCH 1/5] MOSIP-35404 Signed-off-by: Nandhukumar --- api-test/pom.xml | 6 +-- .../resident/testrunner/MosipTestRunner.java | 1 + .../resident/testscripts/AddIdentity.java | 3 -- .../resident/testscripts/DeleteWithParam.java | 1 - .../resident/testscripts/GetWithParam.java | 1 - .../testscripts/GetWithParamForAutoGenId.java | 1 - .../GetWithParamForDownloadCard.java | 1 - .../GetWithQueryParamForDownloadCard.java | 1 - .../PostWithAutogenIdWithOtpGenerate.java | 2 - .../PostWithBodyWithOtpGenerate.java | 2 - .../PostWithBodyWithPdfDownload.java | 1 - .../testscripts/PostWithOnlyPathParam.java | 1 - .../testscripts/PostWithParamAndFile.java | 1 - .../resident/testscripts/SimplePatch.java | 1 - .../resident/testscripts/SimplePost.java | 1 - .../testscripts/SimplePostForAutoGenId.java | 2 - .../SimplePostForAutoGenIdForUrlEncoded.java | 1 - .../resident/testscripts/SimplePut.java | 1 - .../apirig/resident/utils/ResidentUtil.java | 43 +++++++++++++++++++ 19 files changed, 47 insertions(+), 24 deletions(-) diff --git a/api-test/pom.xml b/api-test/pom.xml index 3ee4368477..642167627e 100644 --- a/api-test/pom.xml +++ b/api-test/pom.xml @@ -8,7 +8,7 @@ apitest-resident Parent project of MOSIP Resident Services apitests https://github.com/mosip/resident-services - 1.2.1-SNAPSHOT + 1.2.1-cleanup-SNAPSHOT @@ -49,14 +49,14 @@ 2.2.1 3.0.1 - apitest-resident-1.2.1-SNAPSHOT-jar-with-dependencies + apitest-resident-1.2.1-cleanup-SNAPSHOT-jar-with-dependencies io.mosip.testrig.apirig.apitest.commons apitest-commons - 1.2.2-SNAPSHOT + 1.2.2-cleanup-SNAPSHOT diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testrunner/MosipTestRunner.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testrunner/MosipTestRunner.java index fa83026ef2..010fe7c2f1 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testrunner/MosipTestRunner.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testrunner/MosipTestRunner.java @@ -95,6 +95,7 @@ public static void main(String[] arg) { KeycloakUserManager.removeUser(); KeycloakUserManager.createUsers(); KeycloakUserManager.closeKeycloakInstance(); + AdminTestUtil.getRequiredField(); AdminTestUtil.getRegistrationCenterData(); AdminTestUtil.getLocationDataWithLocationCode(BaseTestCase.locationCode); diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/AddIdentity.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/AddIdentity.java index dc5e18c7a8..3941bb9998 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/AddIdentity.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/AddIdentity.java @@ -98,9 +98,6 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad MediaType.APPLICATION_JSON, COOKIENAME, new KernelAuthentication().getTokenByRole(testCaseDTO.getRole())).asString(), "response.uin"); - - testCaseName = isTestCaseValidForExecution(testCaseDTO); - DateFormat dateFormatter = new SimpleDateFormat("yyyyMMddHHmmss"); Calendar cal = Calendar.getInstance(); String timestampValue = dateFormatter.format(cal.getTime()); diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/DeleteWithParam.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/DeleteWithParam.java index 9f43988680..0d4f13f005 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/DeleteWithParam.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/DeleteWithParam.java @@ -82,7 +82,6 @@ public Object[] getTestCaseList(ITestContext context) { public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, AdminTestException { testCaseName = testCaseDTO.getTestCaseName(); testCaseName = ResidentUtil.isTestCaseValidForExecution(testCaseDTO); - testCaseName = isTestCaseValidForExecution(testCaseDTO); if (HealthChecker.signalTerminateExecution) { throw new SkipException( GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS); diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithParam.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithParam.java index a36d2d5406..b60d08addc 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithParam.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithParam.java @@ -84,7 +84,6 @@ public Object[] getTestCaseList(ITestContext context) { public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, AdminTestException { testCaseName = testCaseDTO.getTestCaseName(); testCaseName = ResidentUtil.isTestCaseValidForExecution(testCaseDTO); - testCaseName = isTestCaseValidForExecution(testCaseDTO); if (HealthChecker.signalTerminateExecution) { throw new SkipException( GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS); diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithParamForAutoGenId.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithParamForAutoGenId.java index ab07138383..5d9c72bc7d 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithParamForAutoGenId.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithParamForAutoGenId.java @@ -86,7 +86,6 @@ public Object[] getTestCaseList(ITestContext context) { public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, AdminTestException { testCaseName = testCaseDTO.getTestCaseName(); testCaseName = ResidentUtil.isTestCaseValidForExecution(testCaseDTO); - testCaseName = isTestCaseValidForExecution(testCaseDTO); if (HealthChecker.signalTerminateExecution) { throw new SkipException( GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS); diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithParamForDownloadCard.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithParamForDownloadCard.java index 83d60336c8..cdc5ed2135 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithParamForDownloadCard.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithParamForDownloadCard.java @@ -84,7 +84,6 @@ public Object[] getTestCaseList(ITestContext context) { public void test(TestCaseDTO testCaseDTO) throws AdminTestException { testCaseName = testCaseDTO.getTestCaseName(); testCaseName = ResidentUtil.isTestCaseValidForExecution(testCaseDTO); - testCaseName = isTestCaseValidForExecution(testCaseDTO); if (HealthChecker.signalTerminateExecution) { throw new SkipException(GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS); } diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithQueryParamForDownloadCard.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithQueryParamForDownloadCard.java index 363f353652..03d96e2716 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithQueryParamForDownloadCard.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/GetWithQueryParamForDownloadCard.java @@ -84,7 +84,6 @@ public Object[] getTestCaseList(ITestContext context) { public void test(TestCaseDTO testCaseDTO) throws Exception { testCaseName = testCaseDTO.getTestCaseName(); testCaseName = ResidentUtil.isTestCaseValidForExecution(testCaseDTO); - testCaseName = isTestCaseValidForExecution(testCaseDTO); if (HealthChecker.signalTerminateExecution) { throw new SkipException(GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS); } diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithAutogenIdWithOtpGenerate.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithAutogenIdWithOtpGenerate.java index f5ad0169ec..d468dbf9fd 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithAutogenIdWithOtpGenerate.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithAutogenIdWithOtpGenerate.java @@ -97,8 +97,6 @@ public void test(TestCaseDTO testCaseDTO) throw new SkipException(GlobalConstants.VID_FEATURE_NOT_SUPPORTED); } } - testCaseName = isTestCaseValidForExecution(testCaseDTO); - String inputJson = testCaseDTO.getInput().toString(); JSONObject req = new JSONObject(testCaseDTO.getInput()); diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithBodyWithOtpGenerate.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithBodyWithOtpGenerate.java index e7c3030a1d..33b2ea4715 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithBodyWithOtpGenerate.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithBodyWithOtpGenerate.java @@ -92,8 +92,6 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad throw new SkipException(GlobalConstants.VID_FEATURE_NOT_SUPPORTED); } } - - testCaseName = isTestCaseValidForExecution(testCaseDTO); auditLogCheck = testCaseDTO.isAuditLogCheck(); String tempUrl = ResidentConfigManager.getEsignetBaseUrl(); JSONObject req = new JSONObject(testCaseDTO.getInput()); diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithBodyWithPdfDownload.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithBodyWithPdfDownload.java index 10d884088d..31c231d0a7 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithBodyWithPdfDownload.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithBodyWithPdfDownload.java @@ -84,7 +84,6 @@ public Object[] getTestCaseList(ITestContext context) { public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, AdminTestException { testCaseName = testCaseDTO.getTestCaseName(); testCaseName = ResidentUtil.isTestCaseValidForExecution(testCaseDTO); - testCaseName = isTestCaseValidForExecution(testCaseDTO); if (HealthChecker.signalTerminateExecution) { throw new SkipException(GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS); } diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithOnlyPathParam.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithOnlyPathParam.java index acb7d04140..6c1881ddb1 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithOnlyPathParam.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithOnlyPathParam.java @@ -83,7 +83,6 @@ public Object[] getTestCaseList(ITestContext context) { public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, AdminTestException { testCaseName = testCaseDTO.getTestCaseName(); testCaseName = ResidentUtil.isTestCaseValidForExecution(testCaseDTO); - testCaseName = isTestCaseValidForExecution(testCaseDTO); String[] templateFields = testCaseDTO.getTemplateFields(); if (HealthChecker.signalTerminateExecution) { throw new SkipException( diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithParamAndFile.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithParamAndFile.java index 3afdb533c2..69b4396754 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithParamAndFile.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/PostWithParamAndFile.java @@ -84,7 +84,6 @@ public Object[] getTestCaseList(ITestContext context) { public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, AdminTestException { testCaseName = testCaseDTO.getTestCaseName(); testCaseName = ResidentUtil.isTestCaseValidForExecution(testCaseDTO); - testCaseName = isTestCaseValidForExecution(testCaseDTO); if (HealthChecker.signalTerminateExecution) { throw new SkipException( GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS); diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePatch.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePatch.java index 4bb643fc88..d2b405e03f 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePatch.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePatch.java @@ -83,7 +83,6 @@ public Object[] getTestCaseList(ITestContext context) { public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, AdminTestException { testCaseName = testCaseDTO.getTestCaseName(); testCaseName = ResidentUtil.isTestCaseValidForExecution(testCaseDTO); - testCaseName = isTestCaseValidForExecution(testCaseDTO); String[] templateFields = testCaseDTO.getTemplateFields(); if (HealthChecker.signalTerminateExecution) { throw new SkipException( diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePost.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePost.java index 78ed619e7f..35b32b72d3 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePost.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePost.java @@ -84,7 +84,6 @@ public Object[] getTestCaseList(ITestContext context) { public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, AdminTestException { testCaseName = testCaseDTO.getTestCaseName(); testCaseName = ResidentUtil.isTestCaseValidForExecution(testCaseDTO); - testCaseName = isTestCaseValidForExecution(testCaseDTO); auditLogCheck = testCaseDTO.isAuditLogCheck(); String[] templateFields = testCaseDTO.getTemplateFields(); if (HealthChecker.signalTerminateExecution) { diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenId.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenId.java index b9c389514b..d3cdccb315 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenId.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenId.java @@ -99,8 +99,6 @@ public void test(TestCaseDTO testCaseDTO) throw new SkipException(GlobalConstants.VID_FEATURE_NOT_SUPPORTED); } } - - testCaseName = isTestCaseValidForExecution(testCaseDTO); String[] templateFields = testCaseDTO.getTemplateFields(); String inputJson = ""; diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenIdForUrlEncoded.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenIdForUrlEncoded.java index d6b69db6fe..ee56dffef1 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenIdForUrlEncoded.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenIdForUrlEncoded.java @@ -100,7 +100,6 @@ public void test(TestCaseDTO testCaseDTO) if (ResidentConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) { throw new SkipException("esignet is not deployed hence skipping the testcase"); } - testCaseName = isTestCaseValidForExecution(testCaseDTO); String[] templateFields = testCaseDTO.getTemplateFields(); String inputJson = getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()); diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePut.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePut.java index eaa34101b3..a780301a62 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePut.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePut.java @@ -95,7 +95,6 @@ public void test(TestCaseDTO testCaseDTO) throws AdminTestException { } } - testCaseName = isTestCaseValidForExecution(testCaseDTO); String[] templateFields = testCaseDTO.getTemplateFields(); if (testCaseDTO.getTemplateFields() != null && templateFields.length > 0) { diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/utils/ResidentUtil.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/utils/ResidentUtil.java index 68dadcaae9..452529bed2 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/utils/ResidentUtil.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/utils/ResidentUtil.java @@ -5,7 +5,9 @@ import io.mosip.testrig.apirig.dto.TestCaseDTO; import io.mosip.testrig.apirig.resident.testrunner.MosipTestRunner; +import io.mosip.testrig.apirig.testrunner.BaseTestCase; import io.mosip.testrig.apirig.utils.AdminTestUtil; +import io.mosip.testrig.apirig.utils.ConfigManager; import io.mosip.testrig.apirig.utils.GlobalConstants; import io.mosip.testrig.apirig.utils.SkipTestCaseHandler; @@ -16,6 +18,11 @@ public class ResidentUtil extends AdminTestUtil { public static String isTestCaseValidForExecution(TestCaseDTO testCaseDTO) { String testCaseName = testCaseDTO.getTestCaseName(); + int indexof = testCaseName.indexOf("_"); + String modifiedTestCaseName = testCaseName.substring(indexof + 1); + + addTestCaseDetailsToMap(modifiedTestCaseName, testCaseDTO.getUniqueIdentifier()); + if (MosipTestRunner.skipAll == true) { throw new SkipException(GlobalConstants.PRE_REQUISITE_FAILED_MESSAGE); } @@ -23,6 +30,42 @@ public static String isTestCaseValidForExecution(TestCaseDTO testCaseDTO) { if (SkipTestCaseHandler.isTestCaseInSkippedList(testCaseName)) { throw new SkipException(GlobalConstants.KNOWN_ISSUES); } + + if ((ConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) + && BaseTestCase.currentModule.equalsIgnoreCase("resident") && testCaseName.contains("_SignJWT_")) { + throw new SkipException("esignet module is not deployed"); + } + + if ((ConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) + && BaseTestCase.currentModule.equalsIgnoreCase("resident") + && (testCaseDTO.getRole() != null && (testCaseDTO.getRole().equalsIgnoreCase("residentNew") + || testCaseDTO.getRole().equalsIgnoreCase("residentNewVid")))) { + throw new SkipException("esignet module is not deployed"); + } + if (BaseTestCase.currentModule.equalsIgnoreCase(GlobalConstants.RESIDENT)) { + if (testCaseDTO.getRole() != null && (testCaseDTO.getRole().equalsIgnoreCase(GlobalConstants.RESIDENTNEW) + || testCaseDTO.isValidityCheckRequired())) { + if (testCaseName.contains("uin") || testCaseName.contains("UIN") || testCaseName.contains("Uin")) { + if (BaseTestCase.getSupportedIdTypesValueFromActuator().contains("UIN") + && BaseTestCase.getSupportedIdTypesValueFromActuator().contains("uin")) { + throw new SkipException("Idtype UIN not supported skipping the testcase"); + } + } + } else if (testCaseDTO.getRole() != null && (testCaseDTO.getRole().equalsIgnoreCase("residentNewVid") + || testCaseDTO.isValidityCheckRequired())) { + if (testCaseName.contains("vid") || testCaseName.contains("VID") || testCaseName.contains("Vid")) { + if (BaseTestCase.getSupportedIdTypesValueFromActuator().contains("VID") + && BaseTestCase.getSupportedIdTypesValueFromActuator().contains("vid")) { + throw new SkipException("Idtype VID not supported skipping the testcase"); + } + } + } + } + + + + + return testCaseName; } From 36a4319552cf7dba0048bfc00c3599bf1bad853c Mon Sep 17 00:00:00 2001 From: Nandhukumar Date: Wed, 4 Dec 2024 01:02:40 +0530 Subject: [PATCH 2/5] MOSIP-35404 Signed-off-by: Nandhukumar --- .../apirig/resident/utils/ResidentUtil.java | 149 +++++++++++++++++- 1 file changed, 145 insertions(+), 4 deletions(-) diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/utils/ResidentUtil.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/utils/ResidentUtil.java index 452529bed2..e940e6e250 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/utils/ResidentUtil.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/utils/ResidentUtil.java @@ -1,20 +1,30 @@ package io.mosip.testrig.apirig.resident.utils; +import java.time.Instant; + +import javax.ws.rs.core.MediaType; + import org.apache.log4j.Logger; +import org.json.JSONArray; +import org.json.JSONObject; import org.testng.SkipException; import io.mosip.testrig.apirig.dto.TestCaseDTO; import io.mosip.testrig.apirig.resident.testrunner.MosipTestRunner; import io.mosip.testrig.apirig.testrunner.BaseTestCase; import io.mosip.testrig.apirig.utils.AdminTestUtil; -import io.mosip.testrig.apirig.utils.ConfigManager; import io.mosip.testrig.apirig.utils.GlobalConstants; +import io.mosip.testrig.apirig.utils.GlobalMethods; +import io.mosip.testrig.apirig.utils.RestClient; import io.mosip.testrig.apirig.utils.SkipTestCaseHandler; +import io.restassured.response.Response; public class ResidentUtil extends AdminTestUtil { private static final Logger logger = Logger.getLogger(ResidentUtil.class); + protected static final String ESIGNET_PAYLOAD = "config/esignetPayload.json"; + public static String isTestCaseValidForExecution(TestCaseDTO testCaseDTO) { String testCaseName = testCaseDTO.getTestCaseName(); @@ -31,12 +41,12 @@ public static String isTestCaseValidForExecution(TestCaseDTO testCaseDTO) { throw new SkipException(GlobalConstants.KNOWN_ISSUES); } - if ((ConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) + if ((ResidentConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) && BaseTestCase.currentModule.equalsIgnoreCase("resident") && testCaseName.contains("_SignJWT_")) { throw new SkipException("esignet module is not deployed"); } - if ((ConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) + if ((ResidentConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) && BaseTestCase.currentModule.equalsIgnoreCase("resident") && (testCaseDTO.getRole() != null && (testCaseDTO.getRole().equalsIgnoreCase("residentNew") || testCaseDTO.getRole().equalsIgnoreCase("residentNewVid")))) { @@ -62,11 +72,142 @@ public static String isTestCaseValidForExecution(TestCaseDTO testCaseDTO) { } } + return testCaseName; + } + + public static String inputstringKeyWordHandeler(String jsonString, String testCaseName) { + if (jsonString.contains(GlobalConstants.TIMESTAMP)) { + jsonString = replaceKeywordValue(jsonString, GlobalConstants.TIMESTAMP, generateCurrentUTCTimeStamp()); + } + + if (jsonString.contains("$CLAIMSFROMCONFIG$")) { + jsonString = replaceKeywordValue(jsonString, "$CLAIMSFROMCONFIG$", getValueFromConfigActuator()); + } + + if (jsonString.contains("$OIDCCLIENT$")) { + jsonString = replaceKeywordValue(jsonString, "$OIDCCLIENT$", + getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, "mosip.iam.module.clientID")); + } + if (jsonString.contains("$IDPCLIENTPAYLOAD$")) { + String clientId = getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, + "mosip.iam.module.clientID"); + String esignetBaseURI = getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, + "mosip.iam.token_endpoint"); + int idTokenExpirySecs = Integer + .parseInt(getValueFromEsignetActuator(ResidentConfigManager.getEsignetActuatorPropertySection(), + GlobalConstants.MOSIP_ESIGNET_ID_TOKEN_EXPIRE_SECONDS)); + + Instant instant = Instant.now(); + + logger.info("Current Instant: " + instant); + + long epochValue = instant.getEpochSecond(); + + org.json.simple.JSONObject payloadBody = getRequestJson(ESIGNET_PAYLOAD); + payloadBody.put("sub", clientId); + payloadBody.put("iss", clientId); + payloadBody.put("aud", esignetBaseURI); + payloadBody.put("exp", epochValue + idTokenExpirySecs); + payloadBody.put("iat", epochValue); + + jsonString = replaceKeywordValue(jsonString, "$IDPCLIENTPAYLOAD$", + encodeBase64(payloadBody.toString())); + } + return jsonString; - return testCaseName; + } + + public static String replaceKeywordValue(String jsonString, String keyword, String value) { + if (value != null && !value.isEmpty()) + return jsonString.replace(keyword, value); + else + throw new SkipException("Marking testcase as skipped as required fields are empty " + keyword); + } + + public static JSONArray esignetActuatorResponseArray = null; + + public static String getValueFromEsignetActuator(String section, String key) { + String url = ResidentConfigManager.getEsignetBaseUrl() + ResidentConfigManager.getproperty("actuatorEsignetEndpoint"); + String actuatorCacheKey = url + section + key; + String value = actuatorValueCache.get(actuatorCacheKey); + if (value != null && !value.isEmpty()) + return value; + + try { + if (esignetActuatorResponseArray == null) { + Response response = null; + JSONObject responseJson = null; + response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON); + responseJson = new JSONObject(response.getBody().asString()); + esignetActuatorResponseArray = responseJson.getJSONArray("propertySources"); + } + + for (int i = 0, size = esignetActuatorResponseArray.length(); i < size; i++) { + JSONObject eachJson = esignetActuatorResponseArray.getJSONObject(i); + if (eachJson.get("name").toString().contains(section)) { + value = eachJson.getJSONObject(GlobalConstants.PROPERTIES).getJSONObject(key) + .get(GlobalConstants.VALUE).toString(); + if (ResidentConfigManager.IsDebugEnabled()) + logger.info("Actuator: " + url + " key: " + key + " value: " + value); + break; + } + } + actuatorValueCache.put(actuatorCacheKey, value); + + return value; + } catch (Exception e) { + logger.error(GlobalConstants.EXCEPTION_STRING_2 + e); + return value; + } + + } + + public static JSONArray configActuatorResponseArray = null; + + public static String getValueFromConfigActuator() { + + String url = ApplnURI + ResidentConfigManager.getproperty("actuatorEndpoint"); + + String actuatorCacheKey = url + "mosip.iam.module.login_flow.claims"; + + String claims = actuatorValueCache.get(actuatorCacheKey); + + if (claims != null && !claims.isEmpty()) + return claims; + + try { + if (configActuatorResponseArray == null) { + Response response = null; + JSONObject responseJson = null; + response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON); + GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response); + + responseJson = new JSONObject(response.getBody().asString()); + configActuatorResponseArray = responseJson.getJSONArray("propertySources"); + } + + for (int i = 0, size = configActuatorResponseArray.length(); i < size; i++) { + JSONObject eachJson = configActuatorResponseArray.getJSONObject(i); + if (eachJson.get("name").toString().contains(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES)) { + String claimVal = eachJson.getJSONObject(GlobalConstants.PROPERTIES) + .getJSONObject("mosip.iam.module.login_flow.claims").getString(GlobalConstants.VALUE); + JSONObject claimJson = new JSONObject(claimVal); + claims = claimJson.getJSONObject("userinfo").toString(); + break; + } + } + + actuatorValueCache.put(actuatorCacheKey, claims); + + return claims; + } catch (Exception e) { + logger.error(GlobalConstants.EXCEPTION_STRING_2 + e); + return claims; + } + } } \ No newline at end of file From 759e4e76ee46da55be1476a419b295d7b77fc22d Mon Sep 17 00:00:00 2001 From: Nandhukumar Date: Fri, 3 Jan 2025 14:01:51 +0530 Subject: [PATCH 3/5] MOSIP-35404 Signed-off-by: Nandhukumar --- .../apirig/resident/testscripts/SimplePostForAutoGenId.java | 2 ++ .../testscripts/SimplePostForAutoGenIdForUrlEncoded.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenId.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenId.java index d3cdccb315..fc6981ad14 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenId.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenId.java @@ -103,6 +103,8 @@ public void test(TestCaseDTO testCaseDTO) String inputJson = ""; inputJson = getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()); + + inputJson = ResidentUtil.inputstringKeyWordHandeler(inputJson, testCaseName); String outputJson = getJsonFromTemplate(testCaseDTO.getOutput(), testCaseDTO.getOutputTemplate()); diff --git a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenIdForUrlEncoded.java b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenIdForUrlEncoded.java index ee56dffef1..bf0d11037e 100644 --- a/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenIdForUrlEncoded.java +++ b/api-test/src/main/java/io/mosip/testrig/apirig/resident/testscripts/SimplePostForAutoGenIdForUrlEncoded.java @@ -104,6 +104,8 @@ public void test(TestCaseDTO testCaseDTO) String inputJson = getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()); String outputJson = getJsonFromTemplate(testCaseDTO.getOutput(), testCaseDTO.getOutputTemplate()); + + inputJson = ResidentUtil.inputstringKeyWordHandeler(inputJson, testCaseName); String jsonInput = inputJsonKeyWordHandeler(inputJson, testCaseName); From 5280cad41bc82c5f7153292529c198b9eb41e6f4 Mon Sep 17 00:00:00 2001 From: Nandhukumar Date: Mon, 6 Jan 2025 16:04:36 +0530 Subject: [PATCH 4/5] MOSIP-35404 Signed-off-by: Nandhukumar --- api-test/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-test/pom.xml b/api-test/pom.xml index 642167627e..8e3502e89c 100644 --- a/api-test/pom.xml +++ b/api-test/pom.xml @@ -54,7 +54,7 @@ - io.mosip.testrig.apirig.apitest.commons + io.mosip.testrig.apitest.commons apitest-commons 1.2.2-cleanup-SNAPSHOT From 3a2c754aa7ebefef73c8de0fb7451829a89e6f0b Mon Sep 17 00:00:00 2001 From: Nandhukumar Date: Wed, 8 Jan 2025 13:34:00 +0530 Subject: [PATCH 5/5] MOSIP-35404 Signed-off-by: Nandhukumar --- api-test/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api-test/pom.xml b/api-test/pom.xml index 8e3502e89c..48a68a5dbd 100644 --- a/api-test/pom.xml +++ b/api-test/pom.xml @@ -8,7 +8,7 @@ apitest-resident Parent project of MOSIP Resident Services apitests https://github.com/mosip/resident-services - 1.2.1-cleanup-SNAPSHOT + 1.2.1-SNAPSHOT @@ -49,14 +49,14 @@ 2.2.1 3.0.1 - apitest-resident-1.2.1-cleanup-SNAPSHOT-jar-with-dependencies + apitest-resident-1.2.1-SNAPSHOT-jar-with-dependencies io.mosip.testrig.apitest.commons apitest-commons - 1.2.2-cleanup-SNAPSHOT + 1.3.1-SNAPSHOT