Skip to content

Commit

Permalink
MOSIP-34894
Browse files Browse the repository at this point in the history
Signed-off-by: Sohan Kumar Dey <72375959+Sohandey@users.noreply.github.com>
  • Loading branch information
Sohandey committed Aug 1, 2024
1 parent d746959 commit 79dfd52
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.mosip.testrig.apirig.testrunner;


import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -51,7 +50,7 @@
* All suite level before and after tests will be completed here.
*
*/
@ContextConfiguration(classes = {BeanConfig.class})
@ContextConfiguration(classes = { BeanConfig.class })
public class BaseTestCase extends AbstractTestNGSpringContextTests {

protected static Logger logger = Logger.getLogger(BaseTestCase.class);
Expand Down Expand Up @@ -111,7 +110,7 @@ public class BaseTestCase extends AbstractTestNGSpringContextTests {
public static String expiredPreId = null;
public String batchJobToken = null;
public String invalidBatchJobToken = null;

public static List<String> expiredPreRegIds = null;
public static List<String> consumedPreRegIds = null;
public static Map<?, ?> residentQueries;
Expand All @@ -132,21 +131,18 @@ public class BaseTestCase extends AbstractTestNGSpringContextTests {
public static List<String> t = new ArrayList<>();
private static final char[] alphaNumericAllowed = "abcdefghijklmnopqrstuvwxyzABCDEFGJKLMNPRSTUVWXYZ0123456789"
.toCharArray();
private static final char[] alphabetsAllowed = "abcdefghijklmnopqrstuvwxyzABCDEFGJKLMNPRSTUVWXYZ"
.toCharArray();
private static final char[] alphabetsAllowed = "abcdefghijklmnopqrstuvwxyzABCDEFGJKLMNPRSTUVWXYZ".toCharArray();
private static final char[] nNumericAllowed = "0123456789".toCharArray();
public static SecureRandom secureRandom = new SecureRandom();

public static String hierarchyName = "";
public static int hierarchyLevel = 0;
public static String parentLocCode = "";

public static String locationCode = "";
public static String ZonelocationCode = "";
public static String hierarchyZoneCode = "";




public static String genRid = "27847" + generateRandomNumberString(10);

public static String genPolicyNumber = "9" + generateRandomNumberString(5);
Expand All @@ -172,11 +168,11 @@ public class BaseTestCase extends AbstractTestNGSpringContextTests {
public static String genPartnerEmail = "automationpartneresi" + generateRandomNumberString(7)
+ "@automationMosip.com";
public String genPartnerEmailForDsl = "automationpartnerdsl" + generateRandomNumberString(10)
+ "@automationMosip.com";
+ "@automationMosip.com";
public String genPartnerEmailNonAuth = "automationesignet" + generateRandomNumberString(10)
+ "@automationMosip.com";
public String genMispPartnerEmail = "misppartner" + generateRandomNumberString(4)
+ generateRandomNumberString(4) + "@automationMosip.com";
+ "@automationMosip.com";
public String genMispPartnerEmail = "misppartner" + generateRandomNumberString(4) + generateRandomNumberString(4)
+ "@automationMosip.com";
public static String publickey;
public static RSAKey rsaJWK;
public static String clientAssertionToken;
Expand All @@ -185,17 +181,16 @@ public class BaseTestCase extends AbstractTestNGSpringContextTests {
MosipTestRunner.getGlobalResourcePath() + "/" + "config/application.properties");
public static Properties propsKernel = getproperty(
MosipTestRunner.getGlobalResourcePath() + "/" + "config/Kernel.properties");

public static String currentRunningLanguage = "";
//Need to handle this

// Need to handle this
/*
* static String timeStamp =
* String.valueOf(Calendar.getInstance().getTimeInMillis()); static String
* partnerId = "Tech-1245"; static String emailId = "mosip_1" + timeStamp +
* "@gmail.com"; static String role = PartnerRegistration.partnerType;
*/


public static String getOSType() {
String type = System.getProperty("os.name");
Expand Down Expand Up @@ -237,9 +232,6 @@ public static void initialize() {
logger.info("Configs from properties file are set.");

}




public static void suiteSetup() {
if (ConfigManager.IsDebugEnabled())
Expand Down Expand Up @@ -268,54 +260,39 @@ public static void suiteSetup() {
BaseTestCase.currentModule = "auth";
BaseTestCase.certsForModule = "IDA";
AuthTestsUtil.initiateAuthTest();

// mockSMTPListener = new MockSMTPListener();
// mockSMTPListener.run();
}
if (listOfModules.contains("idrepo")) {
setReportName("idrepo");
BaseTestCase.currentModule = "idrepo";
BaseTestCase.certsForModule = "idrepo";
AdminTestUtil.copyIdrepoTestResource();
}

if (listOfModules.contains(GlobalConstants.MASTERDATA)) {
DBManager.clearMasterDbData();
BaseTestCase.currentModule = GlobalConstants.MASTERDATA;
setReportName(GlobalConstants.MASTERDATA);
AdminTestUtil.initiateMasterDataTest();
}

if (listOfModules.contains(GlobalConstants.MIMOTO)) {
BaseTestCase.currentModule = GlobalConstants.MIMOTO;
BaseTestCase.certsForModule = GlobalConstants.MIMOTO;
setReportName(GlobalConstants.MIMOTO);
AdminTestUtil.initiateMimotoTest();
mockSMTPListener = new MockSMTPListener();
mockSMTPListener.run();

}

if (listOfModules.contains(GlobalConstants.ESIGNET)) {

BaseTestCase.currentModule = GlobalConstants.ESIGNET;
BaseTestCase.certsForModule = GlobalConstants.ESIGNET;
DBManager.clearKeyManagerDbDataForEsignet();
DBManager.clearIDADbDataForEsignet();
DBManager.clearMasterDbDataForEsignet();
setReportName(GlobalConstants.ESIGNET);
AdminTestUtil.initiateesignetTest();
mockSMTPListener = new MockSMTPListener();
mockSMTPListener.run();

}
if (listOfModules.contains(GlobalConstants.RESIDENT)) {
BaseTestCase.currentModule = GlobalConstants.RESIDENT;
BaseTestCase.certsForModule = GlobalConstants.RESIDENT;
setReportName(GlobalConstants.RESIDENT);
AdminTestUtil.copyResidentTestResource();
mockSMTPListener = new MockSMTPListener();
mockSMTPListener.run();
}
if (listOfModules.contains("partner")) {
BaseTestCase.currentModule = "partner";
Expand All @@ -325,16 +302,11 @@ public static void suiteSetup() {
setReportName("partner");
AdminTestUtil.copyPartnerTestResource();
}

if (listOfModules.contains(GlobalConstants.PARTNERNEW)) {
BaseTestCase.currentModule = GlobalConstants.PARTNERNEW;
DBManager.clearPartnerRevampDbData();
DBManager.clearKeyManagerDbDataForPartnerRevamp();
DBManager.clearIDADbDataForPartnerRevamp();
//KeycloakUserManager.createKeyCloakUsers(partnerId, emailId, role);



BaseTestCase.currentModule = GlobalConstants.PARTNERNEW;
setReportName(GlobalConstants.PARTNERNEW);
AdminTestUtil.copyPmsNewTestResource();
Expand All @@ -343,10 +315,9 @@ public static void suiteSetup() {
BaseTestCase.currentModule = GlobalConstants.PREREG;
setReportName(GlobalConstants.PREREG);
AdminTestUtil.copyPreregTestResource();
mockSMTPListener = new MockSMTPListener();
mockSMTPListener.run();

}
mockSMTPListener = new MockSMTPListener();
mockSMTPListener.run();
}

public static void setReportName(String moduleName) {
Expand All @@ -364,7 +335,7 @@ public void testTearDown(ITestContext ctx) {
logger.info("\n\n");
logger.info("Rest Assured framework has been reset because all tests have been executed.");
logger.info("TESTING COMPLETE: SHUTTING DOWN FRAMEWORK!!");
}
}

public static Properties getproperty(String path) {
Properties prop = new Properties();
Expand All @@ -375,7 +346,7 @@ public static Properties getproperty(String path) {
prop.load(inputStream);
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e.getMessage());
}finally {
} finally {
AdminTestUtil.closeInputStream(inputStream);
}
return prop;
Expand Down Expand Up @@ -443,15 +414,15 @@ public static void mapUserToZone() {

}

//below method is used by dsl.
// below method is used by dsl.
@SuppressWarnings("unchecked")
public static void mapUserToZone(String user, String zone) {

String token = kernelAuthLib.getTokenByRole("globalAdmin");
String url = ApplnURI + propsKernel.getProperty("zoneMappingUrl");
org.json.simple.JSONObject actualrequest = getRequestJson(zoneMappingRequest);
JSONObject request = new JSONObject();
request.put("zoneCode", zone);
request.put("zoneCode", zone);
request.put("userId", user);
request.put("langCode", BaseTestCase.getLanguageList().get(0));
request.put(GlobalConstants.ISACTIVE, GlobalConstants.TRUE_STRING);
Expand Down Expand Up @@ -552,9 +523,9 @@ public static void userCenterMappingStatus() {
MediaType.APPLICATION_JSON, GlobalConstants.AUTHORIZATION, token);
logger.info(response);
}

public static JSONArray idaActuatorResponseArray = null;

public static String getValueFromActuators(String endPoint, String section, String key) {

String url = ApplnURI + endPoint;
Expand All @@ -569,14 +540,14 @@ public static String getValueFromActuators(String endPoint, String section, Stri
responseJson = new org.json.JSONObject(response.getBody().asString());
idaActuatorResponseArray = responseJson.getJSONArray("propertySources");
}
logger.info("idaActuatorResponseArray="+idaActuatorResponseArray);
logger.info("idaActuatorResponseArray=" + idaActuatorResponseArray);

for (int i = 0, size = idaActuatorResponseArray.length(); i < size; i++) {
org.json.JSONObject eachJson = idaActuatorResponseArray.getJSONObject(i);
if (eachJson.get("name").toString().contains(section)) {
value = eachJson.getJSONObject(GlobalConstants.PROPERTIES).getJSONObject(key)
.get(GlobalConstants.VALUE).toString();
logger.info("value="+value);
logger.info("value=" + value);
break;
}
}
Expand Down Expand Up @@ -624,9 +595,9 @@ public static List<String> getLanguageList() {
return languageList;

}

private static String targetEnvVersion = "";

public static boolean isTargetEnvLTS() {

if (targetEnvVersion.isEmpty()) {
Expand Down Expand Up @@ -699,14 +670,15 @@ public static JSONObject getRequestJson(String filepath) {
return kernelCmnLib.readJsonData(filepath, true);

}

public static String generateRandomAlphaNumericString(int length) {
StringBuilder alphaNumericString = new StringBuilder();
for (int i = 0; i < length; i++) {
alphaNumericString.append(alphaNumericAllowed[secureRandom.nextInt(alphaNumericAllowed.length)]);
}
return alphaNumericString.toString();
}

public static String generateRandomAlphabeticString(int length) {
StringBuilder alphaNumericString = new StringBuilder();
for (int i = 0; i < length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ public static String getOtp(String emailId) {
String otp = "";


if (AdminTestUtil.getValueFromAuthActuator(
"mosip/mosip-config/application-default.properties", "mosip.kernel.auth.proxy-otp").equalsIgnoreCase(GlobalConstants.TRUE_STRING)) {
if (ConfigManager.getUsePreConfiguredOtp().equalsIgnoreCase(GlobalConstants.TRUE_STRING)) {
return ConfigManager.getPreConfiguredOtp();
}
while (counter < otpCheckLoopCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ protected Response postRequestWithCookieAuthHeaderAndSignature(String url, Strin
headers.put(AUTHORIZATHION_HEADERNAME, AUTH_HEADER_VALUE);
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
headers.put(SIGNATURE_HEADERNAME, generateSignatureWithRequest(inputJson, partnerId));

if (testCaseName.contains("NOAUTH")) {
token = "";
} else {
Expand Down Expand Up @@ -4170,15 +4171,19 @@ public String getAutoGeneratedFieldValue(String inputFromYml, String testCaseNam
return props.getProperty(keyForIdProperty);
}

public String updateTimestampOtp(String otpIdentyEnryptRequest) {
public String updateTimestampOtp(String otpIdentyEnryptRequest, String otpChannel, String testCaseName) {
otpIdentyEnryptRequest = JsonPrecondtion.parseAndReturnJsonContent(otpIdentyEnryptRequest,
generateCurrentUTCTimeStamp(), "timestamp");
if (proxy)
otpIdentyEnryptRequest = JsonPrecondtion.parseAndReturnJsonContent(otpIdentyEnryptRequest,
properties.getProperty("proxyOTP"), "otp");
else
return otpIdentyEnryptRequest;

String otp = null;

otp = MockSMTPListener.getOtp(otpChannel);

if(otp!=null && !otp.isBlank()){
otpIdentyEnryptRequest = JsonPrecondtion.parseAndReturnJsonContent(otpIdentyEnryptRequest, otp, "otp");
}
else {
logger.error("Not Able To Fetch OTP From SMTP");
}
return otpIdentyEnryptRequest;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public class ConfigManager {
private static String reportIgnoredTestCases;
private static String threadCount;
private static String langselect;
//private static String usePreConfiguredOtp;
private static String usePreConfiguredOtp;
private static String preconfiguredOtp;
private static String eSignetbaseurl;
private static String esignetMockBaseURL;
Expand Down Expand Up @@ -394,11 +394,9 @@ public static void init() {
: System.getenv(LANG_SELECT);
propsKernel.setProperty(LANG_SELECT, langselect);

/*
* usePreConfiguredOtp = System.getenv(USEPRECONFIGOTP) == null ?
* propsKernel.getProperty(USEPRECONFIGOTP) : System.getenv(USEPRECONFIGOTP);
* propsKernel.setProperty(USEPRECONFIGOTP, usePreConfiguredOtp);
*/
usePreConfiguredOtp = System.getenv(USEPRECONFIGOTP) == null ? propsKernel.getProperty(USEPRECONFIGOTP)
: System.getenv(USEPRECONFIGOTP);
propsKernel.setProperty(USEPRECONFIGOTP, usePreConfiguredOtp);

preconfiguredOtp = System.getenv(PRECONFIGOTP) == null ? propsKernel.getProperty(PRECONFIGOTP)
: System.getenv(PRECONFIGOTP);
Expand Down Expand Up @@ -574,11 +572,10 @@ public static String getSunBirdBaseURL() {

}

/*
* public static String getUsePreConfiguredOtp() { return usePreConfiguredOtp;
*
* }
*/
public static String getUsePreConfiguredOtp() {
return usePreConfiguredOtp;

}

public static String getPreConfiguredOtp() {
return preconfiguredOtp;
Expand Down Expand Up @@ -917,4 +914,4 @@ private static Properties getproperty(String path) {
}
return prop;
}
}
}
Loading

0 comments on commit 79dfd52

Please sign in to comment.