Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions apitest-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -510,16 +510,6 @@
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>${central.publishing.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>ossrh</publishingServerId>
<autoPublish>false</autoPublish>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.HashMap;
import java.util.Map;

import io.mosip.testrig.apirig.testrunner.BaseTestCase;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
Expand Down Expand Up @@ -244,6 +245,7 @@ public void execute(Connection connection) throws SQLException {
while ((line = bufferedReader.readLine()) != null) {
if (line.trim().equals("") || line.trim().startsWith("#"))
continue;
line = line.replace("${currentModule}", BaseTestCase.currentModule);
statement.addBatch(line);
}
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public void generateOutputFile(boolean skipPassed) {
}

String oldString = System.getProperty(GlobalConstants.EMAILABLEREPORT2NAME);
// Remove unwanted random suffix (e.g., -5e9, -2b9, -abc123) before the module name
oldString = oldString.replaceAll("-[a-z0-9]{3,}(?=_)", "");
String temp = "";
String reportContext = skipPassed == true ? "error-" : "full-";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.log4j.PropertyConfigurator;
import org.json.JSONArray;
import org.json.simple.JSONObject;
import org.testng.ITestContext;
import org.testng.annotations.AfterSuite;

import com.aventstack.extentreports.ExtentReports;
Expand Down Expand Up @@ -162,8 +161,10 @@ public class BaseTestCase {
public String genPolicyNameNonAuth = "policyNameForEsignet" + generateRandomNumberString(4);
public String genMispPolicyName = "policyNameForMispEsi" + generateRandomNumberString(6)
+ generateRandomNumberString(3);
public static String genPartnerName = "partnernameforautomationesi-" + generateRandomNumberString(6);
public static String genPartnerNameNonAuth = "partnernameforesignet-" + generateRandomNumberString(6);
//public static String genPartnerName = "partnernameforautomationesi-" + generateRandomNumberString(6);
public static String genPartnerName = null;
//public static String genPartnerNameNonAuth = "partnernameforesignet-" + generateRandomNumberString(6);
public static String genPartnerNameNonAuth = BaseTestCase.currentModule + "-partnernameforesignet";
public String genPartnerNameForDsl = "partnernameforautomationdsl-" + generateRandomNumberString(6);
public static String genMispPartnerName = "esignet_" + generateRandomNumberString(6)
+ generateRandomNumberString(3);
Expand All @@ -187,6 +188,8 @@ public class BaseTestCase {

private static String runTypeS = "";
protected static String jarURLS = "";

public static String runContext = GlobalMethods.getRunContext();

public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
Expand All @@ -213,6 +216,10 @@ public static void init() {
* "@gmail.com"; static String role = PartnerRegistration.partnerType;
*/

public static void initializePMSDetails() {
genPartnerName = BaseTestCase.currentModule + "-partnernameforautomationesi";
}

public static String getGlobalResourcePath() {
if (cachedPath != null) {
return cachedPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ public static String getOtp(String emailId) {
logger.info("*******emailNotificationMapS value = " + emailNotificationMapS + " and emailId = " + emailId);
if (emailNotificationMapS.get(emailId) != null) {
String html = (String) emailNotificationMapS.get(emailId);
emailNotificationMapS.remove(emailId);
if(BaseTestCase.currentModule.equals(GlobalConstants.DSL)) {
emailNotificationMapS.remove(emailId);
} else {
emailNotificationMapS.clear();
}
otp = parseOtp(html);
if (otp != null && otp.length() > 0) {
logger.info("Found the OTP = " + otp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,15 @@ public class AdminTestUtil extends BaseTestCase {
protected static String preregHbsForCreate = null;
protected static String preregHbsForUpdate = null;
protected static String timeStamp = String.valueOf(Calendar.getInstance().getTimeInMillis());
protected static String policyGroup = "mosip auth policy group " + timeStamp;
protected static String policyGroup = "mosip auth policy group " + BaseTestCase.runContext + timeStamp;
protected static String mispPolicyGroup = "mosip misp policy group " + timeStamp;
protected static String policyGroupForUpdate = "mosip auth policy group update " + timeStamp;
protected static String policyGroup2 = "mosip auth policy group2 " + timeStamp;
protected static String policyName = "mosip auth policy " + timeStamp;
protected static String mispPolicyName = "mosip misp policy " + timeStamp;
protected static String policyName2 = "mosip auth policy2 " + timeStamp;
protected static String policyNameForUpdate = "mosip auth policy for update " + timeStamp;
protected static final String preRegUser = "Prereg_" + BaseTestCase.runContext +"@mosip.net";
protected static final String UPDATE_UIN_REQUEST = "config/Authorization/requestIdentity.json";
protected static final String AUTH_INTERNAL_REQUEST = "config/Authorization/internalAuthRequest.json";
protected static final String AUTH_POLICY_BODY = "config/AuthPolicy.json";
Expand Down Expand Up @@ -1440,7 +1441,6 @@ protected Response getWithPathParamAndCookieForAutoGeneratedId(String url, Strin
throws SecurityXSSException {
Response response = null;
jsonInput = inputJsonKeyWordHandeler(jsonInput, testCaseName);

if (bothAccessAndIdToken) {
token = kernelAuthLib.getTokenByRole(role, ACCESSTOKENCOOKIENAME);
idToken = kernelAuthLib.getTokenByRole(role, IDTOKENCOOKIENAME);
Expand Down Expand Up @@ -1521,7 +1521,7 @@ protected Response getWithPathParamAndCookieForAutoGeneratedId(String url, Strin
}
return response;
}

public static String encodeBase64(String value) {
String encodedStr;
try {
Expand Down Expand Up @@ -3783,6 +3783,23 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {
String.valueOf(hierarchyLevelWithLocationCode));
}

if (jsonString.contains("$PREREGUSER$")) {
jsonString = replaceKeywordWithValue(jsonString, "$PREREGUSER$", preRegUser);
}

if (jsonString.contains("$PHONENUMBER$")) {
try {
jsonString = replaceKeywordWithValue(jsonString, "$PHONENUMBER$", genStringAsperRegex(phoneSchemaRegex));
} catch (Exception e) {
throw new RuntimeException(e);
}
}

if (jsonString.contains("$EMAILVALUE$")) {
jsonString = replaceKeywordWithValue(jsonString, "$EMAILVALUE$",
BaseTestCase.currentModule + "_" + generateRandomAlphaNumericString(5) + "@mosip.com");
}

if (jsonString.contains("$CACERT$")) {
JSONObject request = new JSONObject(jsonString);
String partnerId = null;
Expand Down Expand Up @@ -4200,9 +4217,9 @@ protected static String replaceIdWithAutogeneratedId(String jsonString, String i
&& ConfigManager.getMockNotificationChannel().equalsIgnoreCase("phone")) {
String temp = idKey + keyForIdProperty + "$"; // $ID:AddIdentity_withValidParameters_smoke_Pos_EMAIL$
keyForIdProperty = keyForIdProperty.replace("_EMAIL", "_PHONE"); // AddIdentity_withValidParameters_smoke_Pos_PHONE
keyToReplace = temp; // $ID:AddIdentity_withValidParameters_smoke_Pos_PHONE$@phone
keyToReplace = temp;

jsonString = jsonString.replace(temp, temp + "@phone");
jsonString = jsonString.replace(temp, temp + "@phone");// $ID:AddIdentity_withValidParameters_smoke_Pos_PHONE$@phone

} else if (keyForIdProperty.endsWith("_PHONE")
&& ConfigManager.getMockNotificationChannel().equalsIgnoreCase("email")) {
Expand Down Expand Up @@ -5604,6 +5621,11 @@ public static String generateHbsForPrereg(boolean isItUpdate) {
phoneFieldAdditionallyAdded = true;
}

if (identityPropsJson.has(result)) {
phoneSchemaRegex = identityPropsJson.getJSONObject(result).getJSONArray("validators").getJSONObject(0)
.getString("validator");
}

// System.out.println("result is:" + result);
String email = getValueFromAuthActuator("json-property", "emailId");
String emailResult = email.replaceAll("\\[\"|\"\\]", "");
Expand Down Expand Up @@ -5672,7 +5694,11 @@ public static String generateHbsForPrereg(boolean isItUpdate) {

if (eachRequiredProp.equals("IDSchemaVersion")) {
identityJson.put(eachRequiredProp, schemaVersion);
} else {
} else if (eachRequiredProp.equals(emailResult)) {
identityJson.put(eachRequiredProp, "$EMAILVALUE$");
} else if (eachRequiredProp.equals(result)) {
identityJson.put(eachRequiredProp, "$PHONENUMBERFORIDENTITY$");
} else {
identityJson.put(eachRequiredProp, "{{" + eachRequiredProp + "}}");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ public static void main(String[] args) throws Exception {
System.out.println(getDependencies("TC_IDRepo_AuthInternalock_01"));
System.out.println(getDependencies("TC_IDRepo_AddIdentity_32"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -34,8 +35,10 @@ public class GlobalMethods {
// Compile the regex pattern
private static Pattern pattern_1 = Pattern.compile(regex_1);
private static Pattern pattern_2 = Pattern.compile(regex_2);

public static boolean isXSSProtectionCheckEnabled() {

public static String runContext = null;

public static boolean isXSSProtectionCheckEnabled() {
return ConfigManager.getproperty("xssProtectionCheck").equalsIgnoreCase("yes") ? true : false;
}

Expand Down Expand Up @@ -69,6 +72,13 @@ public static void setModuleNameAndReCompilePattern(String value) {
pattern_1 = Pattern.compile(regex_1);
pattern_2 = Pattern.compile(regex_2);
}

public static String getRunContext() {
// Generate a UUID, remove dashes,convert to lowercase, and take first 3 characters
runContext = UUID.randomUUID().toString().replaceAll("-", "").toLowerCase().substring(0, 3) + "_";
logger.info("RUN_CONTEXT set to: " + runContext);
return runContext;
}

public static void main(String[] arg) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,9 @@ public String getPreRegToken() {
actualRequest_generation.put(GlobalConstants.REQUESTTIME, AdminTestUtil.getCurrentUTCTime());
((JSONObject) actualRequest_generation.get(GlobalConstants.REQUEST)).put("langCode",
BaseTestCase.getLanguageList().get(0));
((JSONObject) actualRequest_generation.get(GlobalConstants.REQUEST)).get("userId").toString();
String userId = ((JSONObject) actualRequest_generation.get(GlobalConstants.REQUEST)).get("userId").toString();
String userId = AdminTestUtil.preRegUser;
((JSONObject) actualRequest_generation.get(GlobalConstants.REQUEST)).put("userId",
userId);
JSONObject actualRequest_validation = getRequestJson("config/prereg_ValidateOtp.json");
AdminTestUtil.postWithJson(preregSendOtp, actualRequest_generation);
String otp = null;
Expand All @@ -622,6 +623,8 @@ public String getPreRegToken() {
}
((JSONObject) actualRequest_validation.get(GlobalConstants.REQUEST)).put("otp", otp);
actualRequest_validation.put(GlobalConstants.REQUESTTIME, AdminTestUtil.getCurrentUTCTime());
((JSONObject) actualRequest_validation.get(GlobalConstants.REQUEST)).put("userId",
userId);
Response otpValidate = AdminTestUtil.postWithJson(preregValidateOtp, actualRequest_validation);
cookie = otpValidate.getCookie(GlobalConstants.AUTHORIZATION);
return cookie;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,10 @@ private static X500Name getCertificateAttributes(String cn, String organization)
public PrivateKeyEntry getKeyEntry(String dirPath, String parterId) throws NoSuchAlgorithmException, UnrecoverableEntryException,
KeyStoreException, CertificateException, IOException, OperatorCreationException {
String filePrepend = parterId;

String partnerFilePath = dirPath + '/' +PartnerRegistration.appendEkycOrRp.get()+ filePrepend + PARTNER_P12_FILE_NAME;;
logger.info("partnerFilePath : "+partnerFilePath);
return getPrivateKeyEntry(partnerFilePath);
logger.info("partnerFilePath : "+partnerFilePath);
return getPrivateKeyEntry(partnerFilePath);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public class PartnerRegistration extends AdminTestUtil {
public static String updatedApiKey = "";
public static String kycApiKey = "";
public static String mispLicKey ="";
public static final ThreadLocal<String> appendEkycOrRp = ThreadLocal.withInitial(() -> "");
public static String policyGroup = AdminTestUtil.policyGroup;
public static String policyGroupForKyc = AdminTestUtil.policyGroup2;
public static final ThreadLocal<String> appendEkycOrRp = ThreadLocal.withInitial(() -> "");

public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
Expand Down Expand Up @@ -402,7 +402,7 @@ public static void deviceGeneration() {
requestBody.put("organizationName", deviceOrganizationName);
requestBody.put(GlobalConstants.PARTNERID, deviceOrganizationName);
requestBody.put("partnerType", "Device_Provider");
requestBody.put("policyGroup", policyGroup);
// requestBody.put("policyGroup", policyGroup);

HashMap<String, Object> body = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1986,4 +1986,67 @@ public static Response postRequestWithFormDataBody(String url, Map<String, Strin

return postResponse;
}

public static Response postRequestWithFormDataBodyWithHeaders(String url, Map<String, String> formData,
Map<String, String> headers) {
Response postResponse = null;
url = GlobalMethods.addToServerEndPointMap(url);

EncoderConfig encoderConfig = new EncoderConfig().encodeContentTypeAs(
"application/x-www-form-urlencoded; charset=utf-8", io.restassured.http.ContentType.URLENC);

RESTCLIENT_LOGGER.info("REST-ASSURED: Sending a POST request to " + url);

try {
io.restassured.specification.RequestSpecification requestSpec = given()
.config(config.encoderConfig(encoderConfig)).relaxedHTTPSValidation()
.contentType("application/x-www-form-urlencoded; charset=utf-8");

if (formData != null && !formData.isEmpty()) {
requestSpec.formParams(formData);
}

if (headers != null && !headers.isEmpty()) {
RESTCLIENT_LOGGER.info("Headers being sent: " + headers);
requestSpec.headers(headers);
} else {
RESTCLIENT_LOGGER.info("No headers provided for this request.");
}

if (ConfigManager.IsDebugEnabled()) {
postResponse = requestSpec.log().all().when().post(url).then().extract().response();
} else {
postResponse = requestSpec.when().post(url).then().extract().response();
}

RESTCLIENT_LOGGER.info("Response Status Code: " + postResponse.getStatusCode());
RESTCLIENT_LOGGER.info("Response Body: " + postResponse.asString());

} catch (Exception e) {
RESTCLIENT_LOGGER.error("Error while sending POST request to " + url + ": " + e.getMessage(), e);
}

return postResponse;
}

public static Response getRequestWithHeaders(String url, String contentHeader, String acceptHeader,
Map<String, String> headers) {
Response getResponse;
url = GlobalMethods.addToServerEndPointMap(url);

if (ConfigManager.IsDebugEnabled()) {
RESTCLIENT_LOGGER.info("REST-ASSURED: Sending a GET request to " + url);

getResponse = given().config(config).relaxedHTTPSValidation().headers(headers).log().all().when().get(url)
.then().log().all().extract().response();

RESTCLIENT_LOGGER.info(GlobalConstants.REST_ASSURED_STRING_2 + getResponse.asString());
RESTCLIENT_LOGGER.info(GlobalConstants.REST_ASSURED_STRING_3 + getResponse.time());
} else {
getResponse = given().config(config).relaxedHTTPSValidation().headers(headers).when().get(url).then()
.extract().response();
}

return getResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ public static void main(String[] args) {

System.out.println(mapper.getImpactSummaryBasedOnConsumer());
}
}
}