| 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.Assert; |
| 23 |
|
import org.junit.Test; |
| 24 |
|
import org.xwiki.model.reference.DocumentReference; |
| 25 |
|
import org.xwiki.security.authorization.AbstractLegacyWikiTestCase; |
| 26 |
|
import org.xwiki.security.authorization.AuthorizationManager; |
| 27 |
|
import org.xwiki.security.authorization.testwikibuilding.LegacyTestWiki; |
| 28 |
|
import org.xwiki.security.internal.XWikiConstants; |
| 29 |
|
|
| 30 |
|
import com.xpn.xwiki.XWikiContext; |
| 31 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
@link |
| 35 |
|
|
| 36 |
|
@version |
| 37 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (102) |
Complexity: 10 |
Complexity Density: 0.11 |
|
| 38 |
|
public class XWikiRightServiceTest extends AbstractLegacyWikiTestCase |
| 39 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 40 |
1 |
@Test... |
| 41 |
|
public void testUserFromAnotherWiki1() throws Exception |
| 42 |
|
{ |
| 43 |
1 |
LegacyTestWiki testWiki = newTestWiki("userFromAnotherWiki1.xml", true); |
| 44 |
|
|
| 45 |
1 |
XWikiContext ctx = testWiki.getXWikiContext(); |
| 46 |
1 |
ctx.setWikiId("wiki"); |
| 47 |
|
|
| 48 |
1 |
assertAccessLevelTrue("User from another wiki has right on a local wiki", "view", "wiki:XWiki.user", |
| 49 |
|
"wiki2:Space.Page", ctx); |
| 50 |
|
|
| 51 |
1 |
assertAccessLevelTrue("User from another wiki has right on a local wiki", "view", "XWiki.user", |
| 52 |
|
"wiki2:Space.Page", ctx); |
| 53 |
|
} |
| 54 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
| 55 |
1 |
@Test... |
| 56 |
|
public void testUserFromAnotherWiki2() throws Exception |
| 57 |
|
{ |
| 58 |
1 |
LegacyTestWiki testWiki = newTestWiki("userFromAnotherWiki2.xml", true); |
| 59 |
|
|
| 60 |
1 |
XWikiContext ctx = testWiki.getXWikiContext(); |
| 61 |
|
|
| 62 |
1 |
ctx.setWikiId("wiki"); |
| 63 |
|
|
| 64 |
1 |
assertAccessLevelTrue("User from another wiki does not have right on a local wiki when tested from user wiki", |
| 65 |
|
"view", "wiki:XWiki.user", "wiki2:Space.Page", ctx); |
| 66 |
|
|
| 67 |
1 |
assertAccessLevelTrue("User from another wiki does not have right on a local wiki when tested from user wiki", |
| 68 |
|
"view", "XWiki.user", "wiki2:Space.Page", ctx); |
| 69 |
|
|
| 70 |
1 |
ctx.setWikiId("wiki2"); |
| 71 |
|
|
| 72 |
1 |
assertAccessLevelTrue("User from another wiki does not have right on a local wiki when tested from local wiki", |
| 73 |
|
"view", "wiki:XWiki.user", "wiki2:Space.Page", ctx); |
| 74 |
|
|
| 75 |
1 |
assertAccessLevelTrue("User from another wiki does not have right on a local wiki when tested from local wiki", |
| 76 |
|
"view", "wiki:XWiki.user", "Space.Page", ctx); |
| 77 |
|
|
| 78 |
|
} |
| 79 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
| 80 |
1 |
@Test... |
| 81 |
|
public void testGroupFromAnotherWiki1() throws Exception |
| 82 |
|
{ |
| 83 |
1 |
LegacyTestWiki testWiki = newTestWiki("groupFromAnotherWiki1.xml", true); |
| 84 |
|
|
| 85 |
1 |
XWikiContext ctx = testWiki.getXWikiContext(); |
| 86 |
|
|
| 87 |
1 |
ctx.setWikiId("wiki"); |
| 88 |
|
|
| 89 |
1 |
assertAccessLevelTrue( |
| 90 |
|
"User group from another wiki does not have right on a local wiki when tested from user wiki", "view", |
| 91 |
|
"wiki:XWiki.user", "wiki2:Space.Page", ctx); |
| 92 |
|
|
| 93 |
1 |
assertAccessLevelTrue( |
| 94 |
|
"User group from another wiki does not have right on a local wiki when tested from user wiki", "view", |
| 95 |
|
"XWiki.user", "wiki2:Space.Page", ctx); |
| 96 |
|
|
| 97 |
1 |
ctx.setWikiId("wiki2"); |
| 98 |
|
|
| 99 |
1 |
assertAccessLevelTrue("User from another wiki does not have right on a local wiki when tested from local wiki", |
| 100 |
|
"view", "wiki:XWiki.user", "wiki2:Space.Page", ctx); |
| 101 |
|
|
| 102 |
1 |
assertAccessLevelTrue("User from another wiki does not have right on a local wiki when tested from local wiki", |
| 103 |
|
"view", "wiki:XWiki.user", "Space.Page", ctx); |
| 104 |
|
|
| 105 |
|
} |
| 106 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
| 107 |
1 |
@Test... |
| 108 |
|
public void testWikiOwnerFromAnotherWiki() throws Exception |
| 109 |
|
{ |
| 110 |
1 |
LegacyTestWiki testWiki = newTestWiki("userFromAnotherWiki2.xml", true); |
| 111 |
|
|
| 112 |
1 |
XWikiContext ctx = testWiki.getXWikiContext(); |
| 113 |
|
|
| 114 |
1 |
ctx.setWikiId("wiki"); |
| 115 |
|
|
| 116 |
1 |
assertAccessLevelTrue( |
| 117 |
|
"Wiki owner from another wiki does not have right on a local wiki when tested from user wiki", "view", |
| 118 |
|
"wiki:XWiki.user", "wiki2:Space.Page", ctx); |
| 119 |
|
|
| 120 |
1 |
assertAccessLevelTrue( |
| 121 |
|
"Wiki owner from another wiki does not have right on a local wiki when tested from user wiki", "view", |
| 122 |
|
"XWiki.user", "wiki2:Space.Page", ctx); |
| 123 |
|
|
| 124 |
1 |
ctx.setWikiId("wiki2"); |
| 125 |
|
|
| 126 |
1 |
assertAccessLevelTrue( |
| 127 |
|
"Wiki owner from another wiki does not have right on a local wiki when tested from local wiki", "view", |
| 128 |
|
"wiki:XWiki.user", "wiki2:Space.Page", ctx); |
| 129 |
|
|
| 130 |
1 |
assertAccessLevelTrue( |
| 131 |
|
"Wiki owner from another wiki does not have right on a local wiki when tested from local wiki", "view", |
| 132 |
|
"wiki:XWiki.user", "Space.Page", ctx); |
| 133 |
|
|
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
|
@throws |
| 140 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
| 141 |
1 |
@Test... |
| 142 |
|
public void testProgrammingRightsWhenNoContextDocumentIsSet() throws Exception |
| 143 |
|
{ |
| 144 |
1 |
LegacyTestWiki testWiki = newTestWiki("programmingRights.xml", true); |
| 145 |
|
|
| 146 |
1 |
XWikiContext ctx = testWiki.getXWikiContext(); |
| 147 |
|
|
| 148 |
1 |
ctx.setWikiId("wiki"); |
| 149 |
|
|
| 150 |
1 |
setContext(ctx); |
| 151 |
|
|
| 152 |
1 |
testWiki.setSdoc((String) null); |
| 153 |
|
|
| 154 |
|
|
| 155 |
1 |
testWiki.setUser("XWiki.programmer"); |
| 156 |
1 |
Assert.assertTrue(getLegacyImpl().hasProgrammingRights(ctx)); |
| 157 |
1 |
Assert.assertTrue(getCachingImpl().hasProgrammingRights(ctx)); |
| 158 |
|
|
| 159 |
|
|
| 160 |
1 |
testWiki.setUser(XWikiConstants.GUEST_USER_FULLNAME); |
| 161 |
1 |
Assert.assertFalse(getLegacyImpl().hasProgrammingRights(ctx)); |
| 162 |
1 |
Assert.assertFalse(getCachingImpl().hasProgrammingRights(ctx)); |
| 163 |
|
|
| 164 |
|
|
| 165 |
1 |
testWiki.setUser(XWikiConstants.XWIKI_SPACE + '.' + AuthorizationManager.SUPERADMIN_USER); |
| 166 |
1 |
Assert.assertTrue(getLegacyImpl().hasProgrammingRights(ctx)); |
| 167 |
1 |
Assert.assertTrue(getCachingImpl().hasProgrammingRights(ctx)); |
| 168 |
|
|
| 169 |
|
} |
| 170 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
| 171 |
1 |
@Test... |
| 172 |
|
public void testProgrammingRightsWhenCustomSecureDocIsSet() throws Exception |
| 173 |
|
{ |
| 174 |
1 |
LegacyTestWiki testWiki = newTestWiki("programmingRights.xml", true); |
| 175 |
|
|
| 176 |
1 |
XWikiContext ctx = testWiki.getXWikiContext(); |
| 177 |
|
|
| 178 |
1 |
ctx.setWikiId("wiki"); |
| 179 |
|
|
| 180 |
1 |
setContext(ctx); |
| 181 |
|
|
| 182 |
1 |
XWikiDocument sdoc = new XWikiDocument(new DocumentReference("wiki", "space", "page")); |
| 183 |
1 |
sdoc.setContentAuthorReference(new DocumentReference(ctx.getMainXWiki(), "XWiki", "superadmin")); |
| 184 |
1 |
testWiki.setSdoc(sdoc); |
| 185 |
|
|
| 186 |
|
|
| 187 |
1 |
sdoc.setContentAuthorReference(new DocumentReference(ctx.getMainXWiki(), "XWiki", "programmer")); |
| 188 |
1 |
Assert.assertTrue(getLegacyImpl().hasProgrammingRights(ctx)); |
| 189 |
1 |
Assert.assertTrue(getCachingImpl().hasProgrammingRights(ctx)); |
| 190 |
|
|
| 191 |
|
|
| 192 |
1 |
sdoc.setContentAuthorReference(null); |
| 193 |
1 |
Assert.assertFalse(getLegacyImpl().hasProgrammingRights(ctx)); |
| 194 |
1 |
Assert.assertFalse(getCachingImpl().hasProgrammingRights(ctx)); |
| 195 |
|
|
| 196 |
|
|
| 197 |
1 |
sdoc.setContentAuthorReference(new DocumentReference(ctx.getMainXWiki(), "XWiki", "superadmin")); |
| 198 |
1 |
Assert.assertTrue(getLegacyImpl().hasProgrammingRights(ctx)); |
| 199 |
1 |
Assert.assertTrue(getCachingImpl().hasProgrammingRights(ctx)); |
| 200 |
|
|
| 201 |
|
} |
| 202 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
| 203 |
1 |
@Test... |
| 204 |
|
public void testGuestRightsOnEmptyWiki() throws Exception |
| 205 |
|
{ |
| 206 |
1 |
LegacyTestWiki testWiki = newTestWiki("empty.xml", true); |
| 207 |
|
|
| 208 |
1 |
XWikiContext ctx = testWiki.getXWikiContext(); |
| 209 |
|
|
| 210 |
1 |
ctx.setWikiId("wiki"); |
| 211 |
|
|
| 212 |
1 |
assertAccessLevelTrue("Guest does not have view right on empty wiki.", "view", "wiki:XWiki.XWikiGuest", |
| 213 |
|
"wiki:Space.Page", ctx); |
| 214 |
|
|
| 215 |
1 |
assertAccessLevelTrue("Guest does not have edit right on empty wiki.", "edit", "wiki:XWiki.XWikiGuest", |
| 216 |
|
"wiki:Space.Page", ctx); |
| 217 |
|
|
| 218 |
1 |
assertAccessLevelFalseExpectedDifference("Guest should not have delete right on empty wiki.", "delete", |
| 219 |
|
"wiki:XWiki.XWikiGuest", "wiki:Space.Page", ctx); |
| 220 |
|
|
| 221 |
1 |
assertAccessLevelFalseExpectedDifference("Guest should not have admin right on empty wiki.", "admin", |
| 222 |
|
"wiki:XWiki.XWikiGuest", "wiki:Space.Page", ctx); |
| 223 |
|
|
| 224 |
1 |
assertAccessLevelFalse("Guest should not have programming right on empty wiki.", "programming", |
| 225 |
|
"wiki:XWiki.XWikiGuest", "wiki:Space.Page", ctx); |
| 226 |
|
|
| 227 |
1 |
testWiki.setUser("wiki:XWiki.XWikiGuest"); |
| 228 |
|
|
| 229 |
1 |
assertWikiAdminRightsFalseExpectedDifference("Guest should not have admin right on empty wiki.", ctx); |
| 230 |
|
|
| 231 |
1 |
testWiki.setDoc("wiki:Space.Page"); |
| 232 |
|
|
| 233 |
1 |
assertAdminRightsFalseExpectedDifference("Guest should not have admin right on empty wiki.", ctx); |
| 234 |
|
} |
| 235 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 236 |
1 |
@Test... |
| 237 |
|
public void testGlobalUserInLocalGroup() throws Exception |
| 238 |
|
{ |
| 239 |
1 |
LegacyTestWiki testWiki = newTestWiki("glocalUserInLocalGroup.xml", true); |
| 240 |
|
|
| 241 |
1 |
XWikiContext ctx = testWiki.getXWikiContext(); |
| 242 |
|
|
| 243 |
1 |
ctx.setWikiId("wiki2"); |
| 244 |
|
|
| 245 |
1 |
assertAccessLevelTrue("User from global wiki should have right on local wiki through local group", "view", |
| 246 |
|
"wiki:XWiki.user", "wiki2:Space.Page", ctx); |
| 247 |
|
} |
| 248 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 249 |
1 |
@Test... |
| 250 |
|
public void testGlobalGroupInLocalGroup() throws Exception |
| 251 |
|
{ |
| 252 |
1 |
LegacyTestWiki testWiki = newTestWiki("glocalGroupInLocalGroup.xml", true); |
| 253 |
|
|
| 254 |
1 |
XWikiContext ctx = testWiki.getXWikiContext(); |
| 255 |
|
|
| 256 |
1 |
ctx.setWikiId("wiki2"); |
| 257 |
|
|
| 258 |
1 |
assertAccessLevelTrue("Users from global wiki should have right on local wiki through local group", "view", |
| 259 |
|
"wiki:XWiki.user", "wiki2:Space.Page", ctx); |
| 260 |
|
|
| 261 |
1 |
assertAccessLevelTrue("Groups from global wiki should have right on local wiki through local group", "view", |
| 262 |
|
"wiki:XWiki.group", "wiki2:Space.Page", ctx); |
| 263 |
|
} |
| 264 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
| 265 |
1 |
@Test... |
| 266 |
|
public void testRelativeDocumentReference() throws Exception |
| 267 |
|
{ |
| 268 |
1 |
LegacyTestWiki testWiki = newTestWiki("denieddocument.xml", true); |
| 269 |
|
|
| 270 |
1 |
XWikiContext ctx = testWiki.getXWikiContext(); |
| 271 |
1 |
ctx.setWikiId("wiki"); |
| 272 |
1 |
testWiki.setDoc("wiki:Space.Page"); |
| 273 |
|
|
| 274 |
|
|
| 275 |
|
|
| 276 |
1 |
assertAccessLevelFalse("User has right on the denied document", "view", "wiki:XWiki.user", "wiki:Space.Page", |
| 277 |
|
ctx); |
| 278 |
|
|
| 279 |
1 |
assertAccessLevelFalse("User has right on the denied document", "view", "wiki:XWiki.user", "Space.Page", ctx); |
| 280 |
|
|
| 281 |
1 |
assertAccessLevelFalse("User has right on the denied document", "view", "wiki:XWiki.user", "Page", ctx); |
| 282 |
|
|
| 283 |
1 |
assertAccessLevelTrue("User does not have right on the document space", "view", "wiki:XWiki.user", "", ctx); |
| 284 |
|
|
| 285 |
|
|
| 286 |
|
|
| 287 |
1 |
assertAccessLevelFalse("User has right on the denied document", "edit", "XWiki.user", "wiki:Space.Page", ctx); |
| 288 |
|
|
| 289 |
1 |
assertAccessLevelFalse("User has right on the denied document", "edit", "XWiki.user", "Space.Page", ctx); |
| 290 |
|
|
| 291 |
1 |
assertAccessLevelFalse("User has right on the denied document", "edit", "XWiki.user", "Page", ctx); |
| 292 |
|
|
| 293 |
1 |
assertAccessLevelTrue("User does not have right on the document space", "edit", "XWiki.user", "", ctx); |
| 294 |
|
} |
| 295 |
|
} |