01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.authentication;
04:
05: import fitnesse.wiki.*;
06: import fitnesse.http.*;
07: import fitnesse.responders.*;
08: import fitnesse.*;
09: import fitnesse.testutil.SimpleAuthenticator;
10: import junit.framework.TestCase;
11:
12: public class AuthenticatorTest extends TestCase {
13: SimpleAuthenticator authenticator;
14:
15: private WikiPage root;
16:
17: private MockRequest request;
18:
19: private Responder responder;
20:
21: private Class responderType;
22:
23: private WikiPageResponder privilegedResponder;
24:
25: private FitNesseContext context;
26:
27: public void setUp() throws Exception {
28: root = InMemoryPage.makeRoot("RooT");
29: WikiPage frontpage = root.addChildPage("FrontPage");
30: makeReadSecure(frontpage);
31: authenticator = new SimpleAuthenticator();
32: privilegedResponder = new WikiPageResponder();
33:
34: request = new MockRequest();
35: request.setResource("FrontPage");
36: context = new FitNesseContext(root);
37: }
38:
39: private void makeReadSecure(WikiPage frontpage) throws Exception {
40: PageData data = frontpage.getData();
41: data.setAttribute(WikiPage.SECURE_READ);
42: frontpage.commit(data);
43: }
44:
45: public void tearDown() throws Exception {
46: }
47:
48: public void testNotAuthenticated() throws Exception {
49: makeResponder();
50: assertEquals(UnauthorizedResponder.class, responderType);
51: }
52:
53: public void testAuthenticated() throws Exception {
54: authenticator.authenticated = true;
55: makeResponder();
56: assertEquals(WikiPageResponder.class, responderType);
57: }
58:
59: private void makeResponder() throws Exception {
60: responder = authenticator.authenticate(context, request,
61: privilegedResponder);
62: responderType = responder.getClass();
63: }
64: }
|