Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
notshivansh committed Jan 1, 2025
1 parent 56ca545 commit 8c55b2f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,11 @@ private TestingRun createTestingRun(int scheduleTimestamp, int periodInSeconds)
}
if (this.selectedTests != null) {
int id = UUID.randomUUID().hashCode() & 0xfffffff;
TestingRunConfig testingRunConfig = new TestingRunConfig(id, null, this.selectedTests, authMechanism.getId(), this.overriddenTestAppUrl, this.testRoleId);
TestingRunConfig testingRunConfig = new TestingRunConfig(id, null, this.selectedTests, authMechanism.getId(), this.overriddenTestAppUrl, this.testRoleId, this.cleanUpTestingResources);
// add advanced setting here
if(this.testConfigsAdvancedSettings != null && !this.testConfigsAdvancedSettings.isEmpty()){
testingRunConfig.setConfigsAdvancedSettings(this.testConfigsAdvancedSettings);
}
testingRunConfig.setCleanUp(this.cleanUpTestingResources);
this.testIdConfig = testingRunConfig.getId();
TestingRunConfigDao.instance.insertOne(testingRunConfig);
}
Expand Down
3 changes: 0 additions & 3 deletions libs/dao/src/main/java/com/akto/dto/traffic/SampleData.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import java.util.Arrays;
import java.util.List;

import org.bson.codecs.pojo.annotations.BsonId;

import com.akto.util.Util;

