Skip to content

Commit 4f08654

Browse files
Merge pull request #1959 from mohanachandran-s/develop
MOSIP-38979 - Updated the masking and removed redundant api calls
2 parents 3e0c382 + 6267460 commit 4f08654

2 files changed

Lines changed: 42 additions & 26 deletions

File tree

apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ public class AdminTestUtil extends BaseTestCase {
174174
public static String currentLanguage;
175175
protected static String idField = null;
176176
protected static String identityHbs = null;
177+
protected static String identityHbsV2 = null;
177178
protected static String updateIdentityHbs = null;
179+
protected static String updateIdentityHbsV2Cached = null;
178180
protected static String draftHbs = null;
179181
protected static String preregHbsForCreate = null;
180182
protected static String preregHbsForUpdate = null;
@@ -5656,13 +5658,15 @@ public static String modifySchemaGenerateHbs(boolean regenerateHbs) {
56565658
}
56575659

56585660
public static String modifySchemaGenerateHbsV2(boolean regenerateHbs) {
5659-
5661+
if (identityHbsV2 != null && !regenerateHbs) {
5662+
return identityHbsV2;
5663+
}
5664+
if (regenerateHbs) identityHbsV2 = null;
56605665
String hbs = modifySchemaGenerateHbs(regenerateHbs);
5661-
56625666
JSONObject requestJson = new JSONObject(hbs);
56635667
requestJson.getJSONObject("request").put("verifiedAttributes", "$VERIFIED_ATTRIBUTES$");
5664-
5665-
return requestJson.toString().replace("\"$VERIFIED_ATTRIBUTES$\"", buildVerifiedAttributesHbs());
5668+
identityHbsV2 = requestJson.toString().replace("\"$VERIFIED_ATTRIBUTES$\"", buildVerifiedAttributesHbs());
5669+
return identityHbsV2;
56665670
}
56675671

56685672
private static String buildVerifiedAttributesHbs() {
@@ -5866,16 +5870,21 @@ else if (eachRequiredProp.contains(GlobalConstants.GENDER))
58665870
}
58675871

58685872
public static String updateIdentityHbsV2(boolean regenerateHbs) {
5869-
5873+
if (updateIdentityHbsV2Cached != null && !regenerateHbs) {
5874+
return updateIdentityHbsV2Cached;
5875+
}
5876+
if (regenerateHbs) updateIdentityHbsV2Cached = null;
58705877
String hbs = updateIdentityHbs(regenerateHbs);
5871-
58725878
JSONObject requestJson = new JSONObject(hbs);
58735879
requestJson.getJSONObject("request").put("verifiedAttributes", "$VERIFIED_ATTRIBUTES$");
5874-
5875-
return requestJson.toString().replace("\"$VERIFIED_ATTRIBUTES$\"", buildVerifiedAttributesHbs());
5880+
updateIdentityHbsV2Cached = requestJson.toString().replace("\"$VERIFIED_ATTRIBUTES$\"", buildVerifiedAttributesHbs());
5881+
return updateIdentityHbsV2Cached;
58765882
}
58775883

58785884
public static String generateLatestSchemaVersion() {
5885+
if (idSchemaVersion != null) {
5886+
return idSchemaVersion.toString();
5887+
}
58795888
kernelAuthLib = new KernelAuthentication();
58805889
String token = kernelAuthLib.getTokenByRole(GlobalConstants.ADMIN);
58815890
String url = getSchemaURL();

apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/GlobalMethods.java

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -267,28 +267,34 @@ public static boolean getCaptchaStatus() {
267267
}
268268

269269
public static String maskOutSensitiveInfo(String strInput) {
270-
if (ConfigManager.IsDebugEnabled())
271-
return strInput;
272-
273270
if (strInput == null || strInput.isBlank())
274271
return strInput;
275272

276273
String maskedInput = strInput;
277274

278-
String[] sensitiveKeys = {
279-
"password", "secret", "token", "key", "private", "client_secret", "authclientsecret"
280-
};
281-
282-
for (String key : sensitiveKeys) {
283-
String regex = "(?i)(\"[^\"]*" + key + "[^\"]*\"\\s*:\\s*\")(.*?)(\")";
284-
maskedInput = maskedInput.replaceAll(regex, "$1***** MASKED *****$3");
275+
// In debug mode skip key/token masking so full payloads remain visible,
276+
// but always mask large binary payloads to keep the report size manageable.
277+
if (!ConfigManager.IsDebugEnabled()) {
278+
String[] sensitiveKeys = {
279+
"password", "secret", "token", "key", "private", "client_secret", "authclientsecret"
280+
};
281+
for (String key : sensitiveKeys) {
282+
String regex = "(?i)(\"[^\"]*" + key + "[^\"]*\"\\s*:\\s*\")(.*?)(\")";
283+
maskedInput = maskedInput.replaceAll(regex, "$1***** MASKED *****$3");
284+
}
285+
Pattern INDIVIDUAL_BIOMETRICS_PATTERN = Pattern.compile(
286+
"\"category\"\\s*:\\s*\"individualBiometrics\"\\s*,\\s*\"value\"\\s*:\\s*\"(.*?)\"");
287+
Matcher biometricsMatcher = INDIVIDUAL_BIOMETRICS_PATTERN.matcher(maskedInput);
288+
maskedInput = biometricsMatcher.replaceAll(
289+
"\"category\": \"individualBiometrics\", \"value\": \"***** MASKED *****\"");
285290
}
286291

287-
Pattern INDIVIDUAL_BIOMETRICS_PATTERN = Pattern.compile(
288-
"\"category\"\\s*:\\s*\"individualBiometrics\"\\s*,\\s*\"value\"\\s*:\\s*\"(.*?)\"");
289-
Matcher biometricsMatcher = INDIVIDUAL_BIOMETRICS_PATTERN.matcher(maskedInput);
290-
maskedInput = biometricsMatcher.replaceAll(
291-
"\"category\": \"individualBiometrics\", \"value\": \"***** MASKED *****\"");
292+
// Always mask large base64/binary payloads regardless of debug mode --
293+
// cbeff biometrics, document files, encrypted identity data.
294+
maskedInput = maskedInput.replaceAll("\"value\"\\s*:\\s*\"([^\"]{200,})\"",
295+
"\"value\": \"***** MASKED *****\"");
296+
maskedInput = maskedInput.replaceAll("\"data\"\\s*:\\s*\"([^\"]{200,})\"",
297+
"\"data\": \"***** MASKED *****\"");
292298

293299
return maskedInput;
294300
}
@@ -335,7 +341,7 @@ public static void reportResponse(String responseHeader, String url, Response re
335341
+ GlobalConstants.REPORT_RESPONSE_SUFFIX);
336342
} else {
337343
Reporter.log(GlobalConstants.REPORT_RESPONSE_PREFIX + GlobalConstants.REPORT_RESPONSE_BODY + formattedHeader
338-
+ ReportUtil.getTextAreaJsonMsgHtml(response.asString()) + GlobalConstants.REPORT_RESPONSE_SUFFIX);
344+
+ ReportUtil.getTextAreaJsonMsgHtml(maskOutSensitiveInfo(response.asString())) + GlobalConstants.REPORT_RESPONSE_SUFFIX);
339345
}
340346
}
341347
public static void reportResponseHeader(String responseHeader, String url) {
@@ -352,12 +358,13 @@ public static void reportResponse(String responseHeader, String url, String resp
352358
public static void reportResponse(String responseHeader, String url, String response, boolean formatResponse) {
353359
String formattedHeader = ReportUtil.getTextAreaForHeaders(responseHeader);
354360

361+
String maskedResponse = maskOutSensitiveInfo(response);
355362
if (formatResponse)
356363
Reporter.log(GlobalConstants.REPORT_RESPONSE_PREFIX + GlobalConstants.REPORT_RESPONSE_BODY + formattedHeader
357-
+ ReportUtil.getTextAreaJsonMsgHtml(response) + GlobalConstants.REPORT_RESPONSE_SUFFIX);
364+
+ ReportUtil.getTextAreaJsonMsgHtml(maskedResponse) + GlobalConstants.REPORT_RESPONSE_SUFFIX);
358365
else
359366
Reporter.log(GlobalConstants.REPORT_RESPONSE_PREFIX + GlobalConstants.REPORT_RESPONSE_BODY + responseHeader
360-
+ response + GlobalConstants.REPORT_RESPONSE_SUFFIX);
367+
+ maskedResponse + GlobalConstants.REPORT_RESPONSE_SUFFIX);
361368
}
362369

363370
// Hashes a string using SHA-256

0 commit comments

Comments
 (0)