This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
/
ReproTests.java
67 lines (55 loc) · 2.29 KB
/
ReproTests.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
package org.springframework.issues;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.issues.config.WebConfig;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.RequestPostProcessor;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = WebConfig.class)
@WebAppConfiguration
public class ReproTests {
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setupMockMvc() {
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void rfc3986() throws Exception {
final String host = "spring_app"; // RFC 3986 allow '_'. However tests is fail.
mockMvc.perform(get("/")
.with(host(host))
.header(HttpHeaders.ORIGIN, host))
.andExpect(view()
.name("home"));
}
@Test
public void rfc2396() throws Exception {
String host = "spring-app"; // RFC 2396 does not allow '_'. Therefor i use a host name include with "-" instead of "_".
mockMvc.perform(get("/")
.with(host(host))
.header(HttpHeaders.ORIGIN, host))
.andExpect(view()
.name("home"));
}
private RequestPostProcessor host(final String host) {
return new RequestPostProcessor() {
public MockHttpServletRequest postProcessRequest(MockHttpServletRequest request) {
request.setServerName(host);
return request;
}
};
}
}