1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.security.authorization.internal; |
21 |
|
|
22 |
|
import org.junit.Test; |
23 |
|
import org.xwiki.security.authorization.Right; |
24 |
|
import org.xwiki.security.authorization.RuleState; |
25 |
|
import org.xwiki.security.authorization.SecurityAccess; |
26 |
|
|
27 |
|
import static org.hamcrest.CoreMatchers.equalTo; |
28 |
|
import static org.hamcrest.CoreMatchers.not; |
29 |
|
import static org.hamcrest.CoreMatchers.sameInstance; |
30 |
|
import static org.junit.Assert.assertThat; |
31 |
|
import static org.xwiki.security.authorization.RuleState.UNDETERMINED; |
32 |
|
|
33 |
|
|
34 |
|
@link |
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
|
|
| 98.9% |
Uncovered Elements: 1 (87) |
Complexity: 4 |
Complexity Density: 0.05 |
|
39 |
|
public class SecurityAccessTest |
40 |
|
{ |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
46 |
3 |
private void assertDefaultAccessLevel()... |
47 |
|
{ |
48 |
3 |
SecurityAccess access = XWikiSecurityAccess.getDefaultAccess(); |
49 |
3 |
for (Right right : Right.values()) { |
50 |
36 |
if (access.get(right) != UNDETERMINED) { |
51 |
36 |
assertThat("Right(" + right.getName() + ")", |
52 |
|
access.get(right), equalTo(right.getDefaultState())); |
53 |
|
} |
54 |
|
} |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (73) |
Complexity: 1 |
Complexity Density: 0.01 |
1PASS
|
|
60 |
1 |
@Test... |
61 |
|
public void testAccessLevel() throws Exception |
62 |
|
{ |
63 |
1 |
assertDefaultAccessLevel(); |
64 |
|
|
65 |
1 |
XWikiSecurityAccess l = XWikiSecurityAccess.getDefaultAccess().clone(); |
66 |
|
|
67 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.VIEW))); |
68 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.EDIT))); |
69 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.COMMENT))); |
70 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.LOGIN))); |
71 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.REGISTER))); |
72 |
1 |
assertThat(RuleState.DENY, equalTo(l.get(Right.DELETE))); |
73 |
1 |
assertThat(RuleState.DENY, equalTo(l.get(Right.ADMIN))); |
74 |
1 |
assertThat(RuleState.DENY, equalTo(l.get(Right.PROGRAM))); |
75 |
1 |
assertThat(RuleState.DENY, equalTo(l.get(Right.ILLEGAL))); |
76 |
|
|
77 |
1 |
l.clear(Right.VIEW); |
78 |
1 |
l.clear(Right.COMMENT); |
79 |
1 |
l.clear(Right.LOGIN); |
80 |
1 |
l.clear(Right.ADMIN); |
81 |
|
|
82 |
1 |
assertThat(RuleState.UNDETERMINED, equalTo(l.get(Right.VIEW))); |
83 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.EDIT))); |
84 |
1 |
assertThat(RuleState.UNDETERMINED, equalTo(l.get(Right.COMMENT))); |
85 |
1 |
assertThat(RuleState.UNDETERMINED, equalTo(l.get(Right.LOGIN))); |
86 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.REGISTER))); |
87 |
1 |
assertThat(RuleState.DENY, equalTo(l.get(Right.DELETE))); |
88 |
1 |
assertThat(RuleState.UNDETERMINED, equalTo(l.get(Right.ADMIN))); |
89 |
1 |
assertThat(RuleState.DENY, equalTo(l.get(Right.PROGRAM))); |
90 |
1 |
assertThat(RuleState.DENY, equalTo(l.get(Right.ILLEGAL))); |
91 |
|
|
92 |
1 |
l.deny(Right.VIEW); |
93 |
1 |
l.deny(Right.LOGIN); |
94 |
1 |
l.allow(Right.ADMIN); |
95 |
|
|
96 |
1 |
assertThat(RuleState.DENY, equalTo(l.get(Right.VIEW))); |
97 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.EDIT))); |
98 |
1 |
assertThat(RuleState.UNDETERMINED, equalTo(l.get(Right.COMMENT))); |
99 |
1 |
assertThat(RuleState.DENY, equalTo(l.get(Right.LOGIN))); |
100 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.REGISTER))); |
101 |
1 |
assertThat(RuleState.DENY, equalTo(l.get(Right.DELETE))); |
102 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.ADMIN))); |
103 |
1 |
assertThat(RuleState.DENY, equalTo(l.get(Right.PROGRAM))); |
104 |
1 |
assertThat(RuleState.DENY, equalTo(l.get(Right.ILLEGAL))); |
105 |
|
|
106 |
1 |
l.clear(Right.VIEW); |
107 |
1 |
l.clear(Right.EDIT); |
108 |
1 |
l.clear(Right.COMMENT); |
109 |
1 |
l.clear(Right.LOGIN); |
110 |
1 |
l.clear(Right.REGISTER); |
111 |
1 |
l.clear(Right.DELETE); |
112 |
1 |
l.clear(Right.ADMIN); |
113 |
1 |
l.clear(Right.PROGRAM); |
114 |
1 |
l.clear(Right.ILLEGAL); |
115 |
|
|
116 |
1 |
assertThat(RuleState.UNDETERMINED, equalTo(l.get(Right.VIEW))); |
117 |
1 |
assertThat(RuleState.UNDETERMINED, equalTo(l.get(Right.EDIT))); |
118 |
1 |
assertThat(RuleState.UNDETERMINED, equalTo(l.get(Right.COMMENT))); |
119 |
1 |
assertThat(RuleState.UNDETERMINED, equalTo(l.get(Right.LOGIN))); |
120 |
1 |
assertThat(RuleState.UNDETERMINED, equalTo(l.get(Right.REGISTER))); |
121 |
1 |
assertThat(RuleState.UNDETERMINED, equalTo(l.get(Right.DELETE))); |
122 |
1 |
assertThat(RuleState.UNDETERMINED, equalTo(l.get(Right.ADMIN))); |
123 |
1 |
assertThat(RuleState.UNDETERMINED, equalTo(l.get(Right.PROGRAM))); |
124 |
1 |
assertThat(RuleState.UNDETERMINED, equalTo(l.get(Right.ILLEGAL))); |
125 |
|
|
126 |
1 |
l.allow(Right.VIEW); |
127 |
1 |
l.allow(Right.EDIT); |
128 |
1 |
l.allow(Right.COMMENT); |
129 |
1 |
l.allow(Right.LOGIN); |
130 |
1 |
l.allow(Right.REGISTER); |
131 |
1 |
l.allow(Right.DELETE); |
132 |
1 |
l.allow(Right.ADMIN); |
133 |
1 |
l.allow(Right.PROGRAM); |
134 |
1 |
l.allow(Right.ILLEGAL); |
135 |
|
|
136 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.VIEW))); |
137 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.EDIT))); |
138 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.COMMENT))); |
139 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.LOGIN))); |
140 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.REGISTER))); |
141 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.DELETE))); |
142 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.ADMIN))); |
143 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.PROGRAM))); |
144 |
1 |
assertThat(RuleState.ALLOW, equalTo(l.get(Right.ILLEGAL))); |
145 |
|
|
146 |
1 |
assertDefaultAccessLevel(); |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
152 |
1 |
@Test... |
153 |
|
public void testClone() throws Exception |
154 |
|
{ |
155 |
1 |
XWikiSecurityAccess l = XWikiSecurityAccess.getDefaultAccess().clone(); |
156 |
1 |
XWikiSecurityAccess k = l.clone(); |
157 |
1 |
assertThat(l, equalTo(k)); |
158 |
1 |
assertThat(l, not(sameInstance(k))); |
159 |
1 |
assertDefaultAccessLevel(); |
160 |
|
} |
161 |
|
} |