mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-24 10:01:35 +01:00
test cases for fix of issue #710
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
32
dependency-check-maven/src/it/710-pom-parse-error/pom.xml
Normal file
32
dependency-check-maven/src/it/710-pom-parse-error/pom.xml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
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) 2017 Jeremy Long. All Rights Reserved.
|
||||||
|
-->
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.owasp.test</groupId>
|
||||||
|
<artifactId>pom-parse-error</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>qdox</groupId>
|
||||||
|
<artifactId>qdox</artifactId>
|
||||||
|
<version>1.6.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
@@ -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.
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user