From 92581b251379de11950a4a96d444ce577d131d1d Mon Sep 17 00:00:00 2001 From: Anup Nehe Date: Tue, 24 Dec 2024 10:08:01 +0530 Subject: [PATCH 1/8] MOSIP-38558 Signed-off-by: Anup Nehe --- .../testrig/apirig/utils/AdminTestUtil.java | 56 ++++++++++++++++++- .../apirig/utils/KernelAuthentication.java | 7 ++- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java index 61c9584933..633e71da8c 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java @@ -1508,7 +1508,7 @@ protected Response getWithPathParamAndCookieForAutoGeneratedIdForKeyCloak(String } } - public String encodeBase64(String value) { + public static String encodeBase64(String value) { String encodedStr; try { Encoder encoder = Base64.getEncoder(); @@ -1983,13 +1983,18 @@ protected Response postWithPathParamsBodyAndCookie(String url, String jsonInput, String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName); url = uriKeyWordHandelerUri(url, testCaseName); JSONObject req = new JSONObject(inputJson); + JSONObject requestObject = req.getJSONObject("request"); HashMap pathParamsMap = new HashMap<>(); String[] params = pathParams.split(","); for (String param : params) { if (req.has(param)) { pathParamsMap.put(param, req.get(param).toString()); req.remove(param); - } else + } else if (req.has("request")) { + pathParamsMap.put(param, requestObject.get(param).toString()); + requestObject.remove(param); + } + else logger.error(GlobalConstants.ERROR_STRING_2 + param + GlobalConstants.IN_STRING + inputJson); } @@ -2006,6 +2011,46 @@ protected Response postWithPathParamsBodyAndCookie(String url, String jsonInput, return response; } } + + + protected Response postWithPathParamsBodyAndCookieForAutoGeneratedId(String url, String jsonInput, String cookieName, String role, + String testCaseName, String pathParams,String idKeyName) { + Response response = null; + String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName); + url = uriKeyWordHandelerUri(url, testCaseName); + JSONObject req = new JSONObject(inputJson); + JSONObject requestObject = req.getJSONObject("request"); + HashMap pathParamsMap = new HashMap<>(); + String[] params = pathParams.split(","); + for (String param : params) { + if (req.has(param)) { + pathParamsMap.put(param, req.get(param).toString()); + req.remove(param); + } else if (req.has("request")) { + pathParamsMap.put(param, requestObject.get(param).toString()); + requestObject.remove(param); + } + else + logger.error(GlobalConstants.ERROR_STRING_2 + param + GlobalConstants.IN_STRING + inputJson); + } + + token = kernelAuthLib.getTokenByRole(role); + logger.info(GlobalConstants.POST_REQ_URL + url); + GlobalMethods.reportRequest(null, inputJson, url); + try { + response = RestClient.postWithPathParamsBodyAndCookie(url, pathParamsMap, req.toString(), + MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, cookieName, token); + GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response); + if (testCaseName.toLowerCase().contains("_sid")) { + writeAutoGeneratedId(response, idKeyName, testCaseName); + } + return response; + } catch (Exception e) { + logger.error(GlobalConstants.EXCEPTION_STRING_2 + e); + return response; + } + + } protected Response postWithPathParamsBodyHeaderAndCookie(String url, String jsonInput, String cookieName, String role, String testCaseName, String pathParams) { @@ -2095,13 +2140,18 @@ protected Response patchWithPathParamsBodyAndCookie(String url, String jsonInput Response response = null; String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName); JSONObject req = new JSONObject(inputJson); + JSONObject requestObject = req.getJSONObject("request"); HashMap pathParamsMap = new HashMap<>(); String[] params = pathParams.split(","); for (String param : params) { if (req.has(param)) { pathParamsMap.put(param, req.get(param).toString()); req.remove(param); - } else + }else if (req.has("request")) { + pathParamsMap.put(param, requestObject.get(param).toString()); + requestObject.remove(param); + } + else logger.error(GlobalConstants.ERROR_STRING_2 + param + GlobalConstants.IN_STRING + inputJson); } diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/KernelAuthentication.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/KernelAuthentication.java index 7afbc6e8c2..50dad8d19c 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/KernelAuthentication.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/KernelAuthentication.java @@ -182,9 +182,10 @@ public String getTokenByRole(String role, String tokenType) { case "invalid": return "anyRandomString"; case "invalidtoken": - String encodingToken = "AnyRandomString-ToCreate-Jwt"; - invalidcookie = kernelAuthLib.encodeBase64(encodingToken); - return invalidcookie; +// String encodingToken = "AnyRandomString-ToCreate-Jwt"; + return kernelAuthLib.encodeBase64("AnyRandomString-ToCreate-Jwt"); +// invalidcookie = +// return invalidcookie; case "regAdmin": if (!kernelCmnLib.isValidToken(regAdminCookie)) regAdminCookie = kernelAuthLib.getAuthForRegistrationAdmin(); From 77b185ec2638815ce3ace3640ce93d8298d76a88 Mon Sep 17 00:00:00 2001 From: Anup Nehe Date: Tue, 24 Dec 2024 10:19:02 +0530 Subject: [PATCH 2/8] resolve conflicts Signed-off-by: Anup Nehe --- .../io/mosip/testrig/apirig/utils/KernelAuthentication.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/KernelAuthentication.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/KernelAuthentication.java index 50dad8d19c..e3f1a27089 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/KernelAuthentication.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/KernelAuthentication.java @@ -182,10 +182,7 @@ public String getTokenByRole(String role, String tokenType) { case "invalid": return "anyRandomString"; case "invalidtoken": -// String encodingToken = "AnyRandomString-ToCreate-Jwt"; return kernelAuthLib.encodeBase64("AnyRandomString-ToCreate-Jwt"); -// invalidcookie = -// return invalidcookie; case "regAdmin": if (!kernelCmnLib.isValidToken(regAdminCookie)) regAdminCookie = kernelAuthLib.getAuthForRegistrationAdmin(); From 97f26f4b97be29eb436760100701d513f482b016 Mon Sep 17 00:00:00 2001 From: Anup Nehe Date: Thu, 2 Jan 2025 15:51:24 +0530 Subject: [PATCH 3/8] resolve conflicts Signed-off-by: Anup Nehe --- .../java/io/mosip/testrig/apirig/utils/AdminTestUtil.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java index 7a096864d1..2b36566449 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java @@ -1983,16 +1983,12 @@ protected Response postWithPathParamsBodyAndCookie(String url, String jsonInput, String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName); url = uriKeyWordHandelerUri(url, testCaseName); JSONObject req = new JSONObject(inputJson); - JSONObject requestObject = req.getJSONObject("request"); HashMap pathParamsMap = new HashMap<>(); String[] params = pathParams.split(","); for (String param : params) { if (req.has(param)) { pathParamsMap.put(param, req.get(param).toString()); req.remove(param); - } else if (req.has("request")) { - pathParamsMap.put(param, requestObject.get(param).toString()); - requestObject.remove(param); } else logger.error(GlobalConstants.ERROR_STRING_2 + param + GlobalConstants.IN_STRING + inputJson); @@ -2026,9 +2022,6 @@ protected Response postWithPathParamsBodyAndCookieForAutoGeneratedId(String url, if (req.has(param)) { pathParamsMap.put(param, req.get(param).toString()); req.remove(param); - } else if (req.has("request")) { - pathParamsMap.put(param, requestObject.get(param).toString()); - requestObject.remove(param); } else logger.error(GlobalConstants.ERROR_STRING_2 + param + GlobalConstants.IN_STRING + inputJson); From 06beed6471fbd5f88a4fee932300214ae98a9753 Mon Sep 17 00:00:00 2001 From: Anup Nehe Date: Thu, 2 Jan 2025 15:59:18 +0530 Subject: [PATCH 4/8] resolve Signed-off-by: Anup Nehe --- .../main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java index 2b36566449..55d823dc48 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java @@ -1508,7 +1508,7 @@ protected Response getWithPathParamAndCookieForAutoGeneratedIdForKeyCloak(String } } - public static String encodeBase64(String value) { + public String encodeBase64(String value) { String encodedStr; try { Encoder encoder = Base64.getEncoder(); From 24f26698cb682cc1e132e9977dced00d61ff16c1 Mon Sep 17 00:00:00 2001 From: Anup Nehe Date: Thu, 2 Jan 2025 16:17:28 +0530 Subject: [PATCH 5/8] resolve conflicts Signed-off-by: Anup Nehe --- .../java/io/mosip/testrig/apirig/utils/AdminTestUtil.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java index 55d823dc48..756ae35089 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java @@ -2133,17 +2133,13 @@ protected Response patchWithPathParamsBodyAndCookie(String url, String jsonInput Response response = null; String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName); JSONObject req = new JSONObject(inputJson); - JSONObject requestObject = req.getJSONObject("request"); HashMap pathParamsMap = new HashMap<>(); String[] params = pathParams.split(","); for (String param : params) { if (req.has(param)) { pathParamsMap.put(param, req.get(param).toString()); req.remove(param); - }else if (req.has("request")) { - pathParamsMap.put(param, requestObject.get(param).toString()); - requestObject.remove(param); - } + } else logger.error(GlobalConstants.ERROR_STRING_2 + param + GlobalConstants.IN_STRING + inputJson); } From b3f57ca66b7253821d3881584d638cc048dcfd2d Mon Sep 17 00:00:00 2001 From: Anup Nehe Date: Thu, 2 Jan 2025 18:01:04 +0530 Subject: [PATCH 6/8] resolve conflicts Signed-off-by: Anup Nehe --- .../main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java index 756ae35089..fc6e33c3c7 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java @@ -1989,8 +1989,7 @@ protected Response postWithPathParamsBodyAndCookie(String url, String jsonInput, if (req.has(param)) { pathParamsMap.put(param, req.get(param).toString()); req.remove(param); - } - else + } else logger.error(GlobalConstants.ERROR_STRING_2 + param + GlobalConstants.IN_STRING + inputJson); } From c0f416089f0be68f5c7b5787ffe8249904ae0a98 Mon Sep 17 00:00:00 2001 From: Anup Nehe Date: Thu, 2 Jan 2025 18:11:02 +0530 Subject: [PATCH 7/8] resolve conflicts Signed-off-by: Anup Nehe --- .../testrig/apirig/utils/AdminTestUtil.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java index fc6e33c3c7..3babfd55cf 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java @@ -2008,21 +2008,19 @@ protected Response postWithPathParamsBodyAndCookie(String url, String jsonInput, } - protected Response postWithPathParamsBodyAndCookieForAutoGeneratedId(String url, String jsonInput, String cookieName, String role, - String testCaseName, String pathParams,String idKeyName) { + protected Response postWithPathParamsBodyAndCookieForAutoGeneratedId(String url, String jsonInput, + String cookieName, String role, String testCaseName, String pathParams, String idKeyName) { Response response = null; String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName); url = uriKeyWordHandelerUri(url, testCaseName); JSONObject req = new JSONObject(inputJson); - JSONObject requestObject = req.getJSONObject("request"); HashMap pathParamsMap = new HashMap<>(); String[] params = pathParams.split(","); for (String param : params) { if (req.has(param)) { pathParamsMap.put(param, req.get(param).toString()); req.remove(param); - } - else + } else logger.error(GlobalConstants.ERROR_STRING_2 + param + GlobalConstants.IN_STRING + inputJson); } @@ -2033,15 +2031,14 @@ protected Response postWithPathParamsBodyAndCookieForAutoGeneratedId(String url, response = RestClient.postWithPathParamsBodyAndCookie(url, pathParamsMap, req.toString(), MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, cookieName, token); GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response); + if (testCaseName.toLowerCase().contains("_sid")) { writeAutoGeneratedId(response, idKeyName, testCaseName); } - return response; } catch (Exception e) { logger.error(GlobalConstants.EXCEPTION_STRING_2 + e); - return response; } - + return response; } protected Response postWithPathParamsBodyHeaderAndCookie(String url, String jsonInput, String cookieName, @@ -2138,8 +2135,7 @@ protected Response patchWithPathParamsBodyAndCookie(String url, String jsonInput if (req.has(param)) { pathParamsMap.put(param, req.get(param).toString()); req.remove(param); - } - else + }else logger.error(GlobalConstants.ERROR_STRING_2 + param + GlobalConstants.IN_STRING + inputJson); } From 5619ee683ff057cde1dedd198dc451cd80fc0e61 Mon Sep 17 00:00:00 2001 From: Anup Nehe Date: Thu, 2 Jan 2025 18:13:54 +0530 Subject: [PATCH 8/8] resolve conflicts Signed-off-by: Anup Nehe --- .../main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java index 3babfd55cf..fb9e27d58a 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java @@ -2135,7 +2135,7 @@ protected Response patchWithPathParamsBodyAndCookie(String url, String jsonInput if (req.has(param)) { pathParamsMap.put(param, req.get(param).toString()); req.remove(param); - }else + } else logger.error(GlobalConstants.ERROR_STRING_2 + param + GlobalConstants.IN_STRING + inputJson); }