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 junit.framework.TestCase;
06: import fitnesse.wiki.*;
07: import fitnesse.http.*;
08: import fitnesse.FitNesseContext;
09:
10: public class SecureOperationTest extends TestCase {
11: private SecureReadOperation sro;
12:
13: private WikiPage root;
14:
15: FitNesseContext context;
16:
17: private MockRequest request;
18:
19: private PageCrawler crawler;
20:
21: private WikiPagePath parentPagePath;
22:
23: private WikiPagePath childPagePath;
24:
25: protected void setUp() throws Exception {
26: root = InMemoryPage.makeRoot("RooT");
27: context = new FitNesseContext();
28: context.root = root;
29: sro = new SecureReadOperation();
30: request = new MockRequest();
31: crawler = root.getPageCrawler();
32: parentPagePath = PathParser.parse("ParentPage");
33: childPagePath = PathParser.parse("ChildPage");
34: }
35:
36: public void testNormalPageDoesNotRequireAuthentication()
37: throws Exception {
38: String insecurePageName = "InsecurePage";
39: WikiPagePath insecurePagePath = PathParser
40: .parse(insecurePageName);
41: crawler.addPage(root, insecurePagePath);
42: request.setResource(insecurePageName);
43: assertFalse(sro.shouldAuthenticate(context, request));
44: }
45:
46: public void testReadSecurePageRequresAuthentication()
47: throws Exception {
48: String securePageName = "SecurePage";
49: WikiPagePath securePagePath = PathParser.parse(securePageName);
50: WikiPage securePage = crawler.addPage(root, securePagePath);
51: makeSecure(securePage);
52: request.setResource(securePageName);
53: assertTrue(sro.shouldAuthenticate(context, request));
54: }
55:
56: private void makeSecure(WikiPage securePage) throws Exception {
57: PageData data = securePage.getData();
58: data.setAttribute(WikiPage.SECURE_READ);
59: securePage.commit(data);
60: }
61:
62: public void testChildPageOfSecurePageRequiresAuthentication()
63: throws Exception {
64: WikiPage parentPage = crawler.addPage(root, parentPagePath);
65: makeSecure(parentPage);
66: crawler.addPage(parentPage, childPagePath);
67: request.setResource("ParentPage.ChildPage");
68: assertTrue(sro.shouldAuthenticate(context, request));
69: }
70:
71: public void testNonExistentPageCanBeAuthenticated()
72: throws Exception {
73: request.setResource("NonExistentPage");
74: assertFalse(sro.shouldAuthenticate(context, request));
75: }
76:
77: public void testParentOfNonExistentPageStillSetsPriviledges()
78: throws Exception {
79: WikiPage parentPage = crawler.addPage(root, parentPagePath);
80: makeSecure(parentPage);
81: request.setResource("ParentPage.NonExistentPage");
82: assertTrue(sro.shouldAuthenticate(context, request));
83: }
84:
85: public void testChildPageIsRestricted() throws Exception {
86: WikiPage parentPage = crawler.addPage(root, parentPagePath);
87: WikiPage childPage = crawler.addPage(parentPage, childPagePath);
88: makeSecure(childPage);
89: request.setResource("ParentPage.ChildPage");
90: assertTrue(sro.shouldAuthenticate(context, request));
91: }
92:
93: public void testBlankResource() throws Exception {
94: request.setResource("");
95: assertFalse(sro.shouldAuthenticate(context, request));
96: }
97: }
|