Skip to content

Commit

Permalink
MOSIP-35390 Resolved conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Sohan Kumar Dey <[email protected]>
  • Loading branch information
Sohandey committed Aug 27, 2024
2 parents 345811d + 44e43b4 commit adfaec2
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,15 @@ public static void suiteSetup() {
setReportName(GlobalConstants.PREREG);
AdminTestUtil.copyPreregTestResource();
}
// if (listOfModules.contains(GlobalConstants.INJICERTIFY)) {
// BaseTestCase.currentModule = GlobalConstants.INJICERTIFY;
// BaseTestCase.certsForModule = GlobalConstants.INJICERTIFY;
// DBManager.clearKeyManagerDbCertData();
// DBManager.clearIDADbCertData();
// DBManager.clearMasterDbCertData();
// setReportName(GlobalConstants.INJICERTIFY);
// AdminTestUtil.copymoduleSpecificAndConfigFile(GlobalConstants.INJICERTIFY);
// }
if (listOfModules.contains(GlobalConstants.INJICERTIFY)) {
BaseTestCase.currentModule = GlobalConstants.INJICERTIFY;
BaseTestCase.certsForModule = GlobalConstants.INJICERTIFY;
DBManager.clearKeyManagerDbCertData();
DBManager.clearIDADbCertData();
DBManager.clearMasterDbCertData();
setReportName(GlobalConstants.INJICERTIFY);
AdminTestUtil.copymoduleSpecificAndConfigFile(GlobalConstants.INJICERTIFY);
}
mockSMTPListener = new MockSMTPListener();
mockSMTPListener.run();
}
Expand Down Expand Up @@ -740,4 +740,10 @@ public static String generateRandomNumberString(int length) {
}
return numericString.toString();
}

