Skip to content

Commit 09fc505

Browse files
authored
test: Make tests locale independent (#8328)
1 parent 4abf47c commit 09fc505

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

core/src/test/java/org/owasp/dependencycheck/xml/hints/HintParserTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void testParseHints_File() throws Exception {
7373
* Test the application of the correct XSD by the parser by using a
7474
* hints-file with namespace
7575
* {@code https://jeremylong.github.io/DependencyCheck/dependency-hint.1.1.xsd}
76-
* that is using the version evidence for {@code<given>} that was introduced
76+
* that is using the version evidence for {@code <given>} that was introduced
7777
* with namespace
7878
* {@code https://jeremylong.github.io/DependencyCheck/dependency-hint.1.2.xsd}.
7979
* This should yield a specific SAXParseException that gets wrapped into a
@@ -85,7 +85,9 @@ void testParseHintsXSDSelection() {
8585
File file = BaseTest.getResourceAsFile(this, "hints_invalid.xml");
8686
HintParser instance = new HintParser();
8787
Exception exception = assertThrows(org.owasp.dependencycheck.xml.hints.HintParseException.class, () -> instance.parseHints(file));
88-
assertThat(exception.getMessage(), containsString("Line=10, Column=133: cvc-enumeration-valid: Value 'version' is not facet-valid with respect to enumeration '[vendor, product]'. It must be a value from the enumeration."));
88+
assertThat(exception.getMessage(), containsString("Line=10, Column=133: cvc-enumeration-valid"));
89+
assertThat(exception.getMessage(), containsString("'version'"));
90+
assertThat(exception.getMessage(), containsString("'[vendor, product]'"));
8991
}
9092

9193
/**

utils/src/test/java/org/owasp/dependencycheck/utils/XmlUtilsTest.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.xml.sax.XMLReader;
1616

1717
import javax.xml.parsers.ParserConfigurationException;
18+
import java.util.List;
1819
import java.util.stream.Stream;
1920

2021
import static org.hamcrest.MatcherAssert.assertThat;
@@ -49,28 +50,28 @@ void shouldValidateXmlSuccessfullyAgainstSchema(String xmlToValidateResource) th
4950
}
5051
}
5152

52-
static Stream<Pair<String, String>> invalidSchemaDocProvider() {
53+
static Stream<Pair<String, List<String>>> invalidSchemaDocProvider() {
5354
return Stream.of(
5455
Pair.of("schema-validation/simpledoc-invalid-schemaloc-https-badprefix.xml",
55-
"'https' access is not allowed due to restriction set by the accessExternalSchema property"),
56+
List.of("'https'", "accessExternalSchema")),
5657
Pair.of("schema-validation/simpledoc-invalid-schemaloc-https-notfound.xml",
57-
"'https' access is not allowed due to restriction set by the accessExternalSchema property"),
58+
List.of("'https'", "accessExternalSchema")),
5859
Pair.of("schema-validation/simpledoc-invalid-schemaloc-file.xml",
59-
"'file' access is not allowed due to restriction set by the accessExternalSchema property"),
60+
List.of("'file'", "accessExternalSchema")),
6061
Pair.of("schema-validation/simpledoc-invalid-schemaloc-ambiguous-uri.xml",
61-
"'file' access is not allowed due to restriction set by the accessExternalSchema property.")
62+
List.of("'file'", "accessExternalSchema"))
6263
);
6364
}
6465

6566
@ParameterizedTest
6667
@MethodSource("invalidSchemaDocProvider")
67-
void shouldFailValidationWhenUnableToFindExternalSchema(Pair<String, String> test) throws Exception {
68+
void shouldFailValidationWhenUnableToFindExternalSchema(Pair<String, List<String>> test) throws Exception {
6869
try (AutoCloseableInputSource simple = fromResource("schema-validation/simple.xsd");
6970
AutoCloseableInputSource irrelevant = fromResource("schema-validation/irrelevant.xsd");
7071
AutoCloseableInputSource toValidate = fromResource(test.getLeft())) {
7172

7273
Throwable t = assertThrows(SAXException.class, () -> withDefaultReader(simple, irrelevant).parse(toValidate));
73-
assertThat(t.getMessage(), containsString(test.getRight()));
74+
test.getRight().forEach(msg -> assertThat(t.getMessage(), containsString(msg)));
7475
}
7576
}
7677

@@ -81,7 +82,7 @@ void shouldFailValidationWhenDocIsInvalidForSchema() throws Exception {
8182
AutoCloseableInputSource toValidate = fromResource("schema-validation/simpledoc-invalid-no-schemaloc-bad-content.xml")) {
8283

8384
Throwable t = assertThrows(SAXException.class, () -> withDefaultReader(simple, irrelevant).parse(toValidate));
84-
assertThat(t.getMessage(), containsString("Invalid content was found starting with element"));
85+
assertThat(t.getMessage(), containsString("cvc-complex-type.2.4.a"));
8586
}
8687
}
8788

@@ -90,7 +91,8 @@ void shouldFailValidationWhenNoRegisteredSchemas() throws Exception {
9091
try (AutoCloseableInputSource toValidate = fromResource("schema-validation/simpledoc-valid-no-schemaloc.xml")) {
9192

9293
Throwable t = assertThrows(SAXException.class, () -> withDefaultReader().parse(toValidate));
93-
assertThat(t.getMessage(), containsString("Cannot find the declaration of element 'items'."));
94+
assertThat(t.getMessage(), containsString("cvc-elt.1.a"));
95+
assertThat(t.getMessage(), containsString("'items'"));
9496
}
9597
}
9698

@@ -100,7 +102,8 @@ void shouldFailValidationWhenNoRelevantSchemas() throws Exception {
100102
AutoCloseableInputSource toValidate = fromResource("schema-validation/simpledoc-valid-no-schemaloc.xml")) {
101103

102104
Throwable t = assertThrows(SAXException.class, () -> withDefaultReader(irrelevant).parse(toValidate));
103-
assertThat(t.getMessage(), containsString("Cannot find the declaration of element 'items'."));
105+
assertThat(t.getMessage(), containsString("cvc-elt.1.a"));
106+
assertThat(t.getMessage(), containsString("'items'"));
104107
}
105108
}
106109

0 commit comments

Comments
 (0)