Skip to content

Commit

Permalink
array handle in idrepo
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 9, 2024
2 parents 47fa164 + 7cc36b3 commit ca55761
Show file tree
Hide file tree
Showing 20 changed files with 204 additions and 94 deletions.
29 changes: 15 additions & 14 deletions .github/workflows/apitest-push-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,22 @@ jobs:
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

# api test commons is not migrated to java 21 so commenting out for now so that auth demo service sonar will work.

sonar_analysis:
needs: build-maven-apitest-commons
if: "${{ github.event_name != 'pull_request' }}"
uses: mosip/kattu/.github/workflows/maven-sonar-analysis.yml@master
with:
SERVICE_LOCATION: ./apitest-commons
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
ORG_KEY: ${{ secrets.ORG_KEY }}
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_SECRET: ${{ secrets.GPG_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
# sonar_analysis:
# needs: build-maven-apitest-commons
# if: "${{ github.event_name != 'pull_request' }}"
# uses: mosip/kattu/.github/workflows/maven-sonar-analysis.yml@master
# with:
# SERVICE_LOCATION: ./apitest-commons
# secrets:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# ORG_KEY: ${{ secrets.ORG_KEY }}
# OSSRH_USER: ${{ secrets.OSSRH_USER }}
# OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
# OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
# GPG_SECRET: ${{ secrets.GPG_SECRET }}
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

build-maven-authentication-demo-service:
uses: mosip/kattu/.github/workflows/maven-build.yml@master-java21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ public static void clearKeyManagerDbData() {
}
}

public static void clearKeyManagerDbDataForEsignet() {
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getKMDbUrl(), ConfigManager.getKMDbUser(),
ConfigManager.getKMDbPass(), ConfigManager.getKMDbSchema());
executeQueries(session, MosipTestRunner.getGlobalResourcePath() + "/" + "config/keyManagerDataDeleteQueriesForEsignet.txt");
public static void clearKeyManagerDbCertData() {
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getKMDbUrl(), ConfigManager.getKMDbUser(),
ConfigManager.getKMDbPass(), ConfigManager.getKMDbSchema());
executeQueries(session, MosipTestRunner.getGlobalResourcePath() + "/"
+ "config/keyManagerCertDataDeleteQueries.txt");
} catch (Exception e) {
logger.error("Error:: While executing PMS DB Quiries." + e.getMessage());
} finally {
Expand All @@ -124,12 +125,13 @@ public static void clearMasterDbData() {
}
}

public static void clearMasterDbDataForEsignet() {
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getMASTERDbUrl(), ConfigManager.getMasterDbUser(),
ConfigManager.getMasterDbPass(), ConfigManager.getMasterDbSchema());
executeQueries(session, MosipTestRunner.getGlobalResourcePath() + "/" + "config/masterDataDeleteQueriesForEsignet.txt");
public static void clearMasterDbCertData() {
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getMASTERDbUrl(), ConfigManager.getMasterDbUser(),
ConfigManager.getMasterDbPass(), ConfigManager.getMasterDbSchema());
executeQueries(session,
MosipTestRunner.getGlobalResourcePath() + "/" + "config/masterDataCertDataDeleteQueries.txt");
} catch (Exception e) {
logger.error("Error:: While executing MASTER DB Quiries." + e.getMessage());
} finally {
Expand All @@ -139,12 +141,13 @@ public static void clearMasterDbDataForEsignet() {
}
}

