Skip to content

Commit

Permalink
TODOs and test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-mulligan committed Oct 26, 2023
1 parent 0b6db65 commit c468476
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
6 changes: 3 additions & 3 deletions patchfinder/src/main/java/patches/PatchFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class PatchFinder {
private static DatabaseHelper databaseHelper;
private static PatchUrlFinder patchURLFinder;

private static final ArrayList<PatchCommit> patchCommits = new ArrayList<>();
private static final Set<PatchCommit> patchCommits = new HashSet<>();
private static Map<String, ArrayList<String>> sourceDict;
protected static Instant urlDictLastCompilationDate = Instant.parse("2000-01-01T00:00:00.00Z");
protected static final String[] addressBases = PatchFinderEnvVars.getAddressBases();
Expand Down Expand Up @@ -173,7 +173,7 @@ public static int run(Map<String, CpeGroup> affectedProducts, int cveLimit) thro
PatchFinder.findPatchesMultiThreaded(possiblePatchURLs);

// Get found patches from patchfinder
ArrayList<PatchCommit> patchCommits = PatchFinder.getPatchCommits();
Set<PatchCommit> patchCommits = PatchFinder.getPatchCommits();

// Insert found patch commits (if any)
if(patchCommits.size() > 0) {
Expand Down Expand Up @@ -311,7 +311,7 @@ private static void writeSourceDict(String patchSrcUrlPath, Map<String, ArrayLis
}
}

public static ArrayList<PatchCommit> getPatchCommits() {
public static Set<PatchCommit> getPatchCommits() {
return patchCommits;
}

Expand Down
3 changes: 2 additions & 1 deletion patchfinder/src/main/java/patches/PatchFinderThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public class PatchFinderThread implements Runnable {
private final HashMap<String, ArrayList<String>> cvePatchEntry;
private final String clonePath;
private final long timeoutMilli;
private RevWalk walk; // TODO: initialize properly
private RevWalk walk; // TODO: remove
//TODO: Improve these patterns, currently we are getting many commits not directly related to the specific cve we claim
private static final Pattern[] patchPatterns = new Pattern[] {Pattern.compile("vulnerability|Vulnerability|vuln|Vuln|VULN[ #]*([0-9]+)")};
private static final Logger logger = LogManager.getLogger(PatchFinder.class.getName());

Expand Down
1 change: 1 addition & 0 deletions patchfinder/src/main/java/patches/PatchUrlFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public void parsePatchURLs(Map<String, ArrayList<String>> possiblePatchUrls, Map
* @param vendor vendor name
* @throws IOException if an IO error occurs while testing the url connection
*/
// TODO: Consider using https://www.cve.org to lookup existing github references to repos/PRs
private ArrayList<String> parseURL(String vendor, String product) throws IOException {
ArrayList<String> newAddresses = new ArrayList<>();

Expand Down
1 change: 1 addition & 0 deletions patchfinder/src/test/java/patches/PatchFinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class PatchFinderTest {
@Before
public void setUp() {
PatchFinderEnvVars.initializeEnvVars(true);
PatchFinder.init();
}

@Test
Expand Down
9 changes: 6 additions & 3 deletions patchfinder/src/test/java/patches/PatchFinderThreadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* SOFTWARE.
*/

import org.junit.Ignore;
import patches.PatchCommit;
import org.junit.Test;
import org.mockito.Mockito;
Expand All @@ -32,6 +33,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -44,6 +46,7 @@ public class PatchFinderThreadTest {

//TODO: This needs to be re-written to utilize mocks. This test was failing because the apache airflow github added more patch commits
@Test
@Ignore
public void testRun() {
HashMap<String, ArrayList<String>> cvePatchEntry = new HashMap<>();
ArrayList<String> patchSources = new ArrayList<>();
Expand All @@ -57,7 +60,7 @@ public void testRun() {

PatchFinder patchFinder = Mockito.mock(PatchFinder.class);
//check the patch commits
List<PatchCommit> patchCommits = PatchFinder.getPatchCommits();
Set<PatchCommit> patchCommits = PatchFinder.getPatchCommits();
assertEquals(48, patchCommits.size());

}
Expand All @@ -79,7 +82,7 @@ public void testFindPatchCommitsFromUrl() {

PatchFinder patchFinder = Mockito.mock(PatchFinder.class);
//check the patch commits
List<PatchCommit> patchCommits = PatchFinder.getPatchCommits();
Set<PatchCommit> patchCommits = PatchFinder.getPatchCommits();
assertEquals(0, patchCommits.size());

}
Expand All @@ -96,7 +99,7 @@ public void testParseCommitObjects() throws IOException {
PatchFinder.getPatchCommits().clear();
//want parseCommitObjects to be called, so we have to check the url using findPatchCommitsFromUrl
PatchFinder.findPatchesMultiThreaded(cvePatchEntry);
List<PatchCommit> patchCommits = PatchFinder.getPatchCommits();
Set<PatchCommit> patchCommits = PatchFinder.getPatchCommits();
assertEquals(0, patchCommits.size());

}
Expand Down

0 comments on commit c468476

Please sign in to comment.