Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/batik/bridge/JarNoLoadTest.java


1   /*
2   
3      Copyright 2004  The Apache Software Foundation 
4   
5      Licensed under the Apache License, Version 2.0 (the "License");
6      you may not use this file except in compliance with the License.
7      You may obtain a copy of the License at
8   
9          http://www.apache.org/licenses/LICENSE-2.0
10  
11     Unless required by applicable law or agreed to in writing, software
12     distributed under the License is distributed on an "AS IS" BASIS,
13     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14     See the License for the specific language governing permissions and
15     limitations under the License.
16  
17   */
18  package org.apache.batik.bridge;
19  
20  import org.apache.batik.test.*;
21  
22  import org.apache.batik.test.svg.SVGOnLoadExceptionTest;
23  
24  /**
25   * Checks that JAR Scripts which should not be loaded are not
26   * loaded.
27   *
28   * @author <a href="mailto:vincent.hardy@sun.com">Vincent Hardy</a>
29   * @version $Id: JarNoLoadTest.java,v 1.2 2004/08/18 07:16:38 vhardy Exp $
30   */
31  public class JarNoLoadTest extends DefaultTestSuite {
32      public JarNoLoadTest() {
33          String scripts = "text/ecmascript";
34          String[] scriptSource = {"bridge/jarCheckNoLoadAny",
35                                   "bridge/jarCheckNoLoadSameAsDocument",
36                                   "bridge/jarCheckNoLoadEmbed",
37          };
38          boolean[] secure = {true, false};
39          String[] scriptOrigin = {"ANY", "DOCUMENT", "EMBEDED", "NONE"};
40  
41          //
42          // If "application/java-archive" is disallowed, scripts
43          // should not be loaded, no matter their origin or the
44          // other security settings.
45          //
46          for (int i=0; i<scriptSource.length; i++) {
47              for (int j=0; j<secure.length; j++) {
48                  for (int k=0; k<scriptOrigin.length; k++) {
49                      SVGOnLoadExceptionTest t = buildTest(scripts,
50                                                           scriptSource[i],
51                                                           scriptOrigin[k],
52                                                           secure[j]);
53                      addTest(t);
54                  }
55              }
56          }
57  
58          //
59          // If "application/java-archive" is allowed, but the accepted
60          // script origin is lower than the candidate script, then
61          // the script should not be loaded (e.g., if scriptOrigin
62          // is embeded and trying to load an external script).
63          //
64          scripts = "application/java-archive";
65          for (int j=0; j<scriptOrigin.length; j++) {
66              for (int i=0; i<j; i++) {
67                  for (int k=0; k<secure.length; k++) {
68                      SVGOnLoadExceptionTest t= buildTest(scripts, scriptSource[i],
69                                                          scriptOrigin[j],
70                                                          secure[k]);
71                      addTest(t);
72                  }
73              }
74          }
75      }
76  
77      SVGOnLoadExceptionTest buildTest(String scripts, String id, String origin, boolean secure) {
78          SVGOnLoadExceptionTest t = new SVGOnLoadExceptionTest();
79          String desc = 
80              "(scripts=" + scripts + 
81              ")(scriptOrigin=" + origin +
82              ")(secure=" + secure + ")";
83          
84          t.setId(id + desc);
85          t.setScriptOrigin(origin);
86          t.setSecure(secure);
87          t.setScripts(scripts);
88          t.setExpectedExceptionClass("java.lang.SecurityException");
89  
90          return t;
91      }
92                               
93  }