1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.xml.secure;
19
20 import static org.junit.jupiter.api.Assertions.assertNotNull;
21 import static org.junit.jupiter.api.Assertions.assertSame;
22 import static org.junit.jupiter.api.Assertions.assertThrows;
23
24 import javax.xml.stream.XMLResolver;
25 import javax.xml.stream.XMLStreamException;
26
27 import org.junit.jupiter.api.Test;
28
29 class FallbackIgnoreXMLResolverTest {
30
31 @Test
32 void coversDelegateFallbackAndDenyBranches() throws Exception {
33 final FallbackIgnoreXMLResolver resolver = new FallbackIgnoreXMLResolver(null);
34 assertNotNull(resolver.resolveEntity("p", "s", "b", "n"));
35 final Object expected = new Object();
36 final XMLResolver delegate = (publicId, systemId, base, namespace) -> expected;
37 resolver.setDelegate(delegate);
38 assertSame(delegate, resolver.getDelegate());
39 assertSame(expected, resolver.resolveEntity("p", "s", "b", "n"));
40 resolver.setDelegate(null);
41 System.setProperty(SecureException.THROW_ON_UNRESOLVED, "true");
42 try {
43 assertThrows(XMLStreamException.class, () -> resolver.resolveEntity("p", "s", "b", "n"));
44 } finally {
45 System.clearProperty(SecureException.THROW_ON_UNRESOLVED);
46 }
47 }
48 }