mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-11 21:05:38 +01:00
change to skip and remove macOS metadata and non-zip files
This commit is contained in:
@@ -20,17 +20,18 @@ package org.owasp.dependencycheck.analyzer;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Test;
|
||||
import org.owasp.dependencycheck.BaseTest;
|
||||
import org.owasp.dependencycheck.analyzer.JarAnalyzer.ClassNameInformation;
|
||||
import org.owasp.dependencycheck.Engine;
|
||||
import org.owasp.dependencycheck.dependency.Dependency;
|
||||
import org.owasp.dependencycheck.dependency.Evidence;
|
||||
import org.owasp.dependencycheck.utils.Settings;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -176,10 +177,29 @@ public class JarAnalyzerTest extends BaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseManifest_CatchesIOException() {
|
||||
Dependency dependency = new Dependency();
|
||||
dependency.setActualFilePath("doesNotExist");
|
||||
assertFalse(new File(dependency.getActualFilePath()).exists());
|
||||
assertFalse(new JarAnalyzer().parseManifest(dependency, new ArrayList<ClassNameInformation>()));
|
||||
public void testAnalyzeDependency_SkipsMacOSMetaDataFile() throws Exception {
|
||||
JarAnalyzer instance = new JarAnalyzer();
|
||||
Dependency macOSMetaDataFile = new Dependency();
|
||||
macOSMetaDataFile
|
||||
.setActualFilePath(FileUtils.getFile("src", "test", "resources", "._avro-ipc-1.5.0.jar").getAbsolutePath());
|
||||
macOSMetaDataFile.setFileName("._avro-ipc-1.5.0.jar");
|
||||
Dependency actualJarFile = new Dependency();
|
||||
actualJarFile.setActualFilePath(BaseTest.getResourceAsFile(this, "avro-ipc-1.5.0.jar").getAbsolutePath());
|
||||
actualJarFile.setFileName("avro-ipc-1.5.0.jar");
|
||||
Engine engine = new Engine();
|
||||
engine.setDependencies(Arrays.asList(macOSMetaDataFile, actualJarFile));
|
||||
instance.analyzeDependency(macOSMetaDataFile, engine);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnalyseDependency_SkipsNonZipFile() throws Exception {
|
||||
JarAnalyzer instance = new JarAnalyzer();
|
||||
Dependency textFileWithJarExtension = new Dependency();
|
||||
textFileWithJarExtension
|
||||
.setActualFilePath(BaseTest.getResourceAsFile(this, "textFileWithJarExtension.jar").getAbsolutePath());
|
||||
textFileWithJarExtension.setFileName("textFileWithJarExtension.jar");
|
||||
Engine engine = new Engine();
|
||||
engine.setDependencies(Collections.singletonList(textFileWithJarExtension));
|
||||
instance.analyzeDependency(textFileWithJarExtension, engine);
|
||||
}
|
||||
}
|
||||
|
||||
BIN
dependency-check-core/src/test/resources/._avro-ipc-1.5.0.jar
Normal file
BIN
dependency-check-core/src/test/resources/._avro-ipc-1.5.0.jar
Normal file
Binary file not shown.
BIN
dependency-check-core/src/test/resources/avro-ipc-1.5.0.jar
Normal file
BIN
dependency-check-core/src/test/resources/avro-ipc-1.5.0.jar
Normal file
Binary file not shown.
@@ -0,0 +1 @@
|
||||
text file with jar extension
|
||||
Reference in New Issue
Block a user