Skip to content

Commit

Permalink
Merge pull request #1670 from akto-api-security/feature/response_time…
Browse files Browse the repository at this point in the history
…_in_tests

add response time in multiple exec tests
  • Loading branch information
notshivansh authored Oct 26, 2024
2 parents 3aa84ce + 367fbc7 commit 2779cca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function SampleDataComponent(props) {
const [popoverActive, setPopoverActive] = useState({});
const [lineNumbers, setLineNumbers] = useState({request: [], response: []})
const [currentIndex, setCurrentIndex] = useState({request: 0, response: 0})
const [responseTime, setResponseTime] = useState(undefined)

const ref = useRef(null)

Expand All @@ -30,6 +31,9 @@ function SampleDataComponent(props) {
}
let responseJson = func.responseJson(parsed, sampleData?.highlightPaths)
let requestJson = func.requestJson(parsed, sampleData?.highlightPaths)

let responseTime = parsed?.responseTime;
setResponseTime(responseTime)

let originalParsed;
try{
Expand Down Expand Up @@ -201,7 +205,8 @@ function SampleDataComponent(props) {
<LegacyCard.Section flush>
<Box padding={"2"}>
<HorizontalStack padding="2" align='space-between'>
{func.toSentenceCase(type)}
{func.toSentenceCase(type)}
{ type=="response" && responseTime ? (` (${responseTime} ms)`) : "" }
<HorizontalStack gap={2}>
{isNewDiff ? <HorizontalStack gap="2">
<Box borderInlineEndWidth='1' borderColor="border-subdued" padding="1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,16 @@ public NodeResult processNode(Node node, Map<String, Object> varMap, Boolean all
memory.reset(apiInfoKey.getApiCollectionId(), apiInfoKey.getUrl(), apiInfoKey.getMethod().name());
}
tsAfterReq = Context.nowInMillis();
responseTimeArr.add(tsAfterReq - tsBeforeReq);
int responseTime = tsAfterReq - tsBeforeReq;
responseTimeArr.add(responseTime);
ExecutionResult attempt = new ExecutionResult(singleReq.getSuccess(), singleReq.getErrMsg(), testReq.getRequest(), testResponse);
TestResult res = executor.validate(attempt, sampleRawApi, varMap, logId, validatorNode, yamlNodeDetails.getApiInfoKey());
if (res != null) {
result.add(res);
}
vulnerable = res.getVulnerable();
try {
message.add(convertOriginalReqRespToString(testReq.getRequest(), testResponse));
message.add(convertOriginalReqRespToString(testReq.getRequest(), testResponse, responseTime));
} catch (Exception e) {
;
}
Expand Down
12 changes: 11 additions & 1 deletion libs/utils/src/main/java/com/akto/runtime/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ public static Properties configProperties(String kafkaBrokerUrl, String groupIdC
return properties;
}

public static String convertOriginalReqRespToString(OriginalHttpRequest request, OriginalHttpResponse response, int responseTime) {
BasicDBObject ret = convertOriginalReqRespToStringUtil(request, response);
ret.append("responseTime", responseTime);
return ret.toString();
}

public static String convertOriginalReqRespToString(OriginalHttpRequest request, OriginalHttpResponse response) {
return convertOriginalReqRespToStringUtil(request, response).toString();
}

public static BasicDBObject convertOriginalReqRespToStringUtil(OriginalHttpRequest request, OriginalHttpResponse response) {
BasicDBObject req = new BasicDBObject();
if (request != null) {
req.put("url", request.getUrl());
Expand All @@ -74,7 +84,7 @@ public static String convertOriginalReqRespToString(OriginalHttpRequest request,
ret.put("request", req);
ret.put("response", resp);

return ret.toString();
return ret;
}

public static Map<String,String> parseCookie(List<String> cookieList){
Expand Down

0 comments on commit 2779cca

Please sign in to comment.