From f461d8da9d7d9d3959cb70e2defb97cde93a2eab Mon Sep 17 00:00:00 2001 From: Ark2307 Date: Mon, 20 Jan 2025 11:56:38 +0530 Subject: [PATCH] Adding query params support via payload keys in configs --- .../java/com/akto/testing/ApiExecutor.java | 7 ++++ .../src/main/java/com/akto/testing/Utils.java | 39 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/libs/utils/src/main/java/com/akto/testing/ApiExecutor.java b/libs/utils/src/main/java/com/akto/testing/ApiExecutor.java index fd9a6bedde..50abfa6035 100644 --- a/libs/utils/src/main/java/com/akto/testing/ApiExecutor.java +++ b/libs/utils/src/main/java/com/akto/testing/ApiExecutor.java @@ -412,6 +412,13 @@ private static void calculateFinalRequestFromAdvancedSettings(OriginalHttpReques payloadConditions.getOrDefault(TestEditorEnums.NonTerminalExecutorDataOperands.ADD_BODY_PARAM.name(), emptyList), payloadConditions.getOrDefault(TestEditorEnums.TerminalExecutorDataOperands.DELETE_BODY_PARAM.name(), emptyList) ); + + // modify query params as well from payload conditions only, not handling query conditions separately for now + Utils.modifyQueryOperations(originalHttpRequest, + payloadConditions.getOrDefault(TestEditorEnums.NonTerminalExecutorDataOperands.MODIFY_BODY_PARAM.name(), emptyList), + emptyList, + payloadConditions.getOrDefault(TestEditorEnums.TerminalExecutorDataOperands.DELETE_BODY_PARAM.name(), emptyList) + ); } private static OriginalHttpResponse sendWithRequestBody(OriginalHttpRequest request, Request.Builder builder, boolean followRedirects, boolean debug, List testLogs, boolean skipSSRFCheck, String requestProtocol) throws Exception { diff --git a/libs/utils/src/main/java/com/akto/testing/Utils.java b/libs/utils/src/main/java/com/akto/testing/Utils.java index 71ce70c3e1..8aef6d7950 100644 --- a/libs/utils/src/main/java/com/akto/testing/Utils.java +++ b/libs/utils/src/main/java/com/akto/testing/Utils.java @@ -432,6 +432,45 @@ public static void modifyHeaderOperations(OriginalHttpRequest httpRequest, List< } + public static void modifyQueryOperations(OriginalHttpRequest httpRequest, List modifyOperations, List addOperations, List deleteOperations){ + + // since this is being used with payload conditions, we are not supporting any add operations, operations are done only on existing query keys + + String query = httpRequest.getQueryParams(); + if(query == null || query.isEmpty()){ + return ; + } + + BasicDBObject queryParamObj = RequestTemplate.getQueryJSON(httpRequest.getUrl() + "?" + query); + + if(!modifyOperations.isEmpty()){ + for(ConditionsType condition : modifyOperations){ + if(queryParamObj.containsKey(condition.getKey())){ + queryParamObj.put(condition.getKey(), condition.getValue()); + } + } + } + + + if(!deleteOperations.isEmpty()){ + for(ConditionsType condition : deleteOperations){ + if(queryParamObj.containsKey(condition.getKey())){ + queryParamObj.remove(condition.getKey()); + } + } + } + + String queryParams = ""; + for (String key: queryParamObj.keySet()) { + queryParams += (key + "=" + queryParamObj.get(key) + "&"); + } + if (queryParams.length() > 0) { + queryParams = queryParams.substring(0, queryParams.length() - 1); + } + + httpRequest.setQueryParams(queryParams); + } + public static Map finalCountIssuesMap(ObjectId testingRunResultSummaryId){ Map countIssuesMap = new HashMap<>(); countIssuesMap.put(Severity.HIGH.toString(), 0);