mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-22 17:19:30 +01:00
Merge pull request #625 from axel3rd/MinorFixAndUTsWindowsSpaceDirectory
UTs on Windows when project path contains space & some exception review
This commit is contained in:
@@ -253,7 +253,7 @@ public class CliParserTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testParse_scan_withFileExists() throws Exception {
|
public void testParse_scan_withFileExists() throws Exception {
|
||||||
File path = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").getPath());
|
File path = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").toURI().getPath());
|
||||||
String[] args = {"-scan", path.getCanonicalPath(), "-out", "./", "-app", "test"};
|
String[] args = {"-scan", path.getCanonicalPath(), "-out", "./", "-app", "test"};
|
||||||
|
|
||||||
CliParser instance = new CliParser();
|
CliParser instance = new CliParser();
|
||||||
|
|||||||
@@ -115,7 +115,6 @@ class DriverShim implements Driver {
|
|||||||
* @throws SQLFeatureNotSupportedException thrown if the feature is not supported
|
* @throws SQLFeatureNotSupportedException thrown if the feature is not supported
|
||||||
* @see java.sql.Driver#getParentLogger()
|
* @see java.sql.Driver#getParentLogger()
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||||
//return driver.getParentLogger();
|
//return driver.getParentLogger();
|
||||||
Method m = null;
|
Method m = null;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public abstract class BaseDBTestCase extends BaseTest {
|
|||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
ZipInputStream zin = null;
|
ZipInputStream zin = null;
|
||||||
try {
|
try {
|
||||||
File path = new File(BaseDBTestCase.class.getClassLoader().getResource("data.zip").getPath());
|
File path = new File(BaseDBTestCase.class.getClassLoader().getResource("data.zip").toURI().getPath());
|
||||||
fis = new FileInputStream(path);
|
fis = new FileInputStream(path);
|
||||||
zin = new ZipInputStream(new BufferedInputStream(fis));
|
zin = new ZipInputStream(new BufferedInputStream(fis));
|
||||||
ZipEntry entry;
|
ZipEntry entry;
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ package org.owasp.dependencycheck;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Assume;
|
import org.junit.Assume;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
@@ -69,8 +71,12 @@ public class BaseTest {
|
|||||||
* @return the resource as an File
|
* @return the resource as an File
|
||||||
*/
|
*/
|
||||||
public static File getResourceAsFile(Object o, String resource) {
|
public static File getResourceAsFile(Object o, String resource) {
|
||||||
File f = new File(o.getClass().getClassLoader().getResource(resource).getPath());
|
try{
|
||||||
Assume.assumeTrue(String.format("%n%n[SEVERE] Unable to load resource for test case: %s%n%n", resource), f.exists());
|
File f = new File(o.getClass().getClassLoader().getResource(resource).toURI().getPath());
|
||||||
return f;
|
Assume.assumeTrue(String.format("%n%n[SEVERE] Unable to load resource for test case: %s%n%n", resource), f.exists());
|
||||||
|
return f;
|
||||||
|
}catch (URISyntaxException e){
|
||||||
|
throw new UnsupportedOperationException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ public class UpdateableNvdCveTest extends BaseTest {
|
|||||||
public void testIsUpdateNeeded() throws MalformedURLException, DownloadFailedException, IOException {
|
public void testIsUpdateNeeded() throws MalformedURLException, DownloadFailedException, IOException {
|
||||||
String id = "key";
|
String id = "key";
|
||||||
//use a local file as this test will load the result and check the timestamp
|
//use a local file as this test will load the result and check the timestamp
|
||||||
File f = new File("target/test-classes/nvdcve-2.0-2012.xml");
|
String url = new File("target/test-classes/nvdcve-2.0-2012.xml").toURI().toString();
|
||||||
String url = "file:///" + f.getCanonicalPath();
|
|
||||||
UpdateableNvdCve instance = new UpdateableNvdCve();
|
UpdateableNvdCve instance = new UpdateableNvdCve();
|
||||||
instance.add(id, url, url, false);
|
instance.add(id, url, url, false);
|
||||||
|
|
||||||
@@ -64,9 +63,8 @@ public class UpdateableNvdCveTest extends BaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testAdd_3args() throws Exception {
|
public void testAdd_3args() throws Exception {
|
||||||
String id = "key";
|
String id = "key";
|
||||||
File f = new File("target/test-classes/nvdcve-2.0-2012.xml");
|
|
||||||
//use a local file as this test will load the result and check the timestamp
|
//use a local file as this test will load the result and check the timestamp
|
||||||
String url = "file:///" + f.getCanonicalPath();
|
String url = "file:///" + new File("target/test-classes/nvdcve-2.0-2012.xml").toURI().toString();
|
||||||
UpdateableNvdCve instance = new UpdateableNvdCve();
|
UpdateableNvdCve instance = new UpdateableNvdCve();
|
||||||
instance.add(id, url, url);
|
instance.add(id, url, url);
|
||||||
NvdCveInfo results = instance.get(id);
|
NvdCveInfo results = instance.get(id);
|
||||||
@@ -82,8 +80,7 @@ public class UpdateableNvdCveTest extends BaseTest {
|
|||||||
public void testAdd_4args() throws Exception {
|
public void testAdd_4args() throws Exception {
|
||||||
String id = "key";
|
String id = "key";
|
||||||
//use a local file as this test will load the result and check the timestamp
|
//use a local file as this test will load the result and check the timestamp
|
||||||
File f = new File("target/test-classes/nvdcve-2.0-2012.xml");
|
String url = new File("target/test-classes/nvdcve-2.0-2012.xml").toURI().toString();
|
||||||
String url = "file:///" + f.getCanonicalPath();
|
|
||||||
UpdateableNvdCve instance = new UpdateableNvdCve();
|
UpdateableNvdCve instance = new UpdateableNvdCve();
|
||||||
instance.add(id, url, url, false);
|
instance.add(id, url, url, false);
|
||||||
|
|
||||||
@@ -107,8 +104,7 @@ public class UpdateableNvdCveTest extends BaseTest {
|
|||||||
public void testClear() throws MalformedURLException, DownloadFailedException, IOException {
|
public void testClear() throws MalformedURLException, DownloadFailedException, IOException {
|
||||||
String id = "key";
|
String id = "key";
|
||||||
//use a local file as this test will load the result and check the timestamp
|
//use a local file as this test will load the result and check the timestamp
|
||||||
File f = new File("target/test-classes/nvdcve-2.0-2012.xml");
|
String url = new File("target/test-classes/nvdcve-2.0-2012.xml").toURI().toString();
|
||||||
String url = "file:///" + f.getCanonicalPath();
|
|
||||||
UpdateableNvdCve instance = new UpdateableNvdCve();
|
UpdateableNvdCve instance = new UpdateableNvdCve();
|
||||||
instance.add(id, url, url, false);
|
instance.add(id, url, url, false);
|
||||||
assertFalse(instance.getCollection().isEmpty());
|
assertFalse(instance.getCollection().isEmpty());
|
||||||
@@ -122,8 +118,7 @@ public class UpdateableNvdCveTest extends BaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIterator() throws IOException {
|
public void testIterator() throws IOException {
|
||||||
//use a local file as this test will load the result and check the timestamp
|
//use a local file as this test will load the result and check the timestamp
|
||||||
File f = new File("target/test-classes/nvdcve-2.0-2012.xml");
|
String url = new File("target/test-classes/nvdcve-2.0-2012.xml").toURI().toString();
|
||||||
String url = "file:///" + f.getCanonicalPath();
|
|
||||||
UpdateableNvdCve instance = new UpdateableNvdCve();
|
UpdateableNvdCve instance = new UpdateableNvdCve();
|
||||||
instance.add("one", url, url, false);
|
instance.add("one", url, url, false);
|
||||||
instance.add("two", url, url, false);
|
instance.add("two", url, url, false);
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public final class Downloader {
|
|||||||
org.apache.commons.io.FileUtils.copyFile(file, outputPath);
|
org.apache.commons.io.FileUtils.copyFile(file, outputPath);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
final String msg = format("Download failed, unable to copy '%s' to '%s'", url.toString(), outputPath.getAbsolutePath());
|
final String msg = format("Download failed, unable to copy '%s' to '%s'", url.toString(), outputPath.getAbsolutePath());
|
||||||
throw new DownloadFailedException(msg);
|
throw new DownloadFailedException(msg, ex);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final String msg = format("Download failed, file ('%s') does not exist", url.toString());
|
final String msg = format("Download failed, file ('%s') does not exist", url.toString());
|
||||||
@@ -186,7 +186,7 @@ public final class Downloader {
|
|||||||
final String msg = format("Error saving '%s' to file '%s'%nConnection Timeout: %d%nEncoding: %s%n",
|
final String msg = format("Error saving '%s' to file '%s'%nConnection Timeout: %d%nEncoding: %s%n",
|
||||||
url.toString(), outputPath.getAbsolutePath(), conn.getConnectTimeout(), encoding);
|
url.toString(), outputPath.getAbsolutePath(), conn.getConnectTimeout(), encoding);
|
||||||
throw new DownloadFailedException(msg, ex);
|
throw new DownloadFailedException(msg, ex);
|
||||||
} catch (Throwable ex) {
|
} catch (Exception ex) {
|
||||||
final String msg = format("Unexpected exception saving '%s' to file '%s'%nConnection Timeout: %d%nEncoding: %s%n",
|
final String msg = format("Unexpected exception saving '%s' to file '%s'%nConnection Timeout: %d%nEncoding: %s%n",
|
||||||
url.toString(), outputPath.getAbsolutePath(), conn.getConnectTimeout(), encoding);
|
url.toString(), outputPath.getAbsolutePath(), conn.getConnectTimeout(), encoding);
|
||||||
throw new DownloadFailedException(msg, ex);
|
throw new DownloadFailedException(msg, ex);
|
||||||
@@ -249,7 +249,7 @@ public final class Downloader {
|
|||||||
lastModifiedFile = new File(url.toURI());
|
lastModifiedFile = new File(url.toURI());
|
||||||
} catch (URISyntaxException ex) {
|
} catch (URISyntaxException ex) {
|
||||||
final String msg = format("Unable to locate '%s'", url.toString());
|
final String msg = format("Unable to locate '%s'", url.toString());
|
||||||
throw new DownloadFailedException(msg);
|
throw new DownloadFailedException(msg, ex);
|
||||||
}
|
}
|
||||||
timestamp = lastModifiedFile.lastModified();
|
timestamp = lastModifiedFile.lastModified();
|
||||||
} else {
|
} else {
|
||||||
@@ -281,7 +281,7 @@ public final class Downloader {
|
|||||||
return getLastModified(url, true);
|
return getLastModified(url, true);
|
||||||
}
|
}
|
||||||
} catch (InvalidSettingException ex1) {
|
} catch (InvalidSettingException ex1) {
|
||||||
LOGGER.debug("invalid setting?", ex);
|
LOGGER.debug("invalid setting?", ex1);
|
||||||
}
|
}
|
||||||
throw new DownloadFailedException(format("Error making HTTP %s request.", httpMethod), ex);
|
throw new DownloadFailedException(format("Error making HTTP %s request.", httpMethod), ex);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -351,6 +351,9 @@ public final class Downloader {
|
|||||||
try {
|
try {
|
||||||
quickQuery = Settings.getBoolean(Settings.KEYS.DOWNLOADER_QUICK_QUERY_TIMESTAMP, true);
|
quickQuery = Settings.getBoolean(Settings.KEYS.DOWNLOADER_QUICK_QUERY_TIMESTAMP, true);
|
||||||
} catch (InvalidSettingException e) {
|
} catch (InvalidSettingException e) {
|
||||||
|
if (LOGGER.isTraceEnabled()){
|
||||||
|
LOGGER.trace("Invalid settings : {}", e.getMessage(), e);
|
||||||
|
}
|
||||||
quickQuery = true;
|
quickQuery = true;
|
||||||
}
|
}
|
||||||
return quickQuery;
|
return quickQuery;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class ChecksumTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetChecksum() throws Exception {
|
public void testGetChecksum() throws Exception {
|
||||||
String algorithm = "MD5";
|
String algorithm = "MD5";
|
||||||
File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").getPath());
|
File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").toURI().getPath());
|
||||||
byte[] expResult = {-16, -111, 92, 95, 70, -72, -49, -94, -125, -27, -83, 103, -96, -101, 55, -109};
|
byte[] expResult = {-16, -111, 92, 95, 70, -72, -49, -94, -125, -27, -83, 103, -96, -101, 55, -109};
|
||||||
byte[] result = Checksum.getChecksum(algorithm, file);
|
byte[] result = Checksum.getChecksum(algorithm, file);
|
||||||
boolean arraysAreEqual = true;
|
boolean arraysAreEqual = true;
|
||||||
@@ -94,7 +94,7 @@ public class ChecksumTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetMD5Checksum() throws Exception {
|
public void testGetMD5Checksum() throws Exception {
|
||||||
File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").getPath());
|
File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").toURI().getPath());
|
||||||
//String expResult = "F0915C5F46B8CFA283E5AD67A09B3793";
|
//String expResult = "F0915C5F46B8CFA283E5AD67A09B3793";
|
||||||
String expResult = "f0915c5f46b8cfa283e5ad67a09b3793";
|
String expResult = "f0915c5f46b8cfa283e5ad67a09b3793";
|
||||||
String result = Checksum.getMD5Checksum(file);
|
String result = Checksum.getMD5Checksum(file);
|
||||||
@@ -108,7 +108,7 @@ public class ChecksumTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetSHA1Checksum() throws Exception {
|
public void testGetSHA1Checksum() throws Exception {
|
||||||
File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").getPath());
|
File file = new File(this.getClass().getClassLoader().getResource("checkSumTest.file").toURI().getPath());
|
||||||
//String expResult = "B8A9FF28B21BCB1D0B50E24A5243D8B51766851A";
|
//String expResult = "B8A9FF28B21BCB1D0B50E24A5243D8B51766851A";
|
||||||
String expResult = "b8a9ff28b21bcb1d0b50e24a5243d8b51766851a";
|
String expResult = "b8a9ff28b21bcb1d0b50e24a5243d8b51766851a";
|
||||||
String result = Checksum.getSHA1Checksum(file);
|
String result = Checksum.getSHA1Checksum(file);
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
package org.owasp.dependencycheck.utils;
|
package org.owasp.dependencycheck.utils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.owasp.dependencycheck.utils.Downloader;
|
import org.owasp.dependencycheck.utils.Downloader;
|
||||||
@@ -31,9 +30,7 @@ public class DownloaderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetLastModified_file() throws Exception {
|
public void testGetLastModified_file() throws Exception {
|
||||||
File f = new File("target/test-classes/dependencycheck.properties");
|
long timestamp = Downloader.getLastModified(new File("target/test-classes/dependencycheck.properties").toURI().toURL());
|
||||||
URL url = new URL("file:///" + f.getCanonicalPath());
|
|
||||||
long timestamp = Downloader.getLastModified(url);
|
|
||||||
assertTrue("timestamp equal to zero?", timestamp > 0);
|
assertTrue("timestamp equal to zero?", timestamp > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user