Skip to content

Commit

Permalink
MOSIP-39218 (#1144)
Browse files Browse the repository at this point in the history
Signed-off-by: Nandhukumar <[email protected]>
  • Loading branch information
nandhu-kumar authored Jan 27, 2025
1 parent d243ce1 commit 38725e0
Show file tree
Hide file tree
Showing 36 changed files with 1,326 additions and 301 deletions.
2 changes: 1 addition & 1 deletion api-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<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
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ public static void main(String[] arg) {


if (EsignetUtil.getIdentityPluginNameFromEsignetActuator().toLowerCase().contains("mockauthenticationservice") == false
&& EsignetUtil.getIdentityPluginNameFromEsignetActuator().toLowerCase().contains("sunbird") == false) {
&& EsignetUtil.getIdentityPluginNameFromEsignetActuator().toLowerCase().contains("sunbirdrcauthenticationservice") == false) {
KeycloakUserManager.removeUser();
KeycloakUserManager.createUsers();
KeycloakUserManager.closeKeycloakInstance();
AdminTestUtil.getRequiredField();

List<String> localLanguageList = new ArrayList<>(BaseTestCase.getLanguageList());
AdminTestUtil.getLocationData();
Expand Down Expand Up @@ -198,34 +199,15 @@ public static void startTestRunner() {
homeDir = new File(dir.getParent() + "/mosip/testNgXmlFiles");
LOGGER.info("ELSE :" + homeDir);
}
// List and sort the files
File[] files = homeDir.listFiles();
if (files != null) {
Arrays.sort(files, (f1, f2) -> {
// Customize the comparison based on file names
if (f1.getName().toLowerCase().contains("prerequisite")) {
return -1; // f1 should come before f2
} else if (f2.getName().toLowerCase().contains("prerequisite")) {
return 1; // f2 comes before f1
}
return f1.getName().compareTo(f2.getName()); // default alphabetical order
});

for (File file : files) {
TestNG runner = new TestNG();
List<String> suitefiles = new ArrayList<>();

if (file.getName().toLowerCase().contains(GlobalConstants.ESIGNET)) {
if (file.getName().toLowerCase().contains("prerequisite")) {
BaseTestCase.setReportName(GlobalConstants.ESIGNET + "-prerequisite");
} else {
// if the prerequisite total skipped/failed count is greater than zero
if (EmailableReport.getFailedCount() > 0 || EmailableReport.getSkippedCount() > 0) {
// skipAll = true;
}

BaseTestCase.setReportName(GlobalConstants.ESIGNET);
}
if (file.getName().toLowerCase().contains("mastertestsuite")) {
BaseTestCase.setReportName(GlobalConstants.ESIGNET);
suitefiles.add(file.getAbsolutePath());
runner.setTestSuites(suitefiles);
System.getProperties().setProperty("testng.outpur.dir", "testng-report");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ public void test(TestCaseDTO testCaseDTO) throws Exception {
inputJson = replaceKeywordWithValue(inputJson, "$PHONENUMBERFORIDENTITY$", phoneNumber);
inputJson = replaceKeywordWithValue(inputJson, "$EMAILVALUE$", email);
}

inputJson = EsignetUtil.inputstringKeyWordHandeler(inputJson, testCaseName);

response = postWithBodyAndCookie(ApplnURI + testCaseDTO.getEndPoint(), inputJson, COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
}

else {
String inputJson = getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate());

if (testCaseName.contains("ESignet_")) {
if (EsignetConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) {
Expand All @@ -119,20 +120,23 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
if (EsignetConfigManager.isInServiceNotDeployedList("sunbirdrc"))
throw new SkipException(GlobalConstants.SERVICE_NOT_DEPLOYED_MESSAGE);

if (EsignetConfigManager.getSunBirdBaseURL() != null && !EsignetConfigManager.getSunBirdBaseURL().isBlank())
if (EsignetConfigManager.getSunBirdBaseURL() != null
&& !EsignetConfigManager.getSunBirdBaseURL().isBlank())
tempUrl = EsignetConfigManager.getSunBirdBaseURL();
//Once sunbird registry is pointing to specific env, remove the above line and uncomment below line
//tempUrl = ApplnURI.replace(GlobalConstants.API_INTERNAL, ConfigManager.getSunBirdBaseURL());
// Once sunbird registry is pointing to specific env, remove the above line and
// uncomment below line
// tempUrl = ApplnURI.replace(GlobalConstants.API_INTERNAL,
// ConfigManager.getSunBirdBaseURL());
testCaseDTO.setEndPoint(testCaseDTO.getEndPoint().replace("$SUNBIRDBASEURL$", ""));
}
inputJson = EsignetUtil.inputstringKeyWordHandeler(inputJson, testCaseName);

response = deleteWithPathParamAndCookie(tempUrl + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), COOKIENAME,
response = deleteWithPathParamAndCookie(tempUrl + testCaseDTO.getEndPoint(), inputJson, COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());

} else {
response = deleteWithPathParamAndCookie(ApplnURI + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), COOKIENAME,
inputJson = EsignetUtil.inputstringKeyWordHandeler(inputJson, testCaseName);
response = deleteWithPathParamAndCookie(ApplnURI + testCaseDTO.getEndPoint(), inputJson, COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
}
Map<String, List<OutputValidationDto>> ouputValid = OutputValidationUtil.doJsonOutputValidation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
throw new SkipException(GlobalConstants.VID_FEATURE_NOT_SUPPORTED);
}
}
testCaseName = isTestCaseValidForExecution(testCaseDTO);

JSONObject request = new JSONObject(testCaseDTO.getInput());
String identityRequest = null;
String identityRequestTemplate = null;
Expand All @@ -126,7 +124,7 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
identityReqJson.remove("identityRequestEncUrl");

if (identityReqJson.has("transactionId")) {
String oidcTransactionId = AdminTestUtil.getAuthTransactionId(identityReqJson.getString("transactionId"));
String oidcTransactionId = EsignetUtil.getAuthTransactionId(identityReqJson.getString("transactionId"));
if (oidcTransactionId != null && !oidcTransactionId.isBlank())
identityReqJson.put("transactionId", oidcTransactionId);
}
Expand Down Expand Up @@ -166,6 +164,8 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
if (authRequest.contains("$CHALLENGE$")) {
authRequest = authRequest.replace("$CHALLENGE$", challengeValue);
}

authRequest = EsignetUtil.inputstringKeyWordHandeler(authRequest, testCaseName);
if (testCaseName.contains("ESignet_")) {
String tempUrl = EsignetConfigManager.getEsignetBaseUrl();
response = postRequestWithCookieAuthHeaderAndXsrfToken(tempUrl + testCaseDTO.getEndPoint(), authRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,35 +131,38 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
}

else {
String inputJson = getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate());

if (testCaseName.contains("ESignet_")) {
String tempUrl = EsignetConfigManager.getEsignetBaseUrl();
if (testCaseDTO.getEndPoint().contains("/signup/"))
tempUrl = EsignetConfigManager.getSignupBaseUrl();

if (testCaseDTO.getEndPoint().startsWith("$SUNBIRDBASEURL$") && testCaseName.contains("SunBirdR")) {

if (EsignetConfigManager.isInServiceNotDeployedList("sunbirdrc"))
throw new SkipException(GlobalConstants.SERVICE_NOT_DEPLOYED_MESSAGE);

if (EsignetConfigManager.getSunBirdBaseURL() != null && !EsignetConfigManager.getSunBirdBaseURL().isBlank())
if (EsignetConfigManager.getSunBirdBaseURL() != null
&& !EsignetConfigManager.getSunBirdBaseURL().isBlank())
tempUrl = EsignetConfigManager.getSunBirdBaseURL();
//Once sunbird registry is pointing to specific env, remove the above line and uncomment below line
//tempUrl = ApplnURI.replace(GlobalConstants.API_INTERNAL, ConfigManager.getSunBirdBaseURL());
// Once sunbird registry is pointing to specific env, remove the above line and
// uncomment below line
// tempUrl = ApplnURI.replace(GlobalConstants.API_INTERNAL,
// ConfigManager.getSunBirdBaseURL());
testCaseDTO.setEndPoint(testCaseDTO.getEndPoint().replace("$SUNBIRDBASEURL$", ""));
}

inputJson = EsignetUtil.inputstringKeyWordHandeler(inputJson, testCaseName);
if (testCaseName.contains("_AuthToken_Xsrf_")) {
response = getRequestWithCookieAuthHeaderAndXsrfToken(tempUrl + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
inputJson, COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
} else {
response = getWithPathParamAndCookie(tempUrl + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), COOKIENAME,
response = getWithPathParamAndCookie(tempUrl + testCaseDTO.getEndPoint(), inputJson, COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
}
} else {
response = getWithPathParamAndCookie(ApplnURI + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), auditLogCheck,
inputJson = EsignetUtil.inputstringKeyWordHandeler(inputJson, testCaseName);
response = getWithPathParamAndCookie(ApplnURI + testCaseDTO.getEndPoint(), inputJson, auditLogCheck,
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), sendEsignetToken);
}
Map<String, List<OutputValidationDto>> ouputValid = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
}

else {
String inputJson = getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate());
inputJson = EsignetUtil.inputstringKeyWordHandeler(inputJson, testCaseName);
if (testCaseName.contains("ESignet_")) {
String tempUrl = EsignetConfigManager.getEsignetBaseUrl();
response = getWithQueryParamAndCookie(tempUrl + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), COOKIENAME,
response = getWithQueryParamAndCookie(tempUrl + testCaseDTO.getEndPoint(), inputJson, COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
} else {
response = getWithQueryParamAndCookie(ApplnURI + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), COOKIENAME,
response = getWithQueryParamAndCookie(ApplnURI + testCaseDTO.getEndPoint(), inputJson, COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
}
Map<String, List<OutputValidationDto>> ouputValid = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
logger.info("******Post request Json to EndPointUrl: " + url + testCaseDTO.getEndPoint() + " *******");

Response authResponse = null;

input = EsignetUtil.inputstringKeyWordHandeler(input, testCaseName);

authResponse = postWithBodyAndCookieWithText(url + testCaseDTO.getEndPoint(), input, COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
Expand All @@ -141,6 +143,8 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
headers.put(COOKIENAME, token);

logger.info("******Post request Json to EndPointUrl: " + ApplnURI + testCaseDTO.getEndPoint() + " *******");

authResBody = EsignetUtil.inputstringKeyWordHandeler(authResBody, testCaseName);

response = postRequestWithAuthHeaderAndSignatureForOtp(ApplnURI + kycAuthEndPoint, authResBody, COOKIENAME,
token, headers, testCaseDTO.getTestCaseName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public void test(TestCaseDTO testCaseDTO) throws AdminTestException {

testCaseDTO = AdminTestUtil.filterHbs(testCaseDTO);
String inputJson = filterInputHbs(testCaseDTO);

inputJson = EsignetUtil.inputstringKeyWordHandeler(inputJson, testCaseName);

response = patchWithPathParamsBodyAndCookie(ApplnURI + testCaseDTO.getEndPoint(), inputJson, COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), pathParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,6 @@ public void test(TestCaseDTO testCaseDTO)
String inputJson = testCaseDTO.getInput().toString();
JSONObject req = new JSONObject(testCaseDTO.getInput());

if (inputJson.contains("$PHONENUMBERFROMREGEXFORSIGNUP$")) {
String phoneNumber = getPhoneNumber();
if (phoneNumber != null && !phoneNumber.isEmpty()) {
inputJson = replaceKeywordWithValue(inputJson, "$PHONENUMBERFROMREGEXFORSIGNUP$", phoneNumber);
req = new JSONObject(inputJson);
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "PHONE", phoneNumber);
}
}

auditLogCheck = testCaseDTO.isAuditLogCheck();
String otpRequest = null;
String sendOtpReqTemplate = null;
Expand All @@ -124,25 +115,26 @@ public void test(TestCaseDTO testCaseDTO)
otpReqJson.remove("sendOtpReqTemplate");
sendOtpEndPoint = otpReqJson.getString("sendOtpEndPoint");
otpReqJson.remove("sendOtpEndPoint");


String input = getJsonFromTemplate(otpReqJson.toString(), sendOtpReqTemplate);

Response otpResponse = null;
int maxLoopCount = Integer.parseInt(properties.getProperty("uinGenMaxLoopCount"));
int currLoopCount = 0;
while (currLoopCount < maxLoopCount) {
input = EsignetUtil.inputstringKeyWordHandeler(input, testCaseName);
if (testCaseName.contains(GlobalConstants.ESIGNET_)) {
if (EsignetConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) {
throw new SkipException("esignet is not deployed hence skipping the testcase");
}
String tempUrl = EsignetConfigManager.getEsignetBaseUrl();

if (testCaseDTO.getEndPoint().contains("/signup/"))
tempUrl = EsignetConfigManager.getSignupBaseUrl();
otpResponse = postRequestWithCookieAuthHeaderAndXsrfToken(tempUrl + sendOtpEndPoint,
getJsonFromTemplate(otpReqJson.toString(), sendOtpReqTemplate), COOKIENAME,
otpResponse = postRequestWithCookieAuthHeaderAndXsrfToken(tempUrl + sendOtpEndPoint, input, COOKIENAME,
testCaseDTO.getTestCaseName());
} else {
otpResponse = postWithBodyAndCookie(ApplnURI + sendOtpEndPoint,
getJsonFromTemplate(otpReqJson.toString(), sendOtpReqTemplate), COOKIENAME,
otpResponse = postWithBodyAndCookie(ApplnURI + sendOtpEndPoint, input, COOKIENAME,
GlobalConstants.RESIDENT, testCaseDTO.getTestCaseName());
}

Expand Down Expand Up @@ -194,6 +186,9 @@ public void test(TestCaseDTO testCaseDTO)
} else {
throw new AdminTestException("Invalid otp response");
}

String jsonInput = getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate());
jsonInput = EsignetUtil.inputstringKeyWordHandeler(jsonInput, testCaseName);

if (testCaseName.contains(GlobalConstants.ESIGNET_)) {
if (EsignetConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) {
Expand All @@ -204,18 +199,15 @@ public void test(TestCaseDTO testCaseDTO)
tempUrl = EsignetConfigManager.getSignupBaseUrl();
if (testCaseName.startsWith("ESignet_VerifyChallengeNegTC_")
|| testCaseName.startsWith("ESignet_VerifyChallengeForResetPasswordNegTC_")) {
response = postRequestWithCookieAuthHeaderAndXsrfToken(tempUrl + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), COOKIENAME,
testCaseDTO.getTestCaseName());
response = postRequestWithCookieAuthHeaderAndXsrfToken(tempUrl + testCaseDTO.getEndPoint(), jsonInput,
COOKIENAME, testCaseDTO.getTestCaseName());
} else {
response = postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(tempUrl + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), COOKIENAME,
testCaseDTO.getTestCaseName(), idKeyName);
jsonInput, COOKIENAME, testCaseDTO.getTestCaseName(), idKeyName);
}
} else {
response = postWithBodyAndCookieForAutoGeneratedId(ApplnURI + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), auditLogCheck,
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), idKeyName);
response = postWithBodyAndCookieForAutoGeneratedId(ApplnURI + testCaseDTO.getEndPoint(), jsonInput,
auditLogCheck, COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), idKeyName);
}

Map<String, List<OutputValidationDto>> ouputValid = OutputValidationUtil.doJsonOutputValidation(
Expand Down Expand Up @@ -252,7 +244,9 @@ public void setResultTestName(ITestResult result) {
public void waittime() {
try {
if (EsignetUtil.getIdentityPluginNameFromEsignetActuator().toLowerCase()
.contains("mockauthenticationservice") == false) {
.contains("mockauthenticationservice") == false
&& EsignetUtil.getIdentityPluginNameFromEsignetActuator().toLowerCase()
.contains("sunbirdrcauthenticationservice") == false) {
if (!testCaseName.contains(GlobalConstants.ESIGNET_)) {
long delayTime = Long.parseLong(properties.getProperty("Delaytime"));
logger.info("waiting for " + delayTime + " mili secs after VID Generation In RESIDENT SERVICES");
Expand Down
Loading

0 comments on commit 38725e0

Please sign in to comment.