diff --git a/dependency-check-core/src/test/java/org/owasp/dependencycheck/xml/XmlEntityTest.java b/dependency-check-core/src/test/java/org/owasp/dependencycheck/xml/XmlEntityTest.java new file mode 100644 index 000000000..53f2cc3d8 --- /dev/null +++ b/dependency-check-core/src/test/java/org/owasp/dependencycheck/xml/XmlEntityTest.java @@ -0,0 +1,59 @@ +/* + * This file is part of dependency-check-core. + * + * 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. + * + * Copyright (c) 2017 Jeremy Long. All Rights Reserved. + */ +package org.owasp.dependencycheck.xml; + +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.*; + +/** + * + * @author Jeremy Long + */ +public class XmlEntityTest { + + /** + * Test of fromNamedReference method, of class XmlEntity. + */ + @Test + public void testFromNamedReference() { + CharSequence s = null; + String expResult = null; + String result = XmlEntity.fromNamedReference(s); + assertEquals(expResult, result); + + s = "somethingWrong"; + expResult = null; + result = XmlEntity.fromNamedReference(s); + assertEquals(expResult, result); + + s = "amp"; + expResult = "&"; + result = XmlEntity.fromNamedReference(s); + assertEquals(expResult, result); + + s = "acute"; + expResult = "´"; + result = XmlEntity.fromNamedReference(s); + assertEquals(expResult, result); + } + +} diff --git a/dependency-check-core/src/test/java/org/owasp/dependencycheck/xml/XmlInputStreamTest.java b/dependency-check-core/src/test/java/org/owasp/dependencycheck/xml/XmlInputStreamTest.java new file mode 100644 index 000000000..cd2e44504 --- /dev/null +++ b/dependency-check-core/src/test/java/org/owasp/dependencycheck/xml/XmlInputStreamTest.java @@ -0,0 +1,138 @@ +/* + * This file is part of dependency-check-core. + * + * 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. + * + * Copyright (c) 2017 Jeremy Long. All Rights Reserved. + */ +package org.owasp.dependencycheck.xml; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author jerem + */ +public class XmlInputStreamTest { + + /** + * Test of length method, of class XmlInputStream. + */ + @Test + public void testLength() { + String data = ""; + InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); + XmlInputStream instance = new XmlInputStream(stream); + int expResult = 0; + int result = instance.length(); + assertEquals(expResult, result); + + data = "Input data"; + stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); + instance = new XmlInputStream(stream); + result = instance.length(); + assertTrue(result > 0); + } + + /** + * Test of read method, of class XmlInputStream. + */ + @Test + public void testRead_0args() throws Exception { + String data = ""; + InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); + XmlInputStream instance = new XmlInputStream(stream); + int expResult = -1; + int result = instance.read(); + assertEquals(expResult, result); + + data = "*"; + stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); + instance = new XmlInputStream(stream); + expResult = 42; + result = instance.read(); + assertEquals(expResult, result); + } + + /** + * Test of read method, of class XmlInputStream. + */ + @Test + public void testRead_3args() throws Exception { + byte[] data = new byte[10]; + int offset = 0; + int length = 10; + byte[] expected = "abcdefghij".getBytes(StandardCharsets.UTF_8); + String text = "abcdefghijklmnopqrstuvwxyz"; + InputStream stream = new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)); + XmlInputStream instance = new XmlInputStream(stream); + int expResult = 10; + int result = instance.read(data, offset, length); + assertEquals(expResult, result); + assertArrayEquals(expected, data); + + + data = new byte[5]; + offset = 0; + length = 5; + expected = "&".getBytes(StandardCharsets.UTF_8); + text = "&"; + stream = new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)); + instance = new XmlInputStream(stream); + expResult = 5; + result = instance.read(data, offset, length); + assertEquals(expResult, result); + assertArrayEquals(expected, data); + + data = new byte[10]; + offset = 0; + length = 10; + expected = "& test".getBytes(StandardCharsets.UTF_8); + text = "& test"; + stream = new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)); + instance = new XmlInputStream(stream); + expResult = 10; + result = instance.read(data, offset, length); + assertEquals(expResult, result); + assertArrayEquals(expected, data); + } + + /** + * Test of toString method, of class XmlInputStream. + */ + @Test + public void testToString() throws IOException { + String data = "test"; + InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); + XmlInputStream instance = new XmlInputStream(stream); + int r = instance.read(); + String expResult = "[1]-\"t\" ( 74)"; + String result = instance.toString(); + assertEquals(expResult, result); + r = instance.read(); + expResult = "[2]-\"te\" ( 74 65)"; + result = instance.toString(); + assertEquals(expResult, result); + + } +} diff --git a/dependency-check-maven/src/it/710-pom-parse-error/invoker.properties b/dependency-check-maven/src/it/710-pom-parse-error/invoker.properties new file mode 100644 index 000000000..693fb2637 --- /dev/null +++ b/dependency-check-maven/src/it/710-pom-parse-error/invoker.properties @@ -0,0 +1,19 @@ +# +# This file is part of dependency-check-maven. +# +# 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. +# +# Copyright (c) 2014 Jeremy Long. All Rights Reserved. +# + +invoker.goals = install ${project.groupId}:${project.artifactId}:${project.version}:check -X -Dformat=ALL diff --git a/dependency-check-maven/src/it/710-pom-parse-error/pom.xml b/dependency-check-maven/src/it/710-pom-parse-error/pom.xml new file mode 100644 index 000000000..0adbf19b9 --- /dev/null +++ b/dependency-check-maven/src/it/710-pom-parse-error/pom.xml @@ -0,0 +1,32 @@ + + + + 4.0.0 + org.owasp.test + pom-parse-error + 1.0.0-SNAPSHOT + jar + + + qdox + qdox + 1.6.1 + + + \ No newline at end of file diff --git a/dependency-check-maven/src/it/710-pom-parse-error/prebuild.groovy b/dependency-check-maven/src/it/710-pom-parse-error/prebuild.groovy new file mode 100644 index 000000000..9eff4bb5c --- /dev/null +++ b/dependency-check-maven/src/it/710-pom-parse-error/prebuild.groovy @@ -0,0 +1,17 @@ +/* + * This file is part of dependency-check-maven. + * + * 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. + * + * Copyright (c) 2014 Jeremy Long. All Rights Reserved. + */