Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding query params support via payload keys in configs #1998

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libs/utils/src/main/java/com/akto/testing/ApiExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,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 void calculateHashAndAddAuth(OriginalHttpRequest originalHttpRequest, boolean executeScript) {
Expand Down
40 changes: 39 additions & 1 deletion libs/utils/src/main/java/com/akto/testing/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,43 @@ public static void modifyHeaderOperations(OriginalHttpRequest httpRequest, List<


}


public static void modifyQueryOperations(OriginalHttpRequest httpRequest, List<ConditionsType> modifyOperations, List<ConditionsType> addOperations, List<ConditionsType> 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);
}
}
Loading