Skip to content

Commit

Permalink
Merged develop to release 1201
Browse files Browse the repository at this point in the history
Signed-off-by: Sohan Kumar Dey <[email protected]>
  • Loading branch information
Sohandey committed Oct 16, 2023
2 parents 4a81d10 + a18600b commit 8ef273c
Show file tree
Hide file tree
Showing 87 changed files with 1,937 additions and 486 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/automationtests-push-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ jobs:
OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
27 changes: 2 additions & 25 deletions automationtests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -574,31 +574,8 @@
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
</plugin>

<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>io.mosip.testrunner.MosipTestRunner</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin> -->


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public class AdminTestUtil extends BaseTestCase {
+ "config/healthCheckEndpoint.properties";
private static String serverComponentsCommitDetails;

String token = null;
protected static String token = null;
String idToken = null;
String adminAutoGeneratedIdPropFileName = properties.getProperty("adminAutoGeneratedIdPropFileName");
String masterDataAutoGeneratedIdPropFileName = properties.getProperty("masterDataAutoGeneratedIdPropFileName");
Expand Down Expand Up @@ -438,6 +438,26 @@ protected Response postWithBodyAndCookieWithText(String url, String jsonInput, S
return response;
}
}

protected Response postWithBodyAndCookieWithoutBody(String url, String jsonInput, String cookieName, String role,
String testCaseName) {
Response response = null;
jsonInput= null;
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
url = uriKeyWordHandelerUri(url, testCaseName);
token = kernelAuthLib.getTokenByRole(role);
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(null, inputJson);
try {
response = RestClient.postRequestWithCookie(url, inputJson, MediaType.APPLICATION_JSON, "*/*", cookieName,
token);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
return response;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}

protected Response postRequestWithCookieAuthHeaderAndXsrfToken(String url, String jsonInput, String cookieName,
String testCaseName) {
Expand Down Expand Up @@ -742,15 +762,42 @@ protected Response postRequestWithAuthHeaderAndSignatureForOtp(String url, Strin
url = uriKeyWordHandelerUri(url, testCaseName);
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(headers.toString(), inputJson);

try {
response = RestClient.postRequestWithMultipleHeaders(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token, headers);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
return response;

} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
return response;

}



protected Response postRequestWithAuthHeaderAndSignatureForOtpAutoGenId(String url, String jsonInput, String cookieName,
String token, Map<String, String> headers, String testCaseName,String idKeyName) {
Response response = null;
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
url = uriKeyWordHandelerUri(url, testCaseName);
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(headers.toString(), inputJson);

try {
response = RestClient.postRequestWithMultipleHeaders(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token, headers);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);

if (testCaseName.toLowerCase().contains("_sid")) {
writeAutoGeneratedId(response, idKeyName, testCaseName);
}
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
}
return response;

}

protected Response patchRequestWithCookieAuthHeaderAndSignature(String url, String jsonInput, String cookieName,
Expand Down Expand Up @@ -2265,9 +2312,27 @@ public static void closeFileReader(FileReader fileReader) {
}
}

String getPartnerId(org.json.JSONArray responseArray, String active, String partnertype) {
String partnerId = "";
String partnerStatus = "";
String partnerType = "";

for (int i = 0; i < responseArray.length(); i++) {
partnerStatus = responseArray.getJSONObject(i).getString("status");
partnerType = responseArray.getJSONObject(i).getString("partnerType");
if (partnerStatus != null && partnerStatus.equalsIgnoreCase(active)) {
if (partnerType != null && partnerType.equalsIgnoreCase(partnertype)) {
partnerId = responseArray.getJSONObject(i).getString("partnerID");
break;
}
}
}
return partnerId;
}
void writeAutoGeneratedId(Response response, String idKeyName, String testCaseName) {
String fileName = getAutoGenIdFileName(testCaseName);
JSONObject responseJson = null;

JSONObject responseBody = null;
String signature = null;
FileOutputStream outputStream = null;
Expand All @@ -2292,6 +2357,11 @@ void writeAutoGeneratedId(Response response, String idKeyName, String testCaseNa
String identifierKeyName = getAutogenIdKeyName(testCaseName, filedName);
if (responseJson.has(filedName))
props.put(identifierKeyName, responseJson.get(filedName).toString());
else if(responseJson.has("partners")) {
org.json.JSONArray responseArray = responseJson.getJSONArray("partners");
String authPartnerId = getPartnerId (responseArray,"active","Auth_Partner");
props.put(identifierKeyName, authPartnerId);
}
else if (responseJson.has("data")) {
org.json.JSONArray responseArray = responseJson.getJSONArray("data");

Expand Down Expand Up @@ -2968,7 +3038,7 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {
jsonString = replaceKeywordWithValue(jsonString, "$PUBLICKEYFORBINDING$",
MosipTestRunner.generatePublicKeyForMimoto());
}
if (jsonString.contains(GlobalConstants.PARTNER_ID)) {
if (jsonString.contains("$BLOCKEDPARTNERID$")) {
jsonString = replaceKeywordWithValue(jsonString, GlobalConstants.PARTNER_ID, getPartnerId());
}
if (jsonString.contains("$APIKEY$")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public class TestCaseDTO {
private boolean validityCheckRequired;
private boolean auditLogCheck;
private boolean checkErrorsOnlyInResponse;
private String allowedErrorCodes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -457,27 +457,36 @@ else if (!actualMap.get(entry.getKey()).equals(entry.getValue())) {
return true;
}

public static Map<String, List<OutputValidationDto>> doJsonOutputValidation(String actualOutputJson,
String expOutputJson, boolean checkErrorsOnlyInResponse, String allowedErrorCode) throws AdminTestException {
return doJsonOutputValidation(actualOutputJson,
expOutputJson, checkErrorsOnlyInResponse, "expected vs actual", doesResponseHasErrors(actualOutputJson), allowedErrorCode);
}

public static Map<String, List<OutputValidationDto>> doJsonOutputValidation(String actualOutputJson,
String expOutputJson, boolean checkErrorsOnlyInResponse) throws AdminTestException {
return doJsonOutputValidation(actualOutputJson,
expOutputJson, checkErrorsOnlyInResponse, "expected vs actual", doesResponseHasErrors(actualOutputJson));
expOutputJson, checkErrorsOnlyInResponse, "expected vs actual", doesResponseHasErrors(actualOutputJson), null);
}


public static Map<String, List<OutputValidationDto>> doJsonOutputValidation(String actualOutputJson,
String expOutputJson, boolean checkErrorsOnlyInResponse, String context, boolean responseHasErrors) throws AdminTestException {
String expOutputJson, boolean checkErrorsOnlyInResponse, String context, boolean responseHasErrors, String allowedErrorCode) throws AdminTestException {
if (doesResponseHasErrorCode(actualOutputJson, 500))
throw new AdminTestException("Internal Server Error. Hence marking the test case as failed");
if (doesResponseHasErrorCode(actualOutputJson, 404))
else if (doesResponseHasErrorCode(actualOutputJson, 404))
throw new AdminTestException("Page not found. Hence marking the test case as failed");
else if (doesResponseHasErrorCode(actualOutputJson, allowedErrorCode))
return Collections.emptyMap();
JsonPrecondtion jsonPrecondtion = new JsonPrecondtion();
Map<String, String> actual = jsonPrecondtion.retrieveMappingAndItsValueToPerformJsonOutputValidation(actualOutputJson);
Map<String, String> exp = jsonPrecondtion.retrieveMappingAndItsValueToPerformJsonOutputValidation(expOutputJson);

return doJsonOutputValidation(actual, exp, checkErrorsOnlyInResponse, context, responseHasErrors);
return doJsonOutputValidation(actual, exp, checkErrorsOnlyInResponse, context, responseHasErrors, allowedErrorCode);
}

public static Map<String, List<OutputValidationDto>> doJsonOutputValidation(Map<String, String> actualOutput,
Map<String, String> expOutput, boolean checkErrorsOnlyInResponse, String context, boolean responseHasErrors) throws AdminTestException {
Map<String, String> expOutput, boolean checkErrorsOnlyInResponse, String context, boolean responseHasErrors, String allowedErrorCode ) throws AdminTestException {
try {
return compareActuExpValue(actualOutput, expOutput, context);
}catch (SkipException e) {
Expand Down Expand Up @@ -518,4 +527,18 @@ public static boolean doesResponseHasErrorCode(String responseString, int errorC
return false;
}

public static boolean doesResponseHasErrorCode(String responseString, String allowedErrorCode) {
boolean responseHasAllowedErrorCode = false;
if (allowedErrorCode != null) {
String[] allowedErrorCodeList = allowedErrorCode.split(",");
for (int i = 0; i < allowedErrorCodeList.length; i++) {
if (responseString.contains(allowedErrorCodeList[i])) {
responseHasAllowedErrorCode = true;
break;
}
}
}
return responseHasAllowedErrorCode;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static String getOutputValidationReport(Map<String, List<OutputValidation
*/
public static String getTextAreaJsonMsgHtml(String content) {
StringBuilder sb = new StringBuilder();
sb.append("<div> <textarea style='border:solid 1px white;' name='message' rows='20' cols='160' readonly='true'>");
sb.append("<div> <textarea style='border:solid 1px white;' name='message' rows='10' cols='160' readonly='true'>");
try {
sb.append(JsonPrecondtion.toPrettyFormat(content));
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import java.security.NoSuchAlgorithmException;

import org.apache.log4j.Logger;
import org.json.simple.JSONObject;
import org.testng.Reporter;

import com.google.gson.JsonObject;

import io.mosip.testrig.apirig.admin.fw.util.AdminTestUtil;
import io.mosip.testrig.apirig.authentication.fw.util.ReportUtil;
import io.restassured.response.Response;
Expand All @@ -23,7 +26,7 @@ public static void reportRequest(String requestHeader, String request) {

String formattedHeader = ReportUtil.getTextAreaForHeaders(requestHeader);

if (request != null)
if (request != null && !request.equals("{}"))
Reporter.log(GlobalConstants.REPORT_REQUEST_PREFIX + formattedHeader + ReportUtil.getTextAreaJsonMsgHtml(request)
+ GlobalConstants.REPORT_REQUEST_SUFFIX);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ public class ConfigManager {
private static String MOSIP_REG_CLIENT_SECRET = "mosip_reg_client_secret";
private static String MOSIP_REG_CLIENT_ID = "mosip_reg_client_id";
private static String MOSIP_REGCLIENT_APP_ID = "mosip_regclient_app_id";


private static String MOSIP_REGPROC_CLIENT_SECRET = "mosip_regproc_client_secret";
private static String MOSIP_REGPROC_CLIENT_ID = "mosip_regproc_client_id";
private static String MOSIP_REGPROC_APP_ID = "mosip_regprocclient_app_id";

private static String MOSIP_IDA_CLIENT_SECRET = "mosip_ida_client_secret";
private static String MOSIP_IDA_CLIENT_ID = "mosip_ida_client_id";
private static String MOSIP_IDA_APP_ID = "mosip_ida_app_id";
Expand All @@ -64,7 +68,6 @@ public class ConfigManager {
private static String THREAD_COUNT = "threadCount";
private static String LANG_SELECT = "langselect";


private static String USEPRECONFIGOTP = "usePreConfiguredOtp";
private static String ESIGNET_BASE_URL = "eSignetbaseurl";

Expand Down Expand Up @@ -151,6 +154,10 @@ public class ConfigManager {
private static String regproc_client_secret;
private static String regproc_client_id;
private static String regproc_app_id;

private static String regprocessor_client_secret;
private static String regprocessor_client_id;
private static String regprocessor_app_id;

private static String ida_client_secret;
private static String ida_client_id;
Expand Down Expand Up @@ -253,9 +260,15 @@ public static void init() {
admin_client_secret = getValueForKey(MOSIP_ADMIN_CLIENT_SECRET);
admin_client_id = getValueForKey(MOSIP_ADMIN_CLIENT_ID);
admin_app_id = getValueForKey(MOSIP_ADMIN_APP_ID);

regproc_client_secret = getValueForKey(MOSIP_REG_CLIENT_SECRET);
regproc_client_id = getValueForKey(MOSIP_REG_CLIENT_ID);
regproc_app_id = getValueForKey(MOSIP_REGCLIENT_APP_ID);

regprocessor_client_secret = getValueForKey(MOSIP_REGPROC_CLIENT_SECRET);
regprocessor_client_id = getValueForKey(MOSIP_REGPROC_CLIENT_ID);
regprocessor_app_id = getValueForKey(MOSIP_REGPROC_APP_ID);

ida_client_secret = getValueForKey(MOSIP_IDA_CLIENT_SECRET);
ida_client_id = getValueForKey(MOSIP_IDA_CLIENT_ID);
ida_app_id = getValueForKey(MOSIP_IDA_APP_ID);
Expand Down Expand Up @@ -558,6 +571,18 @@ public static String getRegprocClientId() {
public static String getRegprocAppId() {
return regproc_app_id;
}

public static String getRegprocessorClientSecret() {
return regprocessor_client_secret;
}

public static String getRegprocessorClientId() {
return regprocessor_client_id;
}

public static String getRegprocessorAppId() {
return regprocessor_app_id;
}

public static String getIdaClientSecret() {
return ida_client_secret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ public String getAuthForRegProc() {

JSONObject actualrequest = getRequestJson(authRequest);
JSONObject request = new JSONObject();
request.put(GlobalConstants.APPID, "regproc");
request.put(GlobalConstants.CLIENTID, "mosip-regproc-client");
request.put(GlobalConstants.SECRETKEY, "abc123");
request.put(GlobalConstants.APPID, ConfigManager.getRegprocessorAppId());
request.put(GlobalConstants.CLIENTID, ConfigManager.getRegprocessorClientId());
request.put(GlobalConstants.SECRETKEY, ConfigManager.getRegprocessorClientSecret());
actualrequest.put(GlobalConstants.REQUEST, request);

Response reponse = appl.postWithJson(props.get(GlobalConstants.AUTH_CLIENT_IDSECRET_KEYURL), actualrequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad

Map<String, List<OutputValidationDto>> ouputValid = OutputValidationUtil.doJsonOutputValidation(
response.asString(),
getJsonFromTemplate(outputtestcase.get(i).toString(), testCaseDTO.getOutputTemplate()), testCaseDTO.isCheckErrorsOnlyInResponse());
getJsonFromTemplate(outputtestcase.get(i).toString(), testCaseDTO.getOutputTemplate()), testCaseDTO.isCheckErrorsOnlyInResponse(), testCaseDTO.getAllowedErrorCodes());
Reporter.log(ReportUtil.getOutputValidationReport(ouputValid));

if (!OutputValidationUtil.publishOutputResult(ouputValid))
Expand Down Expand Up @@ -141,7 +141,7 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
ouputValid.put("expected vs actual", List.of(customResponse));
}else {
ouputValid = OutputValidationUtil.doJsonOutputValidation(
response.asString(), getJsonFromTemplate(testCaseDTO.getOutput(), testCaseDTO.getOutputTemplate()), testCaseDTO.isCheckErrorsOnlyInResponse());
response.asString(), getJsonFromTemplate(testCaseDTO.getOutput(), testCaseDTO.getOutputTemplate()), testCaseDTO.isCheckErrorsOnlyInResponse(), testCaseDTO.getAllowedErrorCodes());
}

Reporter.log(ReportUtil.getOutputValidationReport(ouputValid));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void test(TestCaseDTO testCaseDTO)
ouputValid.put("expected vs actual", List.of(customResponse));
}else {
ouputValid = OutputValidationUtil.doJsonOutputValidation(
response.asString(), getJsonFromTemplate(testCaseDTO.getOutput(), testCaseDTO.getOutputTemplate()), testCaseDTO.isCheckErrorsOnlyInResponse());
response.asString(), getJsonFromTemplate(testCaseDTO.getOutput(), testCaseDTO.getOutputTemplate()), testCaseDTO.isCheckErrorsOnlyInResponse(), testCaseDTO.getAllowedErrorCodes());
}
Reporter.log(ReportUtil.getOutputValidationReport(ouputValid));
if (!OutputValidationUtil.publishOutputResult(ouputValid))
Expand Down
Loading

0 comments on commit 8ef273c

Please sign in to comment.