diff --git a/dependency-check-core/pom.xml b/dependency-check-core/pom.xml index c6cf0d90c..d42f4c266 100644 --- a/dependency-check-core/pom.xml +++ b/dependency-check-core/pom.xml @@ -177,6 +177,10 @@ along with Dependency-Check. If not, see . data.directory ${project.build.directory}/data + + temp.directory + ${project.build.directory}/temp + **/*IntegrationTest.java diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/DataStoreMetaInfo.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/DataStoreMetaInfo.java index 38fc77bfd..3d25c8e22 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/DataStoreMetaInfo.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/DataStoreMetaInfo.java @@ -223,7 +223,7 @@ public class DataStoreMetaInfo { * * @return the properties file */ - public File getPropertiesFile() { + public static File getPropertiesFile() { final File dataDirectory = Settings.getFile(Settings.KEYS.DATA_DIRECTORY); final File file = new File(dataDirectory, UPDATE_PROPERTIES_FILE); return file; diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/DatabaseUpdater.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/DatabaseUpdater.java index edce25bf0..9af48b57b 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/DatabaseUpdater.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/DatabaseUpdater.java @@ -260,7 +260,7 @@ public class DatabaseUpdater implements CachedWebDataSource { if (data.exists()) { FileUtils.delete(data); } - data = properties.getPropertiesFile(); + data = DataStoreMetaInfo.getPropertiesFile(); if (data.exists()) { FileUtils.delete(data); } diff --git a/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/update/DatabaseUpdaterTest.java b/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/update/DatabaseUpdater_1_Test.java similarity index 68% rename from dependency-check-core/src/test/java/org/owasp/dependencycheck/data/update/DatabaseUpdaterTest.java rename to dependency-check-core/src/test/java/org/owasp/dependencycheck/data/update/DatabaseUpdater_1_Test.java index c44730a49..b39b35954 100644 --- a/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/update/DatabaseUpdaterTest.java +++ b/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/update/DatabaseUpdater_1_Test.java @@ -20,6 +20,7 @@ package org.owasp.dependencycheck.data.update; import org.owasp.dependencycheck.data.update.DatabaseUpdater; import java.io.File; +import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -31,9 +32,9 @@ import org.owasp.dependencycheck.utils.Settings; * * @author Jeremy Long (jeremy.long@owasp.org) */ -public class DatabaseUpdaterTest { +public class DatabaseUpdater_1_Test { - public DatabaseUpdaterTest() { + public DatabaseUpdater_1_Test() { } @BeforeClass @@ -51,17 +52,28 @@ public class DatabaseUpdaterTest { old12 = Settings.getString(Settings.KEYS.CVE_MODIFIED_12_URL); old20 = Settings.getString(Settings.KEYS.CVE_MODIFIED_20_URL); - File file = new File(this.getClass().getClassLoader().getResource("nvdcve-2012.xml").toURI()); - String path = "file:///" + file.getCanonicalPath(); + File tmp = Settings.getFile(Settings.KEYS.TEMP_DIRECTORY); + if (!tmp.exists()) { + tmp.mkdirs(); + } + + File dest = new File(tmp, "data.zip"); + File file = new File(this.getClass().getClassLoader().getResource("data.zip").toURI()); + FileUtils.copyFile(file, dest); + String path = "file:///" + dest.getCanonicalPath(); + Settings.setString(Settings.KEYS.BATCH_UPDATE_URL, path); + + dest = new File(tmp, "nvdcve-2012.xml"); + file = new File(this.getClass().getClassLoader().getResource("nvdcve-2012.xml").toURI()); + FileUtils.copyFile(file, dest); + path = "file:///" + dest.getCanonicalPath(); Settings.setString(Settings.KEYS.CVE_MODIFIED_12_URL, path); + dest = new File(tmp, "nvdcve-2.0-2012.xml"); file = new File(this.getClass().getClassLoader().getResource("nvdcve-2.0-2012.xml").toURI()); - path = "file:///" + file.getCanonicalPath(); + FileUtils.copyFile(file, dest); + path = "file:///" + dest.getCanonicalPath(); Settings.setString(Settings.KEYS.CVE_MODIFIED_20_URL, path); - - file = new File(this.getClass().getClassLoader().getResource("data.zip").toURI()); - path = "file:///" + file.getCanonicalPath(); - Settings.setString(Settings.KEYS.BATCH_UPDATE_URL, path); } @After @@ -82,26 +94,4 @@ public class DatabaseUpdaterTest { instance.deleteExistingData(); instance.update(); } - - /** - * Test of update method (when in batch mode), of class DatabaseUpdater. - * - * @throws Exception - */ - @Test - public void testBatchUpdateWithoutModified() throws Exception { - //setup - consider moving this to its own test case file so it has a different setup/teardown. - final String tmp12 = Settings.getString(Settings.KEYS.CVE_MODIFIED_12_URL); - final String tmp20 = Settings.getString(Settings.KEYS.CVE_MODIFIED_20_URL); - Settings.removeProperty(Settings.KEYS.CVE_MODIFIED_12_URL); - Settings.removeProperty(Settings.KEYS.CVE_MODIFIED_20_URL); - - DatabaseUpdater instance = new DatabaseUpdater(); - instance.deleteExistingData(); - instance.update(); - - //restore defaults - Settings.setString(Settings.KEYS.CVE_MODIFIED_12_URL, tmp12); - Settings.setString(Settings.KEYS.CVE_MODIFIED_20_URL, tmp20); - } } diff --git a/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/update/DatabaseUpdater_2_Test.java b/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/update/DatabaseUpdater_2_Test.java new file mode 100644 index 000000000..4e40c0506 --- /dev/null +++ b/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/update/DatabaseUpdater_2_Test.java @@ -0,0 +1,87 @@ +/* + * This file is part of dependency-check-core. + * + * Dependency-check-core is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * Dependency-check-core is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * dependency-check-core. If not, see http://www.gnu.org/licenses/. + * + * Copyright (c) 2012 Jeremy Long. All Rights Reserved. + */ +package org.owasp.dependencycheck.data.update; + +import org.owasp.dependencycheck.data.update.DatabaseUpdater; +import java.io.File; +import org.apache.commons.io.FileUtils; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.owasp.dependencycheck.utils.Settings; + +/** + * + * @author Jeremy Long (jeremy.long@owasp.org) + */ +public class DatabaseUpdater_2_Test { + + public DatabaseUpdater_2_Test() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + private String old12; + private String old20; + + @Before + public void setUp() throws Exception { + old12 = Settings.getString(Settings.KEYS.CVE_MODIFIED_12_URL); + old20 = Settings.getString(Settings.KEYS.CVE_MODIFIED_20_URL); + Settings.removeProperty(Settings.KEYS.CVE_MODIFIED_12_URL); + Settings.removeProperty(Settings.KEYS.CVE_MODIFIED_20_URL); + + File tmp = Settings.getFile(Settings.KEYS.TEMP_DIRECTORY); + if (!tmp.exists()) { + tmp.mkdirs(); + } + + File dest = new File(tmp, "data.zip"); + File file = new File(this.getClass().getClassLoader().getResource("data.zip").toURI()); + FileUtils.copyFile(file, dest); + String path = "file:///" + dest.getCanonicalPath(); + Settings.setString(Settings.KEYS.BATCH_UPDATE_URL, path); + } + + @After + public void tearDown() { + Settings.setString(Settings.KEYS.CVE_MODIFIED_12_URL, old12); + Settings.setString(Settings.KEYS.CVE_MODIFIED_20_URL, old20); + Settings.removeProperty(Settings.KEYS.BATCH_UPDATE_URL); + } + + /** + * Test of update method (when in batch mode), of class DatabaseUpdater. + * + * @throws Exception + */ + @Test + public void testBatchUpdateWithoutModified() throws Exception { + DatabaseUpdater instance = new DatabaseUpdater(); + instance.deleteExistingData(); + instance.update(); + } +}