public static int getRecommendedHierarchyLevel() {
String recommendedHierarchLevel = getValueFromActuators(propsKernel.getProperty("actuatorMasterDataEndpoint"),
"/mosip-config/application-default.properties", "mosip.recommended.centers.locCode");
return Integer.parseInt(recommendedHierarchLevel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public class AdminTestUtil extends BaseTestCase {
public static final String AUTH_HEADER_VALUE = "Some String";
public static final String SIGNATURE_HEADERNAME = GlobalConstants.SIGNATURE;
public static String updatedPolicyId = "";
public static String currentLanguage;
// public static BioDataUtility bioDataUtil = new BioDataUtility();
//
// public static BioDataUtility getBioDataUtil() {
Expand Down Expand Up @@ -3393,7 +3394,7 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {
}
if (jsonString.contains("$GETCLIENTIDFROMMIMOTOACTUATOR$")) {
jsonString = replaceKeywordWithValue(jsonString, "$GETCLIENTIDFROMMIMOTOACTUATOR$",
getValueFromMimotoActuator("configService:overrides", "mimoto.oidc.partner.clientid"));
getValueFromMimotoActuator("overrides", "mimoto.oidc.partner.clientid"));
}
if (jsonString.contains("$IDPREDIRECTURI$")) {
jsonString = replaceKeywordWithValue(jsonString, "$IDPREDIRECTURI$",
Expand Down Expand Up @@ -3794,6 +3795,7 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {
JSONObject request = new JSONObject(jsonString);
String clientId = "";
String accessToken = "";
String tempUrl = "";
if (request.has("client_id")) {
clientId = request.getString("client_id");
request.remove("client_id");
Expand All @@ -3802,8 +3804,21 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {
accessToken = request.getString("idpAccessToken");
}
jsonString = request.toString();

if (BaseTestCase.currentModule.equals(GlobalConstants.INJICERTIFY)) {
String baseURL = ConfigManager.getInjiCertifyBaseUrl();
if (testCaseName.contains("_GetCredentialSunBirdC")) {
tempUrl = getValueFromInjiCertifyWellKnownEndPoint("credential_issuer",
baseURL.replace("injicertify.", "injicertify-insurance."));
}
} else {
tempUrl = getValueFromEsignetWellKnownEndPoint("issuer");
if (tempUrl.contains("esignet.")) {
tempUrl = tempUrl.replace("esignet.", propsKernel.getProperty("esignetMockBaseURL"));
}
}
jsonString = replaceKeywordWithValue(jsonString, "$PROOF_JWT_2$",
signJWKForMock(clientId, accessToken, oidcJWKKey4, testCaseName));
signJWKForMock(clientId, accessToken, oidcJWKKey4, testCaseName, tempUrl));
}

if (jsonString.contains(GlobalConstants.REMOVE))
Expand All @@ -3812,12 +3827,8 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {
return jsonString;
}

public static String signJWKForMock(String clientId, String accessToken, RSAKey jwkKey, String testCaseName) {
// String tempUrl = getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, "mosip.iam.base.url");
String tempUrl = getValueFromEsignetWellKnownEndPoint("issuer");
if (tempUrl.contains("esignet.")) {
tempUrl = tempUrl.replace("esignet.", propsKernel.getProperty("esignetMockBaseURL"));
}
public static String signJWKForMock(String clientId, String accessToken, RSAKey jwkKey, String testCaseName,
String tempUrl) {
int idTokenExpirySecs = Integer
.parseInt(getValueFromEsignetActuator(ConfigManager.getEsignetActuatorPropertySection(),
GlobalConstants.MOSIP_ESIGNET_ID_TOKEN_EXPIRE_SECONDS));
Expand Down Expand Up @@ -4215,7 +4226,47 @@ private String replaceIdWithAutogeneratedId(String jsonString, String idKey, Str
if (!jsonString.contains(idKey))
return jsonString;
String keyForIdProperty = StringUtils.substringBetween(jsonString, idKey, "$");
String keyToReplace = idKey + keyForIdProperty + "$";
String keyToReplace = "";

// mock = email,phone; default
// mock = phone;
// mock = email;

// $ID:AddIdentity_withValidParameters_smoke_Pos_EMAIL$

// $ID:AddIdentity_withValidParameters_smoke_Pos_PHONE$@phone



if (keyForIdProperty.endsWith("_EMAIL") && 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

jsonString = jsonString.replace(temp, temp + "@phone");


} else if (keyForIdProperty.endsWith("_PHONE") && ConfigManager.getMockNotificationChannel().equalsIgnoreCase("email")) {
String temp = idKey + keyForIdProperty + "$" ; //$ID:AddIdentity_withValidParameters_smoke_Pos_PHONE$
keyForIdProperty = keyForIdProperty.replace("_PHONE", "_EMAIL"); // AddIdentity_withValidParameters_smoke_Pos_EMAIL
keyToReplace = temp + "@phone";
} else {
keyToReplace = idKey + keyForIdProperty + "$"; //AddIdentity_withValidParameters_smoke_Pos_EMAIL
}














Properties props = new Properties();

try (FileInputStream inputStream = new FileInputStream(getResourcePath() + autoGenIdFileName);) {
Expand Down Expand Up @@ -4535,6 +4586,14 @@ private static ArrayList<JSONObject> convertJson(String[] templateFields, String
translatedValue = valueToConvert;
isFilterRequired = true;
}
} else if (jsonObject.has(GlobalConstants.KEYWORD_DATA)) {
String filterValueToConvert = jsonObject.getJSONArray(GlobalConstants.KEYWORD_DATA).get(0).toString();
JSONObject filtervalue = new JSONObject(filterValueToConvert);
if (filtervalue.has(fieldToConvert)) {
valueToConvert = filtervalue.getString(fieldToConvert);
translatedValue = valueToConvert;
isFilterRequired = false;
}
}

if (!language.equalsIgnoreCase("eng") && valueToConvert != null) {
Expand Down Expand Up @@ -6162,6 +6221,29 @@ public static String getValueFromEsignetWellKnownEndPoint(String key) {
}
return responseJson.getString(key);
}

public static String getValueFromInjiCertifyWellKnownEndPoint(String key, String baseURL) {
String url = baseURL + propsKernel.getProperty("injiCertifyWellKnownEndPoint");

String actuatorCacheKey = url + key;
String value = actuatorValueCache.get(actuatorCacheKey);
if (value != null && !value.isEmpty())
return value;

Response response = null;
JSONObject responseJson = null;
try {
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
responseJson = new org.json.JSONObject(response.getBody().asString());
if (responseJson.has(key)) {
actuatorValueCache.put(actuatorCacheKey, responseJson.getString(key));
return responseJson.getString(key);
}
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
}
return responseJson.getString(key);
}

public static JSONObject signUpSettingsResponseJson = null;

Expand Down Expand Up @@ -6983,6 +7065,7 @@ public static void getLocationData() {
JSONObject responseJson = null;
String url = ApplnURI + props.getProperty("fetchLocationData");
String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN);
int recommendedHierarchyLevel = getRecommendedHierarchyLevel();
try {
response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON,
GlobalConstants.AUTHORIZATION, token);
Expand All @@ -6993,15 +7076,21 @@ public static void getLocationData() {
JSONObject responseObject = responseJson.getJSONObject("response");
JSONArray data = responseObject.getJSONArray("data");

if (!(languageList.size() > 1)) {
currentLanguage = BaseTestCase.languageList.get(0);
}

for (int i = 0; i < data.length(); i++) {
JSONObject entry = data.getJSONObject(i);
String langCode = entry.getString("langCode");

if (BaseTestCase.languageList.get(0).equals(langCode)) {
hierarchyName = entry.getString("hierarchyName");
hierarchyLevel = entry.getInt("hierarchyLevel");
parentLocCode = entry.optString("parentLocCode", "");
break;
hierarchyLevel = entry.getInt("hierarchyLevel");

if (hierarchyLevel == recommendedHierarchyLevel) {
if (currentLanguage.equals(langCode)) {
hierarchyName = entry.getString("hierarchyName");
parentLocCode = entry.optString("parentLocCode", "");
break;
}
}
}

Expand Down Expand Up @@ -7421,5 +7510,6 @@ else if (testCaseName.endsWith("_withoutselectedhandles")) {
// }
// return false;
// }

}
}


Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class ConfigManager {
private static String USEPRECONFIGOTP = "usePreConfiguredOtp";
private static String ESIGNET_BASE_URL = "eSignetbaseurl";
private static String ESIGNET_ACTUATOR_PROPERTY_SECTION = "esignetActuatorPropertySection";
private static String INJI_CERTIFY_BASE_URL = "injiCertifyBaseURL";

private static String ESIGNET_MOCK_BASE_URL = "esignetMockBaseURL";
private static String SUNBIRD_BASE_URL = "sunBirdBaseURL";
Expand Down Expand Up @@ -122,6 +123,7 @@ public class ConfigManager {
private static String MOUNT_PATH = "mountPath";
private static String AUTHCERTS_PATH = "authCertsPath";
private static String MOUNT_PATH_FOR_SCENARIO = "mountPathForScenario";
private static String MOCK_NOTIFICATION_CHANNEL = "mockNotificationChannel";

private static String SERVER_ERRORS_TO_MONITOR = "serverErrorsToMonitor";

Expand Down Expand Up @@ -207,6 +209,7 @@ public class ConfigManager {
private static String esignetMockBaseURL;
private static String sunBirdBaseURL;
private static String esignetActuatorPropertySection;
private static String injiCertifyBaseURL;

private static String dbPort;
private static String dbDomain;
Expand Down Expand Up @@ -247,6 +250,7 @@ public class ConfigManager {

private static String mountPath;
private static String authCertsPath;
private static String mockNotificationChannel;
private static String mountPathForScenario;
private static String packetUtilityBaseUrl;
public static Properties propsKernel;
Expand Down Expand Up @@ -361,6 +365,11 @@ public static void init() {
mountPath = System.getenv(MOUNT_PATH) == null ? propsKernel.getProperty(MOUNT_PATH) : System.getenv(MOUNT_PATH);
propsKernel.setProperty(MOUNT_PATH, mountPath);

mockNotificationChannel = System.getenv(MOCK_NOTIFICATION_CHANNEL) == null
? propsKernel.getProperty(MOCK_NOTIFICATION_CHANNEL)
: System.getenv(MOCK_NOTIFICATION_CHANNEL);
propsKernel.setProperty(MOCK_NOTIFICATION_CHANNEL, mockNotificationChannel);

authCertsPath = System.getenv(AUTHCERTS_PATH) == null ? propsKernel.getProperty(AUTHCERTS_PATH)
: System.getenv(AUTHCERTS_PATH);
propsKernel.setProperty(AUTHCERTS_PATH, authCertsPath);
Expand Down Expand Up @@ -420,6 +429,13 @@ public static void init() {
eSignetbaseurl = System.getProperty("env.endpoint").replace("-internal", "");
}
propsKernel.setProperty(ESIGNET_BASE_URL, eSignetbaseurl);

if (System.getenv(INJI_CERTIFY_BASE_URL) != null) {
injiCertifyBaseURL = System.getenv(INJI_CERTIFY_BASE_URL);
} else {
injiCertifyBaseURL = System.getProperty("env.endpoint").replace("api-internal", "injicertify");
}
propsKernel.setProperty(INJI_CERTIFY_BASE_URL, injiCertifyBaseURL);

esignetMockBaseURL = System.getenv(ESIGNET_MOCK_BASE_URL) == null
? propsKernel.getProperty(ESIGNET_MOCK_BASE_URL)
Expand Down Expand Up @@ -573,6 +589,11 @@ public static String getEsignetBaseUrl() {
return eSignetbaseurl;

}

public static String getInjiCertifyBaseUrl() {
return injiCertifyBaseURL;

}

public static String getEsignetMockBaseURL() {
return esignetMockBaseURL;
Expand Down Expand Up @@ -615,6 +636,10 @@ public static String getmountPathForScenario() {
public static String getpacketUtilityBaseUrl() {
return packetUtilityBaseUrl;
}

public static String getMockNotificationChannel() {
return mockNotificationChannel;
}

public static String getauthCertsPath() {
return authCertsPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public class GlobalConstants {
public static final String CERTIFICATEDATA = "certificateData";
public static final String PARTNERDOMAIN = "partnerDomain";
public static final String DATA = ".data";
public static final String KEYWORD_DATA = "data";
public static final String AUTOMATION = "automation";
public static final String AUTOMATIONLABS = "@automationlabs.com";
public static final String REPSONSE = "Repsonse: %s %s%n";
Expand Down Expand Up @@ -227,4 +228,4 @@ public class GlobalConstants {
public static final String SEND_OTP_ENDPOINT = "mimoto/req/";
public static final String CREATE_VID_ENDPOINT = "/idrepository/v1/vid";
public static final String MIMOTO_CREDENTIAL_STATUS = "Mimoto_CredentialsStatus_";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,8 @@ public static boolean doesResponseHasErrorCode(String responseString, String all
}

public static void reportServerIssues(String responseString, TestCaseDTO testCaseDTO) throws AdminTestException {
if (responseString.startsWith("<!DOCTYPE html>"))
if (responseString.startsWith("<!DOCTYPE html>") || responseString.startsWith("<html")
|| responseString.startsWith("no healthy upstream"))
throw new AdminTestException("Not a JSON response. Hence marking the test case as failed");

try {
Expand Down

0 comments on commit adfaec2

Please sign in to comment.