-
Notifications
You must be signed in to change notification settings - Fork 888
/
HtmlSanitizerOptionalTest.java
108 lines (92 loc) · 4.16 KB
/
HtmlSanitizerOptionalTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package org.jboss.resteasy.test.providers.html;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.test.providers.html.resource.HtmlSanitizerOptionalResource;
import org.jboss.resteasy.utils.PortProviderUtil;
import org.jboss.resteasy.utils.TestUtil;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* @tpSubChapter
* @tpChapter Integration tests
* @tpTestCaseDetails Regression test for RESTEASY-2034
* @tpSince RESTEasy 4.0.0
*/
@RunWith(Arquillian.class)
@RunAsClient
public class HtmlSanitizerOptionalTest {
static ResteasyClient client;
private static final String ENABLED = "_enabled";
private static final String DISABLED = "_disabled";
private static final String DEFAULT = "_default";
static public final String input = "<html <\"abc\" 'xyz'>/>";
static private final String output = "<html &lt;"abc" 'xyz'&gt;/>";
@Deployment(name = ENABLED, order = 1)
public static Archive<?> createTestArchive1() {
WebArchive war = TestUtil.prepareArchive(HtmlSanitizerOptionalTest.class.getSimpleName() + ENABLED);
war.addAsWebInfResource(HtmlSanitizerOptionalTest.class.getPackage(), "HtmlSanitizerOptional_Enabled_web.xml", "web.xml");
return TestUtil.finishContainerPrepare(war, null, HtmlSanitizerOptionalResource.class);
}
@Deployment(name = DISABLED, order = 2)
public static Archive<?> createTestArchive2() {
WebArchive war = TestUtil.prepareArchive(HtmlSanitizerOptionalTest.class.getSimpleName() + DISABLED);
war.addAsWebInfResource(HtmlSanitizerOptionalTest.class.getPackage(), "HtmlSanitizerOptional_Disabled_web.xml", "web.xml");
return TestUtil.finishContainerPrepare(war, null, HtmlSanitizerOptionalResource.class);
}
@Deployment(name = DEFAULT, order = 3)
public static Archive<?> createTestArchive3() {
WebArchive war = TestUtil.prepareArchive(HtmlSanitizerOptionalTest.class.getSimpleName() + DEFAULT);
war.addAsWebInfResource(HtmlSanitizerOptionalTest.class.getPackage(), "HtmlSanitizerOptional_Default_web.xml", "web.xml");
return TestUtil.finishContainerPrepare(war, null, HtmlSanitizerOptionalResource.class);
}
private String generateURL(String path, String version) {
return PortProviderUtil.generateURL(path, HtmlSanitizerOptionalTest.class.getSimpleName() + version);
}
@Before
public void init() {
client = (ResteasyClient)ClientBuilder.newClient();
}
@After
public void after() throws Exception {
client.close();
}
/**
* @tpTestDetails Context parameter "resteasy.disable.html.sanitizer" is set to "true".
* @tpPassCrit Input string should be unchanged.
* @tpSince RESTEasy 4.0.0
*/
@Test
public void testHtmlSanitizerDisabled() throws Exception {
Response response = client.target(generateURL("/test", DISABLED)).request().get();
Assert.assertEquals(input, response.readEntity(String.class));
}
/**
* @tpTestDetails Context parameter "resteasy.disable.html.sanitizer" is set to "false"
* @tpPassCrit Input string should be sanitized.
* @tpSince RESTEasy 4.0.0
*/
@Test
public void testHtmlSanitizerEnabled() throws Exception {
Response response = client.target(generateURL("/test", ENABLED)).request().get();
Assert.assertEquals(output, response.readEntity(String.class));
}
/**
* @tpTestDetails Context parameter "resteasy.disable.html.sanitizer" is not set.
* @tpPassCrit Input string should be sanitized.
* @tpSince RESTEasy 4.0.0
*/
@Test
public void testHtmlSanitizerDefault() throws Exception {
Response response = client.target(generateURL("/test", DEFAULT)).request().get();
Assert.assertEquals(output, response.readEntity(String.class));
}
}