| 1 |
|
package com.atlassian.xwork.interceptors; |
| 2 |
|
|
| 3 |
|
import com.opensymphony.xwork.ActionSupport; |
| 4 |
|
import com.atlassian.xwork.ParameterSafe; |
| 5 |
|
import junit.framework.TestCase; |
| 6 |
|
|
| 7 |
|
import java.util.List; |
| 8 |
|
import java.util.Collections; |
| 9 |
|
import java.util.Map; |
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (58) |
Complexity: 11 |
Complexity Density: 0.23 |
|
| 14 |
|
public class TestSafeParametersInterceptor extends TestCase |
| 15 |
|
{ |
| 16 |
|
@ParameterSafe |
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 17 |
|
public static class SafeReturnType {} |
| 18 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 19 |
|
public static class UnsafeReturnType {} |
| 20 |
|
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 13 |
Complexity Density: 1.3 |
|
| 21 |
|
public static class MyAction extends ActionSupport |
| 22 |
|
{ |
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 23 |
0
|
public void setFoo(String foo) {}... |
| 24 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 25 |
0
|
public void setBar(String bar) {}... |
| 26 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 27 |
0
|
public void setFoo_bar(String foo_bar) {}... |
| 28 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 29 |
0
|
public List getBaz() { return Collections.EMPTY_LIST; }... |
| 30 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 31 |
0
|
@ParameterSafe... |
| 32 |
0
|
public List getQuux() { return Collections.EMPTY_LIST; } |
| 33 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 34 |
0
|
public SafeReturnType getSafeReturnType() { return new SafeReturnType(); }... |
| 35 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 36 |
0
|
public UnsafeReturnType getUnsafeReturnType() { return new UnsafeReturnType(); }... |
| 37 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 38 |
0
|
public String getFoo() { return "foo"; }... |
| 39 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 40 |
0
|
@ParameterSafe... |
| 41 |
0
|
public String getBar() { return "bar"; } |
| 42 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 43 |
0
|
@ParameterSafe... |
| 44 |
0
|
public Map getBarMap() { return Collections.emptyMap(); } |
| 45 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 46 |
0
|
@ParameterSafe... |
| 47 |
0
|
public Map getBar_Map() { return Collections.emptyMap(); } |
| 48 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 49 |
0
|
public Map getFooMap() { return Collections.emptyMap(); }... |
| 50 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 51 |
0
|
public Map getFoo_Map() { return Collections.emptyMap(); }... |
| 52 |
|
} |
| 53 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 54 |
1
|
public void testSimpleSetters()... |
| 55 |
|
{ |
| 56 |
1
|
assertTrue(isSafe("foo")); |
| 57 |
1
|
assertTrue(isSafe("bar")); |
| 58 |
1
|
assertTrue(isSafe("foo_bar")); |
| 59 |
|
} |
| 60 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 61 |
1
|
public void testIndexedSetters()... |
| 62 |
|
{ |
| 63 |
1
|
assertTrue(isSafe("baz[0]")); |
| 64 |
1
|
assertTrue(isSafe("baz[1]")); |
| 65 |
1
|
assertTrue(isSafe("baz[2]")); |
| 66 |
|
} |
| 67 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 68 |
1
|
public void testTraverseIndexedSetters()... |
| 69 |
|
{ |
| 70 |
1
|
assertFalse(isSafe("baz[1].foo")); |
| 71 |
1
|
assertTrue(isSafe("baz[1].foo", true)); |
| 72 |
1
|
assertTrue(isSafe("quux[1].foo")); |
| 73 |
|
} |
| 74 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
| 75 |
1
|
public void testMultipleTraversing()... |
| 76 |
|
{ |
| 77 |
1
|
assertFalse(isSafe("foo.bar.baz")); |
| 78 |
1
|
assertTrue(isSafe("foo.bar.baz", true)); |
| 79 |
1
|
assertFalse(isSafe("unsafeReturnType.foo")); |
| 80 |
1
|
assertTrue(isSafe("unsafeReturnType.foo", true)); |
| 81 |
1
|
assertTrue(isSafe("bar.bar.baz")); |
| 82 |
1
|
assertTrue(isSafe("safeReturnType.foo")); |
| 83 |
|
} |
| 84 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 85 |
1
|
public void testMixedTraversingAndIndexing()... |
| 86 |
|
{ |
| 87 |
1
|
assertFalse(isSafe("foo.bar[1]")); |
| 88 |
1
|
assertTrue(isSafe("foo.bar[1]", true)); |
| 89 |
1
|
assertTrue(isSafe("bar.foo[1]")); |
| 90 |
|
} |
| 91 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
| 92 |
1
|
public void testUnsafeCharacters()... |
| 93 |
|
{ |
| 94 |
1
|
assertFalse(isSafe("foo#bar")); |
| 95 |
1
|
assertFalse(isSafe("foo#bar", true)); |
| 96 |
|
|
| 97 |
1
|
assertFalse(isSafe("foo\u0023bar")); |
| 98 |
1
|
assertFalse(isSafe("foo\u0023bar", true)); |
| 99 |
|
|
| 100 |
1
|
assertFalse(isSafe("foo\\u0023bar")); |
| 101 |
1
|
assertFalse(isSafe("foo\\u0023bar", true)); |
| 102 |
|
} |
| 103 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
| 104 |
1
|
public void testDotNotation()... |
| 105 |
|
{ |
| 106 |
1
|
assertTrue(isSafe("bar.property")); |
| 107 |
1
|
assertTrue(isSafe("safeReturnType.property")); |
| 108 |
1
|
assertFalse(isSafe("foo.property")); |
| 109 |
1
|
assertTrue(isSafe("foo.property", true)); |
| 110 |
1
|
assertFalse(isSafe("unsafeReturnType.property")); |
| 111 |
1
|
assertTrue(isSafe("unsafeReturnType.property", true)); |
| 112 |
|
} |
| 113 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1
PASS
|
|
| 114 |
1
|
public void testMapNotation()... |
| 115 |
|
{ |
| 116 |
1
|
assertTrue(isSafe("barMap['key']")); |
| 117 |
1
|
assertTrue(isSafe("bar_Map['key']")); |
| 118 |
1
|
assertTrue(isSafe("bar_Map['key_key']")); |
| 119 |
1
|
assertFalse(isSafe("fooMap['key']")); |
| 120 |
1
|
assertTrue(isSafe("fooMap['key']", true)); |
| 121 |
1
|
assertFalse(isSafe("foo_Map['key']")); |
| 122 |
1
|
assertTrue(isSafe("foo_Map['key']", true)); |
| 123 |
1
|
assertFalse(isSafe("foo_Map['key_key']")); |
| 124 |
1
|
assertTrue(isSafe("foo_Map['key_key']", true)); |
| 125 |
|
} |
| 126 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
| 127 |
1
|
public void testMapNotationWithBadCharacters()... |
| 128 |
|
{ |
| 129 |
1
|
assertFalse(isSafe("barMap['key#G']")); |
| 130 |
1
|
assertFalse(isSafe("barMap['key#G']", true)); |
| 131 |
1
|
assertFalse(isSafe("barMap['key!G']")); |
| 132 |
1
|
assertFalse(isSafe("barMap['key!G']", true)); |
| 133 |
1
|
assertFalse(isSafe("barMap['key\u0023G']")); |
| 134 |
1
|
assertFalse(isSafe("barMap['key\u0023G']", true)); |
| 135 |
|
} |
| 136 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 137 |
30
|
private boolean isSafe(String parameter)... |
| 138 |
|
{ |
| 139 |
30
|
return isSafe(parameter, false); |
| 140 |
|
} |
| 141 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 142 |
45
|
private boolean isSafe(String parameter, boolean disableAnnotationChecks)... |
| 143 |
|
{ |
| 144 |
45
|
return SafeParametersInterceptor.isSafeParameterName(parameter, new MyAction(), disableAnnotationChecks); |
| 145 |
|
} |
| 146 |
|
} |