1
2
3
4
5
6
7
8
9
10
11
12
13
14 package sparklr.common;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertTrue;
18
19 import org.junit.Test;
20 import org.springframework.http.HttpStatus;
21 import org.springframework.http.ResponseEntity;
22
23
24
25
26
27 public abstract class AbstractProtectedResourceTests extends AbstractIntegrationTests {
28
29 @Test
30 public void testHomePageIsProtected() throws Exception {
31 ResponseEntity<String> response = http.getForString("/");
32 assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
33 assertTrue("Wrong header: " + response.getHeaders(), response.getHeaders().getFirst("WWW-Authenticate")
34 .startsWith("Bearer realm="));
35 }
36
37 @Test
38 public void testBeansResourceIsProtected() throws Exception {
39 ResponseEntity<String> response = http.getForString("/admin/beans");
40 assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
41 assertTrue("Wrong header: " + response.getHeaders(), response.getHeaders().getFirst("WWW-Authenticate")
42 .startsWith("Bearer realm="));
43 }
44
45 @Test
46 public void testHealthResourceIsOpen() throws Exception {
47 assertEquals(HttpStatus.OK, http.getStatusCode("/admin/health"));
48 }
49
50
51 }