01: /*
02: * Copyright 2003-2006 Rick Knowles <winstone-devel at lists sourceforge net>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: */
07: package winstone.testCase;
08:
09: import java.io.File;
10: import java.io.IOException;
11:
12: import junit.framework.TestCase;
13: import winstone.StaticResourceServlet;
14:
15: /**
16: * Automated tests for the url security check inside the static resource servlet
17: *
18: * @author <a href="mailto:rick_knowles@hotmail.com">Rick Knowles</a>
19: * @version $Id: StaticResourceServletTest.java,v 1.2 2006/02/28 07:32:49 rickknowles Exp $
20: */
21: public class StaticResourceServletTest extends TestCase {
22:
23: /**
24: * Constructor
25: */
26: public StaticResourceServletTest(String name) {
27: super (name);
28: }
29:
30: public void testIsDescendant() throws IOException {
31: File webroot = new File("src/testwebapp");
32: File webinf = new File(webroot, "WEB-INF");
33: assertTrue("Direct subfolder", StaticResourceServlet
34: .isDescendant(webroot, webinf, webroot));
35: assertTrue("Self is a descendent of itself",
36: StaticResourceServlet.isDescendant(webinf, webinf,
37: webroot));
38: assertTrue("Direct subfile", StaticResourceServlet
39: .isDescendant(webinf, new File(webinf, "web.xml"),
40: webroot));
41: assertTrue("Indirect subfile", StaticResourceServlet
42: .isDescendant(webroot, new File(webinf, "web.xml"),
43: webroot));
44: assertTrue("Backwards iterations", !StaticResourceServlet
45: .isDescendant(webinf, new File(webinf, ".."), webroot));
46: }
47:
48: public void testCanonicalVersion() throws IOException {
49: File webroot = new File("src/testwebapp");
50: File webinf = new File(webroot, "WEB-INF");
51: File webxml = new File(webinf, "web.xml");
52: assertTrue("Simplest case", StaticResourceServlet
53: .constructOurCanonicalVersion(webxml, webroot).equals(
54: "/WEB-INF/web.xml"));
55: assertTrue("One back step", StaticResourceServlet
56: .constructOurCanonicalVersion(
57: new File(webroot, "/test/../WEB-INF/web.xml"),
58: webroot).equals("/WEB-INF/web.xml"));
59: }
60: }
|