FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

WIP: Read metadata from result files by darkspirit510 · Pull Request #152 · OWASP-Benchmark/BenchmarkJava · GitHub

Repository navigation

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

Filter by extension

Filter by extension .java  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
package org.owasp.benchmark.score.parsers;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.json.JSONArray;
import org.json.JSONObject;
import org.owasp.benchmark.score.BenchmarkScore;
Expand All @@ -40,6 +42,8 @@ public static boolean isHorusecReport(final JSONObject json) {
}
}

private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

public TestSuiteResults parse(JSONObject json) throws Exception {
TestSuiteResults tr =
new TestSuiteResults("Horusec", false, TestSuiteResults.ToolType.SAST);
Expand All @@ -53,6 +57,9 @@ public TestSuiteResults parse(JSONObject json) throws Exception {
}
}

tr.setToolVersion(readVersion(json));
tr.setTime(calculateTime(json.getString("createdAt"), json.getString("finishedAt")));

return tr;
}

Expand Down Expand Up @@ -162,4 +169,30 @@ private int testNumber(String filename) {
private String filename(JSONObject vuln) {
return new File(vuln.getString("file")).getName();
}

private String calculateTime(String createdAt, String finishedAt) {
try {
long passedMilliseconds = unixMilliseconds(finishedAt) - unixMilliseconds(createdAt);
return TestSuiteResults.formatTime(passedMilliseconds);
} catch (Exception e) {
e.printStackTrace();
return "Unknown";
}
}

private long unixMilliseconds(String createdAt) throws ParseException {
return sdf.parse(trimAfterDot(createdAt)).getTime();
}

private String trimAfterDot(String date) {
return date.substring(0, date.indexOf('.'));
}

private String readVersion(JSONObject json) {
if (json.has("version")) {
return json.getString("version");
} else {
return "0.0.0";
}
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public static TestSuiteResults parse(JSONObject json) throws Exception {
}
}

tr.setToolVersion(readVersion(json));

return tr;
}

Expand Down Expand Up @@ -96,4 +98,8 @@ private static String filename(JSONObject finding) {
private static int testNumber(String filename) {
return Integer.parseInt(filename.substring(BenchmarkScore.TESTCASENAME.length() + 1));
}

private static String readVersion(JSONObject json) {
return json.getJSONObject("infos").getString("version").substring("Wapiti ".length());
}
}

Back | FazBrowse Home | New Git URL