1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.ui.basicauth;
17
18 import junit.framework.TestCase;
19
20 import org.acegisecurity.DisabledException;
21 import org.springframework.mock.web.MockHttpServletRequest;
22 import org.springframework.mock.web.MockHttpServletResponse;
23
24
25
26
27
28
29
30
31 public class BasicProcessingFilterEntryPointTests extends TestCase {
32
33
34 public BasicProcessingFilterEntryPointTests() {
35 super();
36 }
37
38 public BasicProcessingFilterEntryPointTests(String arg0) {
39 super(arg0);
40 }
41
42
43
44 public static void main(String[] args) {
45 junit.textui.TestRunner.run(BasicProcessingFilterEntryPointTests.class);
46 }
47
48 public final void setUp() throws Exception {
49 super.setUp();
50 }
51
52 public void testDetectsMissingRealmName() throws Exception {
53 BasicProcessingFilterEntryPoint ep = new BasicProcessingFilterEntryPoint();
54
55 try {
56 ep.afterPropertiesSet();
57 fail("Should have thrown IllegalArgumentException");
58 } catch (IllegalArgumentException expected) {
59 assertEquals("realmName must be specified", expected.getMessage());
60 }
61 }
62
63 public void testGettersSetters() {
64 BasicProcessingFilterEntryPoint ep = new BasicProcessingFilterEntryPoint();
65 ep.setRealmName("realm");
66 assertEquals("realm", ep.getRealmName());
67 }
68
69 public void testNormalOperation() throws Exception {
70 BasicProcessingFilterEntryPoint ep = new BasicProcessingFilterEntryPoint();
71
72 ep.setRealmName("hello");
73
74 MockHttpServletRequest request = new MockHttpServletRequest();
75 request.setRequestURI("/some_path");
76
77 MockHttpServletResponse response = new MockHttpServletResponse();
78
79
80
81 String msg = "These are the jokes kid";
82 ep.commence(request, response, new DisabledException(msg));
83
84 assertEquals(401, response.getStatus());
85 assertEquals(msg, response.getErrorMessage());
86
87 assertEquals("Basic realm=\"hello\"", response.getHeader("WWW-Authenticate"));
88 }
89 }