public static void clearIDADbDataForEsignet() {
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getIdaDbUrl(), ConfigManager.getIdaDbUser(),
ConfigManager.getPMSDbPass(), ConfigManager.getIdaDbSchema());
executeQueries(session, MosipTestRunner.getGlobalResourcePath() + "/" + "config/idaDeleteQueriesForEsignet.txt");
public static void clearIDADbCertData() {
Session session = null;
try {
session = getDataBaseConnection(ConfigManager.getIdaDbUrl(), ConfigManager.getIdaDbUser(),
ConfigManager.getPMSDbPass(), ConfigManager.getIdaDbSchema());
executeQueries(session,
MosipTestRunner.getGlobalResourcePath() + "/" + "config/idaCertDataDeleteQueries.txt");
} catch (Exception e) {
logger.error("Error:: While executing MASTER DB Quiries." + e.getMessage());
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ private String getTestCaseDescription(ITestResult result) {
Object[] parameters = result.getParameters();
if (parameters != null && parameters.length > 0 && parameters[0] instanceof TestCaseDTO) {
TestCaseDTO testCase = (TestCaseDTO) parameters[0];
System.out.println("Test Case Name: " + testCase.getDescription());
if (testCase.getDescription() == null)
return "";
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public class Root{
public Cc cc;
public String messageId;
public String type;
public String text;
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,18 @@ public static void suiteSetup() {
setReportName("auth");
BaseTestCase.currentModule = "auth";
BaseTestCase.certsForModule = "IDA";
DBManager.clearKeyManagerDbCertData();
DBManager.clearIDADbCertData();
DBManager.clearMasterDbCertData();
AuthTestsUtil.initiateAuthTest();
}
if (listOfModules.contains("idrepo")) {
setReportName("idrepo");
BaseTestCase.currentModule = "idrepo";
BaseTestCase.certsForModule = "idrepo";
DBManager.clearKeyManagerDbCertData();
DBManager.clearIDADbCertData();
DBManager.clearMasterDbCertData();
AdminTestUtil.copyIdrepoTestResource();
}
if (listOfModules.contains(GlobalConstants.MASTERDATA)) {
Expand All @@ -276,21 +282,27 @@ public static void suiteSetup() {
if (listOfModules.contains(GlobalConstants.MIMOTO)) {
BaseTestCase.currentModule = GlobalConstants.MIMOTO;
BaseTestCase.certsForModule = GlobalConstants.MIMOTO;
DBManager.clearKeyManagerDbCertData();
DBManager.clearIDADbCertData();
DBManager.clearMasterDbCertData();
setReportName(GlobalConstants.MIMOTO);
AdminTestUtil.initiateMimotoTest();
}
if (listOfModules.contains(GlobalConstants.ESIGNET)) {
BaseTestCase.currentModule = GlobalConstants.ESIGNET;
BaseTestCase.certsForModule = GlobalConstants.ESIGNET;
DBManager.clearKeyManagerDbDataForEsignet();
DBManager.clearIDADbDataForEsignet();
DBManager.clearMasterDbDataForEsignet();
DBManager.clearKeyManagerDbCertData();
DBManager.clearIDADbCertData();
DBManager.clearMasterDbCertData();
setReportName(GlobalConstants.ESIGNET);
AdminTestUtil.initiateesignetTest();
}
if (listOfModules.contains(GlobalConstants.RESIDENT)) {
BaseTestCase.currentModule = GlobalConstants.RESIDENT;
BaseTestCase.certsForModule = GlobalConstants.RESIDENT;
DBManager.clearKeyManagerDbCertData();
DBManager.clearIDADbCertData();
DBManager.clearMasterDbCertData();
setReportName(GlobalConstants.RESIDENT);
AdminTestUtil.copyResidentTestResource();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,31 @@ public CompletionStage<?> onText(WebSocket webSocket, CharSequence data, boolean
}
try {
ObjectMapper om = new ObjectMapper();
String message = "";
String address = "";

root = om.readValue(data.toString(), Root.class);
if (!parseOtp(root.html).isEmpty() || !parseAdditionalReqId(root.html).isEmpty()) {
emailNotificationMapS.put(root.to.value.get(0).address, root.html);
logger.info(" After adding to emailNotificationMap key = " + root.to.value.get(0).address + " data "
+ data + " root " + root);
if (root.type.equals("SMS")) {
message = root.subject;
address = root.to.text;

} else if (root.type.equals("MAIL")) {
message = root.html;
address = root.to.value.get(0).address;
}
else {
logger.error("Unsupported notification type. type="+ root.type);
}

if (!parseOtp(message).isEmpty() || !parseAdditionalReqId(message).isEmpty()) {
emailNotificationMapS.put(address, message);
logger.info(" After adding to emailNotificationMap key = " + address + " data " + data + " root "
+ root);
}

else {
logger.info(" Skip adding to emailNotificationMap key = " + root.to.value.get(0).address + " data "
+ data + " root " + root);
logger.info(" Skip adding to emailNotificationMap key = " + address + " data " + data + " root "
+ root);
}
} catch (Exception e) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public class AdminTestUtil extends BaseTestCase {
String regProcAutoGeneratedIdPropFileName = properties.getProperty("regProcAutoGeneratedIdPropFileName");
String mimotoAutoGeneratedIdPropFileName = properties.getProperty("mimotoAutoGeneratedIdPropFileName");
String pmsAutoGeneratedIdPropFileName = properties.getProperty("pmsAutoGeneratedIdPropFileName");
String injiCertifyAutoGeneratedIdPropFileName = properties.getProperty("injiCertifyAutoGeneratedIdPropFileName");
String fullNameForSunBirdRC = properties.getProperty("fullNameForSunBirdRC");
String dobForSunBirdRC = properties.getProperty("dobForSunBirdRC");

Expand Down Expand Up @@ -3442,6 +3443,11 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {
jsonString = replaceKeywordWithValue(jsonString, "$OIDCCLIENT$",
getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, "mosip.iam.module.clientID"));
}

if (jsonString.contains("$DOB$")) {
jsonString = replaceKeywordWithValue(jsonString, "$DOB$",
getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, "mosip.date-of-birth.pattern"));
}
if (jsonString.contains("$GETCLIENTIDFROMMIMOTOACTUATOR$")) {
jsonString = replaceKeywordWithValue(jsonString, "$GETCLIENTIDFROMMIMOTOACTUATOR$",
getValueFromMimotoActuator("configService:overrides", "mimoto.oidc.partner.clientid"));
Expand Down Expand Up @@ -4146,6 +4152,8 @@ else if (testCaseName.toLowerCase().startsWith(GlobalConstants.ESIGNET))
autoGenFileName = esignetAutoGeneratedIdPropFileName;
else if (testCaseName.toLowerCase().startsWith(GlobalConstants.PARTNERNEW))
autoGenFileName = pmsAutoGeneratedIdPropFileName;
else if (testCaseName.toLowerCase().startsWith(GlobalConstants.INJICERTIFY))
autoGenFileName = injiCertifyAutoGeneratedIdPropFileName;

else {
autoGenFileName = "default";
Expand Down Expand Up @@ -4667,7 +4675,7 @@ public static String getKeysDirPath() {
if (System.getProperty("os.name").toLowerCase().contains("windows") == false) {
certsTargetDir = "/home/mosip/authcerts";
}

logger.info("Certs target path is: " +certsTargetDir + File.separator + certsForModule + "-IDA-" + environment + ".mosip.net");
return certsTargetDir + File.separator + certsForModule + "-IDA-" + environment + ".mosip.net";
}

Expand Down Expand Up @@ -4927,7 +4935,9 @@ public static void getPasswordSaltFromKeyManager(String passwordForAddIdentity)

public static String schemaRequiredField = "";
String phoneNumber = "";
public static String phoneSchemaRegex = "^\\91[1-9][0-9]{9}$";

public static String phoneSchemaRegex = "";
public static String dateOfBirthSchemaRegex = "";
public static Double idSchemaVersion;

public static String modifySchemaGenerateHbs() {
Expand Down Expand Up @@ -6827,7 +6837,10 @@ public static String smtpOtpHandler(String inputJson, String testCaseName) {
if (emailId.endsWith(GlobalConstants.OTP_AS_PHONE))
emailId = emailId.replace(GlobalConstants.OTP_AS_PHONE, "");
logger.info(emailId);
otp = MockSMTPListener.getOtp(emailId);
if(testCaseName.contains("_EmptyChannel_Invalid_Neg"))
otp = "";
else
otp = MockSMTPListener.getOtp(emailId);
request.getJSONObject(GlobalConstants.REQUEST).put("otp", otp);
inputJson = request.toString();
}
Expand Down Expand Up @@ -7277,5 +7290,80 @@ public String getPasswordPattern() {
}
return password;
}

public static JSONArray ArrayOfJsonObjects = null;

public static JSONArray getSyncDataResponseArray() {
if (ArrayOfJsonObjects != null) {
return ArrayOfJsonObjects;
}
String url = ApplnURI + "/v1/syncdata/getcacertificates";

String token = kernelAuthLib.getTokenByRole("admin");

Response response = RestClient.getRequestWithCookie(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON,
GlobalConstants.AUTHORIZATION, token);
JSONObject responseJson = new JSONObject(response.asString());
if (responseJson.has("response") && responseJson.getJSONObject("response").has("certificateDTOList")) {
ArrayOfJsonObjects = responseJson.getJSONObject("response").getJSONArray("certificateDTOList");
}
return ArrayOfJsonObjects;
}

public static boolean IsCertSyncd(String certSubjectSubString) {
if (ArrayOfJsonObjects == null) {
ArrayOfJsonObjects = getSyncDataResponseArray();
}

if (ArrayOfJsonObjects != null) {
for (int i = 0; i < ArrayOfJsonObjects.length(); i++) {
if (ArrayOfJsonObjects.getJSONObject(i).has("certSubject") && ArrayOfJsonObjects.getJSONObject(i)
.getString("certSubject").contains(certSubjectSubString)) {
return true;
}
}
}
return false;
}

// public static boolean checkIsCertTrusted(String certIssuer, JSONArray ArrayOfJsonObjects, int recursiveCount) {
// for (int i = 0; i < ArrayOfJsonObjects.length(); i++) {
// if (ArrayOfJsonObjects.getJSONObject(i).has("certSubject")
// && ArrayOfJsonObjects.getJSONObject(i).has("certIssuer")
// && ArrayOfJsonObjects.getJSONObject(i).getString("certSubject").equals(certIssuer)) {
//
// String certSubjectValue = ArrayOfJsonObjects.getJSONObject(i).getString("certSubject");
// String certIssuerValue = ArrayOfJsonObjects.getJSONObject(i).getString("certIssuer");
//
// if (!(certSubjectValue.equals(certIssuerValue)) && recursiveCount <= 5) {
// recursiveCount++;
// return checkIsCertTrusted(certIssuerValue, ArrayOfJsonObjects, recursiveCount);
// } else if (certSubjectValue.equals(certIssuerValue)) {
// return true;
// } else {
// break;
// }
// }
// }
// return false;
// }
//
// public static boolean IsCertTrusted(String certSubjectSubString) {
// if (ArrayOfJsonObjects == null) {
// ArrayOfJsonObjects = getSyncDataResponseArray();
// }
//
// if (ArrayOfJsonObjects != null) {
// for (int i = 0; i < ArrayOfJsonObjects.length(); i++) {
// if (ArrayOfJsonObjects.getJSONObject(i).has("certSubject") && ArrayOfJsonObjects.getJSONObject(i)
// .getString("certSubject").contains(certSubjectSubString)) {
// if (ArrayOfJsonObjects.getJSONObject(i).has("certIssuer")) {
// return checkIsCertTrusted(ArrayOfJsonObjects.getJSONObject(i).getString("certIssuer"),
// ArrayOfJsonObjects, 1);
// }
// }
// }
// }
// return false;
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,12 @@ public Map<String, String> getEncryptSessionKeyValue(String jsonString) {
Map<String, String> ecryptData = new HashMap<>();
EncryptionResponseDto encryptionResponseDto = new EncryptionResponseDto();
try {
// jsonString = StringEscapeUtils.unescapeJava(jsonString);
encryptionResponseDto = encrypt(jsonString);
// JSONObject jsonobj = new JSONObject(json);
Reporter.log("<b> <u>Encryption of identity request</u> </b>");
GlobalMethods.reportRequest(null, encryptionResponseDto.toString());
ecryptData.put("key", encryptionResponseDto.getEncryptedSessionKey());
ecryptData.put("data", encryptionResponseDto.getEncryptedIdentity());
ecryptData.put("hmac", encryptionResponseDto.getRequestHMAC());


// ecryptData.put("key", jsonobj.get(key).toString());
// ecryptData.put("data", jsonobj.get(data).toString());
// ecryptData.put("hmac", jsonobj.get(hmac).toString());
ecryptData.put("thumbprint", partnerThumbPrint);
return ecryptData;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class GlobalConstants {
public static final String KYCAUTHENDPOINT = "kycAuthEndPoint";
public static final String IDP_ACCESS_TOKEN = "idpAccessToken";
public static final String RESIDENT_DEFAULT_PROPERTIES = "resident-default.properties";
// public static final String MOSIP_DATE_OF_BIRTH_PATTERN = "mosip.date-of-birth.pattern";
public static final String ESIGNET_DEFAULT_PROPERTIES = "esignet-default.properties";
public static final String MOSIP_ESIGNET_ID_TOKEN_EXPIRE_SECONDS = "mosip.esignet.id-token-expire-seconds";
public static final String MOSIP_ESIGNET_ACCESS_TOKEN_EXPIRE_SECONDS = "mosip.esignet.access-token-expire-seconds";
Expand Down Expand Up @@ -191,6 +192,7 @@ public class GlobalConstants {
public static final String REMOVE = "$REMOVE$";
public static final String PARTNER = "partner";
public static final String PARTNERNEW = "pms";
public static final String INJICERTIFY = "injicertify";
public static final String LANGNUMBER = "$LANGNUMBER$";
public static final String RESPONSE_CENTER_DETAILS = "response.centerDetails[";
public static final String TIMESLOTS_FROMTIME = "].timeSlots[0].fromTime";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ public static String getUpdatedEndPointURL(String url) {
String module = matcher.group(3);
String endpoint = version + "/" + module + "/" + matcher.group(4);

logger.info(
"Domain: " + domain + " ---- Module: " + module + " ---- End Point: " + removeNumerics(endpoint));

// Replace BaseURL if provided from outside
String newBaseURL = ConfigManager.getComponentBaseURL(module);

Expand All @@ -72,8 +69,6 @@ public static String getUpdatedEndPointURL(String url) {
String module = matcher2.group(2) != null ? matcher2.group(2) : ""; // Handle null for optional group
String version = matcher2.group(3);
String endpoint = module + "/" + version + "/" + matcher2.group(4);
logger.info(
"Domain: " + domain + " ---- Module: " + module + " ---- End Point: " + removeNumerics(endpoint));

// Replace BaseURL if provided from outside
String newBaseURL = ConfigManager.getComponentBaseURL(module);
Expand Down
Loading

0 comments on commit ca55761

Please sign in to comment.