Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public void execute(Connection connection) throws SQLException {
statement.addBatch("delete from biometric_type where cr_by ='"+BaseClass.userid+"'");
statement.addBatch("delete from blocklisted_words where cr_by ='"+BaseClass.userid+"'");
// statement.addBatch("delete from daysofweek_list where cr_by ='"+BaseClass.userid+"'");
// statement.addBatch(
// "delete from device_master where cr_by ='"+BaseClass.userid+"'");
statement.addBatch(
"delete from device_master where cr_by ='"+BaseClass.userid+"'");
statement.addBatch(
"delete from device_master_h where cr_by ='"+BaseClass.userid+"'");
statement.addBatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static String getUnUsedUIN(String role){
}

public static String getMasterDataSchema(String role){
String url = ApplnURI + props.getProperty("masterSchemaURL");
String url = BaseTestCaseFunc.masterDataUrl(props.getProperty("masterSchemaURL"));
kernelAuthLib = new KernelAuthentication();
String token = kernelAuthLib.getTokenByRole("admin");

Expand Down Expand Up @@ -98,8 +98,11 @@ public static String getServerComponentsDetails() {
if (ConfigManager.isInServiceNotDeployedList(parts[1])) {
continue;
}
stringBuilder.append("\n")
.append(getCommitDetails(BaseTestCaseFunc.ApplnURI + parts[1].replace("health", "info")));
String infoPath = parts[1].replace("health", "info");
String infoBase = infoPath.contains("/v1/masterdata")
? BaseTestCaseFunc.masterDataUrl(infoPath)
: BaseTestCaseFunc.ApplnURI + infoPath;
stringBuilder.append("\n").append(getCommitDetails(infoBase));
}
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.SecureRandom;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import org.apache.log4j.Logger;

Expand Down Expand Up @@ -93,6 +98,7 @@ public class ConfigManager {
private static String IAM_ADMINPORTAL_PATH = "adminPortalPath";
private static String IAM_APIENVUSER = "apiEnvUser";
private static String IAM_APIINTERNALENDPOINT = "apiInternalEndPoint";
private static String MASTER_DATA_BASE_URL = "masterdatabaseurl";
private static String IAM_REALM_ID = "keycloak-realm-id";
private static String IAM_USERS_TO_CREATE = "iam-users-to-create";
private static String IAM_USERS_PASSWORD = "iam-users-password";
Expand Down Expand Up @@ -217,6 +223,7 @@ public class ConfigManager {
private static String iam_adminportal_path;
private static String iam_apienvuser;
private static String iam_apiinternalendpoint;
private static String masterdatabaseurl;
private static String iam_realm_id;
private static String iam_users_to_create;
private static String iam_users_password;
Expand Down Expand Up @@ -288,6 +295,10 @@ public static void init() {
? propsKernel.getProperty(IAM_APIINTERNALENDPOINT)
: System.getenv(IAM_APIINTERNALENDPOINT);
logger.info("apiinternalendpoint from config manager::" + iam_apiinternalendpoint);
masterdatabaseurl = System.getenv(MASTER_DATA_BASE_URL) == null
? propsKernel.getProperty(MASTER_DATA_BASE_URL)
: System.getenv(MASTER_DATA_BASE_URL);
logger.info("masterdatabaseurl from config manager::" + masterdatabaseurl);

serviceNotDeployedList = System.getenv(SERVICES_NOT_DEPLOYED) == null
? propsKernel.getProperty(SERVICES_NOT_DEPLOYED)
Expand All @@ -308,10 +319,11 @@ public static void init() {

push_reports_to_s3 =System.getenv(PUSH_TO_S3) == null ? propsKernel.getProperty(PUSH_TO_S3) : System.getenv(PUSH_TO_S3);
propsKernel.setProperty(PUSH_TO_S3, push_reports_to_s3);
holidayDateCenter =System.getenv(HolidayDateCenter) == null ? propsKernel.getProperty(HolidayDateCenter) : System.getenv(HolidayDateCenter);
Set<String> usedDates = new HashSet<>();
holidayDateCenter = randomFutureDate(usedDates);
propsKernel.setProperty(HolidayDateCenter, holidayDateCenter);

holidayDate =System.getenv(HolidayDate) == null ? propsKernel.getProperty(HolidayDate) : System.getenv(HolidayDate);
holidayDate = randomFutureDate(usedDates);
propsKernel.setProperty(HolidayDate, holidayDate);

preappend =System.getenv(Preappend) == null ? propsKernel.getProperty(Preappend) : System.getenv(Preappend);
Expand All @@ -328,11 +340,13 @@ public static void init() {



dummyData =System.getenv(DummyData) == null ? propsKernel.getProperty(DummyData) : System.getenv(DummyData);
dummyData = randomLetters(11);
propsKernel.setProperty(DummyData, dummyData);

validityDate =System.getenv(ValidityDate) == null ? propsKernel.getProperty(ValidityDate) : System.getenv(ValidityDate);
validityDate = randomFutureDate(usedDates);
propsKernel.setProperty(ValidityDate, validityDate);
logger.info("Generated test data holidayDateCenter=" + holidayDateCenter + " holidayDate=" + holidayDate
+ " validityDate=" + validityDate + " dummyData=" + dummyData);

publicKey =System.getenv(PublicKey) == null ? propsKernel.getProperty(PublicKey) : System.getenv(PublicKey);
propsKernel.setProperty(PublicKey, publicKey);
Expand All @@ -356,6 +370,26 @@ public static void init() {
propsKernel.setProperty(Testcases, testcases);

}
private static final SecureRandom SECURE_RANDOM = new SecureRandom();

private static String randomLetters(int length) {
StringBuilder word = new StringBuilder(length);
for (int i = 0; i < length; i++) {
word.append((char) ('a' + SECURE_RANDOM.nextInt(26)));
}
return word.toString();
}

private static String randomFutureDate(Set<String> usedDates) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
String formatted;
do {
int plusDays = 1 + SECURE_RANDOM.nextInt(699);
formatted = LocalDate.now().plusDays(plusDays).format(formatter);
} while (!usedDates.add(formatted));
return formatted;
}

public static String gettestcases() {
return testcases;
}
Expand Down Expand Up @@ -670,6 +704,10 @@ public static String getiam_apienvuser() {
public static String getiam_apiinternalendpoint() {
return iam_apiinternalendpoint;
}

public static String getMasterdatabaseurl() {
return masterdatabaseurl;
}
// public static String getAuthDemoServiceUrl() {
// return ConfigManager.getAuthDemoServiceBaseUrl() + ":" + ConfigManager.getAuthDemoServicePort();
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import io.github.bonigarcia.wdm.WebDriverManager;
import io.mosip.testrig.adminui.kernel.util.ConfigManager;
import io.mosip.testrig.adminui.kernel.util.KernelAuthentication;
import io.mosip.testrig.adminui.kernel.util.KeycloakUserManager;

public class BaseClass {
Expand Down Expand Up @@ -68,17 +69,41 @@ public void setUp(Method testMethod) throws Exception {
"--disable-dev-shm-usage");
}

if (isLocalPortal(envPath)) {
// Local UI (4200) calls local admin-service (8086). The auth adapter does not
// allow every header the UI sends, so Chrome blocks the call and the UI shows
// "No internet". Disable web security only for this local run.
// Each thread needs its own profile. A shared --user-data-dir makes Chrome
// fail to open localhost when tests run in parallel.
String profileDir = System.getProperty("java.io.tmpdir") + "admin-ui-chrome-"
+ Thread.currentThread().getId();
options.addArguments("--disable-web-security", "--user-data-dir=" + profileDir,
"--proxy-bypass-list=<-loopback>");
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.block_third_party_cookies", Boolean.FALSE);
prefs.put("profile.cookie_controls_mode", Integer.valueOf(0));
options.setExperimentalOption("prefs", prefs);
}

WebDriver threadDriver = new ChromeDriver(options);
driverThread.set(threadDriver); // Set driver for this thread

js = (JavascriptExecutor) driver();
vars = new HashMap<String, Object>();
driver().manage().window().maximize();
driver().manage().timeouts().implicitlyWait(Duration.ofSeconds(20));

if (isLocalPortal(envPath)) {
injectAdminToken(threadDriver);
logger.info("Localhost run: opened portal with admin Authorization cookie. URL: " + envPath);
driver().get(envPath);
Commons.waitForPageLoad(driver());
return;
}

driver().get(envPath);
logger.info("Launch URL: " + envPath);
driver().manage().window().maximize();
Commons.waitForPageLoad(driver());
;
driver().manage().timeouts().implicitlyWait(Duration.ofSeconds(20));

String language1 = ConfigManager.getloginlang();
String loginlang;
Expand All @@ -103,6 +128,57 @@ public void setUp(Method testMethod) throws Exception {

}

/**
* localhost is not in the auth-manager allowed redirect list, so the Keycloak
* login page returns KER-ACP-009. Store the internal-auth token as a real
* cookie on the API host. Forcing a Cookie header instead replaces every other
* cookie, so later POST calls fail and the UI opens a Technical Error dialog
* for each one.
*/
private void injectAdminToken(WebDriver threadDriver) {
if (BaseTestCaseFunc.ApplnURI == null || BaseTestCaseFunc.ApplnURI.isEmpty()) {
BaseTestCaseFunc.ApplnURI = ConfigManager.getiam_apiinternalendpoint();
}
String token = new KernelAuthentication().getAuthForAdmin();
if (token == null || token.isEmpty()) {
throw new IllegalStateException("Admin token was empty. Check Kernel.properties client id and secret.");
}
String apiUrl = cookieHost();
boolean https = apiUrl.startsWith("https://");
Map<String, Object> cookie = new HashMap<String, Object>();
cookie.put("name", BaseTestCaseFunc.COOKIENAME);
cookie.put("value", token);
cookie.put("url", apiUrl);
cookie.put("path", "/");
cookie.put("secure", Boolean.valueOf(https));
cookie.put("sameSite", https ? "None" : "Lax");
ChromeDriver chromeDriver = (ChromeDriver) threadDriver;
chromeDriver.executeCdpCommand("Network.enable", new HashMap<String, Object>());
chromeDriver.executeCdpCommand("Network.setCookie", cookie);
logger.info("Stored Authorization cookie for " + apiUrl);
}

/**
* The UI calls masterdatabaseurl (local admin-service). A cookie stored on the
* dev2 API host is not sent with those requests.
*/
private String cookieHost() {
String master = ConfigManager.getMasterdatabaseurl();
String host = (master != null && !master.isEmpty()) ? master : BaseTestCaseFunc.ApplnURI;
if (!host.endsWith("/")) {
host = host + "/";
}
return host;
}

private boolean isLocalPortal(String portalUrl) {
if (portalUrl == null) {
return false;
}
String url = portalUrl.toLowerCase();
return url.contains("localhost") || url.contains("127.0.0.1");
}

@AfterMethod(alwaysRun = true)
public void tearDown(ITestResult result) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static String getOSType() {
public static List<String> getLanguageList() {
logger.info("We have created a Config Manager. Beginning to read properties!");

environment = ConfigManager.getiam_apienvuser();
environment = resolveReportEnvironment();
logger.info("Environemnt is ==== :" + environment);
ApplnURI = ConfigManager.getiam_apiinternalendpoint();
logger.info("Application URI ======" + ApplnURI);
Expand All @@ -94,6 +94,17 @@ public static List<String> getLanguageList() {
return languageList;
}

/**
* Report label. Local portal runs use "local" even when API properties still point at a named env.
*/
public static String resolveReportEnvironment() {
String portalPath = ConfigManager.getiam_adminportal_path();
if (portalPath != null && portalPath.toLowerCase().contains("localhost")) {
return "local";
}
return ConfigManager.getiam_apienvuser();
}

public static Properties getproperty(String path) {
Properties prop = new Properties();

Expand All @@ -120,7 +131,7 @@ public static void initialize() {
getOSType();
logger.info("We have created a Config Manager. Beginning to read properties!");

environment = ConfigManager.getiam_apienvuser();
environment = resolveReportEnvironment();
logger.info("Environemnt is ==== :" + environment);
ApplnURI = ConfigManager.getiam_apiinternalendpoint();
logger.info("Application URI ======" + ApplnURI);
Expand Down Expand Up @@ -157,7 +168,7 @@ public static JSONObject getRequestJson(String filepath) {

public static void getLeafeZone() {
String token = kernelAuthLib.getTokenByRole("globalAdmin");
String url=ApplnURI + propsKernel.getProperty("leafzonesURL");
String url = masterDataUrl(propsKernel.getProperty("leafzonesURL"));
JSONObject request = new JSONObject();

Response response = RestClient.getRequestWithCookieAndPathParm(url, request, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, "Authorization", token);
Expand All @@ -168,7 +179,7 @@ public static void getLeafeZone() {
@SuppressWarnings("unchecked")
public static void mapUserToZone(String user, String zone) {
String token = kernelAuthLib.getTokenByRole("globalAdmin");
String url = ApplnURI + propsKernel.getProperty("zoneMappingUrl");
String url = masterDataUrl(propsKernel.getProperty("zoneMappingUrl"));
org.json.simple.JSONObject actualrequest = getRequestJson(zoneMappingRequest);
JSONObject request = new JSONObject();
request.put("zoneCode", RestClient.ZONECODE);
Expand All @@ -184,7 +195,7 @@ public static void mapUserToZone(String user, String zone) {
}
public static void mapZone(String user) {
String token = kernelAuthLib.getTokenByRole("globalAdmin");
String url = ApplnURI + propsKernel.getProperty("zoneMappingActivateUrl");
String url = masterDataUrl(propsKernel.getProperty("zoneMappingActivateUrl"));
HashMap<String, String> map = new HashMap<String, String>();
map.put("isActive","true");
map.put("userId", user);
Expand All @@ -196,7 +207,7 @@ public static void mapZone(String user) {
public static int getHierarchyNumbers() {
KernelAuthentication kernelAuthLib = new KernelAuthentication();
String token = kernelAuthLib.getTokenByRole("admin");
String url = ApplnURI + props.getProperty("locationHierarchyLevels") + getlang();
String url = masterDataUrl(props.getProperty("locationHierarchyLevels") + getlang());
Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, "Authorization", token);

String responseString = response.asString();
Expand All @@ -219,6 +230,20 @@ public static int getHierarchyNumbers() {
return maxHierarchyLevel;
}

public static String masterDataUrl(String path) {
String base = ConfigManager.getMasterdatabaseurl();
if (base == null || base.isEmpty()) {
base = ApplnURI;
}
if (base.endsWith("/")) {
base = base.substring(0, base.length() - 1);
}
if (path != null && !path.startsWith("/")) {
path = "/" + path;
}
return base + path;
}

public static String getlang() {
String language=ConfigManager.getloginlang();
if(language.equalsIgnoreCase("sin")) {
Expand Down
Loading
Loading