From fded8b6cd3c818d4de22baba0762ff0d41e380f3 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Tue, 13 Oct 2015 21:24:03 -0400 Subject: [PATCH] fixed issue #383 --- .../analyzer/ArchiveAnalyzer.java | 5 +- .../analyzer/ArchiveAnalyzerTest.java | 54 +++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 dependency-check-core/src/test/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzerTest.java diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzer.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzer.java index 289b434ba..1855bb006 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzer.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzer.java @@ -26,6 +26,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; @@ -114,8 +115,8 @@ public class ArchiveAnalyzer extends AbstractFileTypeAnalyzer { static { final String additionalZipExt = Settings.getString(Settings.KEYS.ADDITIONAL_ZIP_EXTENSIONS); if (additionalZipExt != null) { - final Set ext = new HashSet(Collections.singletonList(additionalZipExt)); - ZIPPABLES.addAll(ext); + String[] ext = additionalZipExt.split("\\s*,\\s*"); + Collections.addAll(ZIPPABLES, ext); } EXTENSIONS.addAll(ZIPPABLES); } diff --git a/dependency-check-core/src/test/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzerTest.java b/dependency-check-core/src/test/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzerTest.java new file mode 100644 index 000000000..58acf2107 --- /dev/null +++ b/dependency-check-core/src/test/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzerTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2015 OWASP. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.owasp.dependencycheck.analyzer; + +import java.io.File; +import java.io.FileFilter; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; +import org.owasp.dependencycheck.BaseTest; +import org.owasp.dependencycheck.Engine; +import org.owasp.dependencycheck.dependency.Dependency; +import org.owasp.dependencycheck.utils.Settings; + +/** + * + * @author jeremy + */ +public class ArchiveAnalyzerTest extends BaseTest { + + @Before + public void setUp() { + Settings.setString(Settings.KEYS.ADDITIONAL_ZIP_EXTENSIONS, "z2, z3"); + } + + /** + * Test of analyzeFileType method, of class ArchiveAnalyzer. + */ + @Test + public void testZippableExtensions() throws Exception { + ArchiveAnalyzer instance = new ArchiveAnalyzer(); + assertTrue(instance.getFileFilter().accept(new File("c:/test.zip"))); + assertTrue(instance.getFileFilter().accept(new File("c:/test.z2"))); + assertTrue(instance.getFileFilter().accept(new File("c:/test.z3"))); + assertFalse(instance.getFileFilter().accept(new File("c:/test.z4"))); + } + +}