|
13 | 13 | * See the License for the specific language governing permissions and
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
| 16 | + |
16 | 17 | package sample;
|
17 | 18 |
|
18 | 19 | import javax.servlet.http.HttpServletResponse;
|
|
30 | 31 | import org.springframework.security.web.FilterChainProxy;
|
31 | 32 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
32 | 33 |
|
33 |
| -import static org.hamcrest.Matchers.*; |
| 34 | +import static org.hamcrest.Matchers.equalTo; |
34 | 35 | import static org.junit.Assert.assertThat;
|
35 | 36 |
|
36 | 37 | @RunWith(SpringJUnit4ClassRunner.class)
|
37 | 38 | @SpringApplicationConfiguration(classes = HelloWebSecurityApplication.class)
|
38 | 39 | @WebIntegrationTest(randomPort = true)
|
39 | 40 | public class HelloWebSecurityApplicationTests {
|
| 41 | + |
40 | 42 | @Autowired
|
41 |
| - FilterChainProxy springSecurityFilterChain; |
| 43 | + private FilterChainProxy springSecurityFilterChain; |
42 | 44 |
|
43 |
| - MockHttpServletRequest request; |
| 45 | + private MockHttpServletRequest request; |
44 | 46 |
|
45 |
| - MockHttpServletResponse response; |
| 47 | + private MockHttpServletResponse response; |
46 | 48 |
|
47 |
| - MockFilterChain chain; |
| 49 | + private MockFilterChain chain; |
48 | 50 |
|
49 | 51 | @Before
|
50 | 52 | public void setup() {
|
51 |
| - request = new MockHttpServletRequest(); |
52 |
| - response = new MockHttpServletResponse(); |
53 |
| - chain = new MockFilterChain(); |
| 53 | + this.request = new MockHttpServletRequest(); |
| 54 | + this.response = new MockHttpServletResponse(); |
| 55 | + this.chain = new MockFilterChain(); |
54 | 56 | }
|
55 | 57 |
|
56 | 58 | @Test
|
57 | 59 | public void requiresAuthentication() throws Exception {
|
58 |
| - springSecurityFilterChain.doFilter(request, response, chain); |
| 60 | + this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain); |
59 | 61 |
|
60 |
| - assertThat(response.getStatus(), equalTo(HttpServletResponse.SC_UNAUTHORIZED)); |
| 62 | + assertThat(this.response.getStatus(), |
| 63 | + equalTo(HttpServletResponse.SC_UNAUTHORIZED)); |
61 | 64 | }
|
62 | 65 |
|
63 |
| - |
64 | 66 | @Test
|
65 | 67 | public void userAuthenticates() throws Exception {
|
66 |
| - request.addHeader("Authorization", "Basic " + new String(Base64.encode("user:password".getBytes("UTF-8")))); |
| 68 | + this.request.addHeader("Authorization", |
| 69 | + "Basic " + new String(Base64.encode("user:password".getBytes("UTF-8")))); |
67 | 70 |
|
68 |
| - springSecurityFilterChain.doFilter(request, response, chain); |
| 71 | + this.springSecurityFilterChain.doFilter(this.request, this.response, this.chain); |
69 | 72 |
|
70 |
| - assertThat(response.getStatus(), equalTo(HttpServletResponse.SC_OK)); |
| 73 | + assertThat(this.response.getStatus(), equalTo(HttpServletResponse.SC_OK)); |
71 | 74 | }
|
72 | 75 | }
|
0 commit comments