From 1a9214e725533cb1cd13d4cc87950747e271b0b1 Mon Sep 17 00:00:00 2001 From: thc202 Date: Tue, 15 Oct 2024 19:01:41 +0100 Subject: [PATCH] exim: import HAR entry timings Import the HAR entry sent and elapsed time when creating the HTTP messages. Signed-off-by: thc202 --- addOns/exim/CHANGELOG.md | 3 +++ .../main/java/org/zaproxy/addon/exim/har/HarImporter.java | 7 +++++++ .../org/zaproxy/addon/exim/har/HarImporterUnitTest.java | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/addOns/exim/CHANGELOG.md b/addOns/exim/CHANGELOG.md index 39e8cb3d61e..7a4d7f752ef 100644 --- a/addOns/exim/CHANGELOG.md +++ b/addOns/exim/CHANGELOG.md @@ -7,6 +7,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Maintenance changes. +### Fixed +- Import HAR entry sent and elapsed time. + ## [0.12.0] - 2024-10-07 ### Changed - Improved HTTP 1.1 traffic detection in PCAP files diff --git a/addOns/exim/src/main/java/org/zaproxy/addon/exim/har/HarImporter.java b/addOns/exim/src/main/java/org/zaproxy/addon/exim/har/HarImporter.java index e8d79bd1fc9..c402513069d 100644 --- a/addOns/exim/src/main/java/org/zaproxy/addon/exim/har/HarImporter.java +++ b/addOns/exim/src/main/java/org/zaproxy/addon/exim/har/HarImporter.java @@ -26,10 +26,13 @@ import de.sstoehr.harreader.model.HarHeader; import de.sstoehr.harreader.model.HarLog; import de.sstoehr.harreader.model.HarResponse; +import de.sstoehr.harreader.model.HarTiming; import java.io.File; import java.util.ArrayList; import java.util.Base64; +import java.util.Date; import java.util.List; +import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; @@ -216,6 +219,10 @@ private static HttpMessage getHttpMessage(HarEntry harEntry) headerEx.getMessage()); return null; } + result.setTimeSentMillis( + Optional.ofNullable(harEntry.getStartedDateTime()).map(Date::getTime).orElse(0L)); + result.setTimeElapsedMillis( + Optional.ofNullable(harEntry.getTimings()).map(HarTiming::getReceive).orElse(0)); setHttpResponse(harEntry.getResponse(), result); return result; } diff --git a/addOns/exim/src/test/java/org/zaproxy/addon/exim/har/HarImporterUnitTest.java b/addOns/exim/src/test/java/org/zaproxy/addon/exim/har/HarImporterUnitTest.java index 85c08cd516e..7e5710f927f 100644 --- a/addOns/exim/src/test/java/org/zaproxy/addon/exim/har/HarImporterUnitTest.java +++ b/addOns/exim/src/test/java/org/zaproxy/addon/exim/har/HarImporterUnitTest.java @@ -159,6 +159,10 @@ void serializedAndDeserializedShouldMatch() throws Exception { byte[] responseBody = {0x30, 0x31}; HttpMessage httpMessage = new HttpMessage(requestHeader, requestBody, responseHeader, responseBody); + long timeSentMillis = 1234L; + httpMessage.setTimeSentMillis(timeSentMillis); + int timeElapsedMillis = 42; + httpMessage.setTimeElapsedMillis(timeElapsedMillis); HarLog harLog = createHarLog(httpMessage); // When @@ -173,6 +177,8 @@ void serializedAndDeserializedShouldMatch() throws Exception { deserializedHttpMessage.getResponseHeader().toString(), is(equalTo(responseHeader))); assertThat(deserializedHttpMessage.getResponseBody().getBytes(), is(equalTo(responseBody))); + assertThat(deserializedHttpMessage.getTimeSentMillis(), is(equalTo(timeSentMillis))); + assertThat(deserializedHttpMessage.getTimeElapsedMillis(), is(equalTo(timeElapsedMillis))); } @Test