|
33 | 33 | * Tests for pragmas
|
34 | 34 | */
|
35 | 35 | public class ComposePermissionsTest extends JexlTestCase {
|
36 |
| - static final String SAMPLE_JSON = "src/test/scripts/sample.json"; |
37 |
| - /** |
38 |
| - * Create a new test case. |
39 |
| - */ |
40 |
| - public ComposePermissionsTest() { |
41 |
| - super("PermissionsTest"); |
42 |
| - } |
| 36 | + static final String SAMPLE_JSON = "src/test/scripts/sample.json"; |
43 | 37 |
|
44 |
| - void runComposePermissions(final JexlPermissions p) throws Exception { |
45 |
| - final String check = "http://example.com/content.jpg"; |
46 |
| - final File jsonFile = new File(SAMPLE_JSON); |
47 |
| - final Gson gson = new Gson(); |
48 |
| - final Object json = gson.fromJson(new FileReader(jsonFile), Object.class); |
49 |
| - assertNotNull(json); |
| 38 | + /** |
| 39 | + * Create a new test case. |
| 40 | + */ |
| 41 | + public ComposePermissionsTest() { |
| 42 | + super("PermissionsTest"); |
| 43 | + } |
50 | 44 |
|
51 |
| - // will succeed because java.util.Map is allowed and gson LinkedTreeMap is one |
52 |
| - final JexlEngine j0 = createEngine(false, p); |
53 |
| - final JexlScript s0 = j0.createScript("json.pageInfo.pagePic", "json"); |
54 |
| - final Object r0 = s0.execute(null, json); |
55 |
| - assertEquals(check, r0); |
| 45 | + void runComposePermissions(final JexlPermissions p) throws Exception { |
| 46 | + final String check = "http://example.com/content.jpg"; |
| 47 | + final File jsonFile = new File(SAMPLE_JSON); |
| 48 | + final Gson gson = new Gson(); |
| 49 | + final Object json = gson.fromJson(new FileReader(jsonFile), Object.class); |
| 50 | + assertNotNull(json); |
56 | 51 |
|
57 |
| - // will fail if gson package is denied |
58 |
| - JexlEngine j1 = createEngine(false, p.compose("com.google.gson.internal {}")); |
59 |
| - JexlScript s1 = j1.createScript("json.pageInfo.pagePic", "json"); |
60 |
| - try { |
61 |
| - final Object r1 = s1.execute(null, json); |
62 |
| - fail("gson restricted"); |
63 |
| - } catch (final JexlException.Property xproperty) { |
64 |
| - assertEquals("pageInfo", xproperty.getProperty()); |
65 |
| - } |
| 52 | + // will succeed because java.util.Map is allowed and gson LinkedTreeMap is one |
| 53 | + final JexlEngine j0 = createEngine(false, p); |
| 54 | + final JexlScript s0 = j0.createScript("json.pageInfo.pagePic", "json"); |
| 55 | + final Object r0 = s0.execute(null, json); |
| 56 | + assertEquals(check, r0); |
66 | 57 |
|
67 |
| - // will fail since gson package is denied |
68 |
| - j1 = createEngine(false, p.compose("com.google.gson.internal { LinkedTreeMap {} }")); |
69 |
| - s1 = j1.createScript("json.pageInfo.pagePic", "json"); |
70 |
| - try { |
71 |
| - final Object r1 = s1.execute(null, json); |
72 |
| - fail("gson LinkTreeMap restricted"); |
73 |
| - } catch (final JexlException.Property xproperty) { |
74 |
| - assertEquals("pageInfo", xproperty.getProperty()); |
75 |
| - } |
| 58 | + // will fail if gson package is denied |
| 59 | + JexlEngine j1 = createEngine(false, p.compose("com.google.gson.internal {}")); |
| 60 | + JexlScript s1 = j1.createScript("json.pageInfo.pagePic", "json"); |
| 61 | + try { |
| 62 | + final Object r1 = s1.execute(null, json); |
| 63 | + fail("gson restricted"); |
| 64 | + } catch (final JexlException.Property xproperty) { |
| 65 | + assertEquals("pageInfo", xproperty.getProperty()); |
| 66 | + } |
| 67 | + |
| 68 | + // will fail since gson package is denied |
| 69 | + j1 = createEngine(false, p.compose("com.google.gson.internal { LinkedTreeMap {} }")); |
| 70 | + s1 = j1.createScript("json.pageInfo.pagePic", "json"); |
| 71 | + try { |
| 72 | + final Object r1 = s1.execute(null, json); |
| 73 | + fail("gson LinkTreeMap restricted"); |
| 74 | + } catch (final JexlException.Property xproperty) { |
| 75 | + assertEquals("pageInfo", xproperty.getProperty()); |
| 76 | + } |
76 | 77 |
|
77 |
| - // will not fail since gson objects |
78 |
| - j1 = createEngine(false, JexlPermissions.RESTRICTED); |
79 |
| - s1 = j1.createScript("json.pageInfo.pagePic", "json"); |
80 |
| - final Object r1 = s1.execute(null, json); |
81 |
| - assertEquals(check, r0); |
82 |
| - } |
| 78 | + // will not fail since gson objects |
| 79 | + j1 = createEngine(false, JexlPermissions.RESTRICTED); |
| 80 | + s1 = j1.createScript("json.pageInfo.pagePic", "json"); |
| 81 | + final Object r1 = s1.execute(null, json); |
| 82 | + assertEquals(check, r0); |
| 83 | + } |
83 | 84 |
|
84 |
| - @Test |
85 |
| - public void testComposePermissions() throws Exception { |
86 |
| - runComposePermissions(JexlPermissions.UNRESTRICTED); |
87 |
| - } |
| 85 | + @Test |
| 86 | + public void testComposePermissions() throws Exception { |
| 87 | + runComposePermissions(JexlPermissions.UNRESTRICTED); |
| 88 | + } |
88 | 89 |
|
89 |
| - @Test |
90 |
| - public void testComposePermissions1() throws Exception { |
91 |
| - runComposePermissions(new JexlPermissions.Delegate(JexlPermissions.UNRESTRICTED) { |
92 |
| - @Override public String toString() { |
93 |
| - return "delegate:" + base.toString(); |
94 |
| - } |
95 |
| - }); |
96 |
| - } |
| 90 | + @Test |
| 91 | + public void testComposePermissions1() throws Exception { |
| 92 | + runComposePermissions(new JexlPermissions.Delegate(JexlPermissions.UNRESTRICTED) { |
| 93 | + @Override |
| 94 | + public String toString() { |
| 95 | + return "delegate:" + base.toString(); |
| 96 | + } |
| 97 | + }); |
| 98 | + } |
97 | 99 |
|
98 |
| - @Test |
99 |
| - public void testComposePermissions2() throws Exception { |
100 |
| - runComposePermissions(new JexlPermissions.ClassPermissions(JexlPermissions.UNRESTRICTED, Collections.emptySet())); |
101 |
| - } |
| 100 | + @Test |
| 101 | + public void testComposePermissions2() throws Exception { |
| 102 | + runComposePermissions(new JexlPermissions.ClassPermissions(JexlPermissions.UNRESTRICTED, Collections.emptySet())); |
| 103 | + } |
102 | 104 | }
|
0 commit comments