public class SampleData {
@BsonId
Key id;

public static final String SAMPLES = "samples";
Expand Down
28 changes: 1 addition & 27 deletions libs/utils/src/main/java/com/akto/testing/ApiExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,10 @@ public class ApiExecutor {
private static Map<Integer, TestScript> testScriptMap = new HashMap<>();

private static OriginalHttpResponse common(Request request, boolean followRedirects, boolean debug, List<TestingRunResult.TestLog> testLogs, boolean skipSSRFCheck, String requestProtocol) throws Exception {
debug = true;
Integer accountId = Context.accountId.get();
if (accountId != null) {
int i = 0;
boolean rateLimitHit = true;



while (RateLimitHandler.getInstance(accountId).shouldWait(request)) {
if(rateLimitHit){
if (!(request.url().toString().contains("insertRuntimeLog") || request.url().toString().contains("insertTestingLog") || request.url().toString().contains("insertProtectionLog"))) {
Expand Down Expand Up @@ -82,9 +78,6 @@ private static OriginalHttpResponse common(Request request, boolean followRedire
}

Call call = client.newCall(request);

System.out.println("------ACTUAL REQ-------");
System.out.println(request.headers());
Response response = null;
String body;
byte[] grpcBody = null;
Expand Down Expand Up @@ -341,9 +334,7 @@ public static OriginalHttpResponse sendRequest(OriginalHttpRequest request, bool
if (!(url.contains("insertRuntimeLog") || url.contains("insertTestingLog") || url.contains("insertProtectionLog"))) {
loggerMaker.infoAndAddToDb("Received response from: " + url, LogDb.TESTING);
}
System.out.println("====RESPONSE====");
System.out.println(response.getHeaders());
System.out.println(response.getBody());

return response;
}
public static OriginalHttpResponse sendRequest(OriginalHttpRequest request, boolean followRedirects, TestingRunConfig testingRunConfig, boolean debug, List<TestingRunResult.TestLog> testLogs) throws Exception {
Expand Down Expand Up @@ -397,7 +388,6 @@ public void writeTo(BufferedSink sink) throws IOException {
}

public static void calculateFinalRequestFromAdvancedSettings(OriginalHttpRequest originalHttpRequest, List<TestConfigsAdvancedSettings> advancedSettings){
System.out.println("in calculateFinalRequestFromAdvancedSettings...");
Map<String,List<ConditionsType>> headerConditions = new HashMap<>();
Map<String,List<ConditionsType>> payloadConditions = new HashMap<>();

Expand All @@ -416,14 +406,11 @@ public static void calculateFinalRequestFromAdvancedSettings(OriginalHttpRequest
headerConditions.getOrDefault(TestEditorEnums.TerminalExecutorDataOperands.DELETE_HEADER.name(), emptyList)
);

System.out.println("modifyBodyOperations calculateFinalRequestFromAdvancedSettings...");
Utils.modifyBodyOperations(originalHttpRequest,
payloadConditions.getOrDefault(TestEditorEnums.NonTerminalExecutorDataOperands.MODIFY_BODY_PARAM.name(), emptyList),
payloadConditions.getOrDefault(TestEditorEnums.NonTerminalExecutorDataOperands.ADD_BODY_PARAM.name(), emptyList),
payloadConditions.getOrDefault(TestEditorEnums.TerminalExecutorDataOperands.DELETE_BODY_PARAM.name(), emptyList)
);
System.out.println("modifyBodyOperations completed calculateFinalRequestFromAdvancedSettings...");

}

private static OriginalHttpResponse sendWithRequestBody(OriginalHttpRequest request, Request.Builder builder, boolean followRedirects, boolean debug, List<TestingRunResult.TestLog> testLogs, boolean skipSSRFCheck, String requestProtocol) throws Exception {
Expand Down Expand Up @@ -479,14 +466,6 @@ private static OriginalHttpResponse sendWithRequestBody(OriginalHttpRequest requ

if (payload == null) payload = "";

try {
System.out.println("payloadStr: " + payload);
payload = Utils.replaceVariables(payload, new HashMap<>(), false, false);
System.out.println("payloadStrFinal: " + payload);

} catch (Exception e) {
System.out.println("failed to replace vars in payload: " + e.getMessage());
}
if (body == null) {// body not created by GRPC block yet
if (request.getHeaders().containsKey("charset")) {
body = RequestBody.create(payload, null);
Expand All @@ -496,11 +475,6 @@ private static OriginalHttpResponse sendWithRequestBody(OriginalHttpRequest requ
}
}

System.out.println("====REQUEST====");
System.out.println(request.getMethod() + " " + request.getUrl() + "?" + request.getQueryParams());
System.out.println(request.getHeaders());
System.out.println(payload);

builder = builder.method(request.getMethod(), body);
Request okHttpRequest = builder.build();
return common(okHttpRequest, followRedirects, debug, testLogs, skipSSRFCheck, requestProtocol);
Expand Down
17 changes: 5 additions & 12 deletions libs/utils/src/main/java/com/akto/testing/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -217,16 +216,11 @@ public static String replaceVariables(String payload, Map<String, Object> values
if (key == null) continue;
Object obj = valuesMap.get(key);
if (obj == null) {
if (key.toLowerCase().startsWith("x0.unique_")) {
String suffix = key.substring(key.toLowerCase().indexOf("_")+1);
obj = suffix+"_"+System.nanoTime();
} else {
loggerMaker.errorAndAddToDb("couldn't find: " + key, LogDb.TESTING);
if(shouldThrowException){
throw new Exception("Couldn't find " + key);
}else{
continue;
}
loggerMaker.errorAndAddToDb("couldn't find: " + key, LogDb.TESTING);
if(shouldThrowException){
throw new Exception("Couldn't find " + key);
}else{
continue;
}
}
String val = obj.toString();
Expand Down Expand Up @@ -359,7 +353,6 @@ private static ValidationResult validate(FilterNode node, RawApi rawApi, RawApi
}

public static void modifyBodyOperations(OriginalHttpRequest httpRequest, List<ConditionsType> modifyOperations, List<ConditionsType> addOperations, List<ConditionsType> deleteOperations){
System.out.println("inside modifyBodyOperations");
String oldReqBody = httpRequest.getBody();
if(oldReqBody == null || oldReqBody.isEmpty()){
return ;
Expand Down

0 comments on commit 8c55b2f

Please sign in to comment.