| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.security; |
| 21 |
|
|
| 22 |
|
import java.util.Arrays; |
| 23 |
|
import java.util.HashMap; |
| 24 |
|
import java.util.List; |
| 25 |
|
import java.util.Map; |
| 26 |
|
|
| 27 |
|
import org.junit.Before; |
| 28 |
|
import org.xwiki.model.reference.AttachmentReference; |
| 29 |
|
import org.xwiki.model.reference.DocumentReference; |
| 30 |
|
import org.xwiki.model.reference.EntityReference; |
| 31 |
|
import org.xwiki.model.reference.SpaceReference; |
| 32 |
|
import org.xwiki.model.reference.WikiReference; |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
@version |
| 38 |
|
@since |
| 39 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (60) |
Complexity: 6 |
Complexity Density: 0.11 |
|
| 40 |
|
public abstract class AbstractSecurityTestCase |
| 41 |
|
{ |
| 42 |
|
protected SecurityReference xwikiRef; |
| 43 |
|
protected SecurityReference wikiRef; |
| 44 |
|
protected SecurityReference anotherWikiRef; |
| 45 |
|
|
| 46 |
|
protected List<SecurityReference> wikiRefs; |
| 47 |
|
|
| 48 |
|
protected SecurityReference xspaceRef; |
| 49 |
|
protected SecurityReference anotherXspaceRef; |
| 50 |
|
protected SecurityReference spaceRef; |
| 51 |
|
protected SecurityReference anotherSpaceRef; |
| 52 |
|
protected SecurityReference anotherWikiSpaceRef; |
| 53 |
|
protected SecurityReference xdocRef; |
| 54 |
|
protected SecurityReference anotherXdocRef; |
| 55 |
|
protected SecurityReference docRef; |
| 56 |
|
protected SecurityReference anotherDocRef; |
| 57 |
|
protected SecurityReference anotherSpaceDocRef; |
| 58 |
|
protected SecurityReference anotherWikiDocRef; |
| 59 |
|
protected SecurityReference xwikiPreferencesDocRef; |
| 60 |
|
protected SecurityReference webPreferencesDocRef; |
| 61 |
|
|
| 62 |
|
protected SecurityReference xattachmentRef; |
| 63 |
|
|
| 64 |
|
protected List<SecurityReference> entityRefs; |
| 65 |
|
|
| 66 |
|
protected SecurityReference xXWikiSpace; |
| 67 |
|
protected SecurityReference xwikiSpace; |
| 68 |
|
protected SecurityReference anotherWikiXWikiSpace; |
| 69 |
|
|
| 70 |
|
protected List<SecurityReference> xwikiSpaceRefs; |
| 71 |
|
|
| 72 |
|
protected UserSecurityReference xuserRef; |
| 73 |
|
protected UserSecurityReference userRef; |
| 74 |
|
protected UserSecurityReference creatorRef; |
| 75 |
|
protected UserSecurityReference ownerRef; |
| 76 |
|
protected UserSecurityReference anotherXuserRef; |
| 77 |
|
protected UserSecurityReference anotherUserRef; |
| 78 |
|
protected UserSecurityReference anotherWikiUserRef; |
| 79 |
|
protected UserSecurityReference defaultUserRef; |
| 80 |
|
|
| 81 |
|
protected GroupSecurityReference groupRef; |
| 82 |
|
protected GroupSecurityReference anotherGroupRef; |
| 83 |
|
|
| 84 |
|
protected GroupSecurityReference xgroupRef; |
| 85 |
|
protected GroupSecurityReference anotherXGroupRef; |
| 86 |
|
|
| 87 |
|
protected UserSecurityReference groupUserRef; |
| 88 |
|
protected UserSecurityReference anotherGroupUserRef; |
| 89 |
|
protected UserSecurityReference bothGroupUserRef; |
| 90 |
|
|
| 91 |
|
protected UserSecurityReference groupXUserRef; |
| 92 |
|
protected UserSecurityReference anotherGroupXUserRef; |
| 93 |
|
protected UserSecurityReference bothGroupXUserRef; |
| 94 |
|
|
| 95 |
|
protected List<UserSecurityReference> userRefs; |
| 96 |
|
protected List<UserSecurityReference> groupUserRefs; |
| 97 |
|
|
| 98 |
|
protected Map<GroupSecurityReference, List<UserSecurityReference>> groupRefs |
| 99 |
|
= new HashMap<GroupSecurityReference, List<UserSecurityReference>>(); |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
private SecurityReference mainWikiReference; |
| 103 |
|
|
| 104 |
|
@return |
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 105 |
532 |
private SecurityReference getMainWikiReference()... |
| 106 |
|
{ |
| 107 |
532 |
if (mainWikiReference == null) { |
| 108 |
14 |
mainWikiReference = new SecurityReference(new WikiReference("xwiki")); |
| 109 |
|
} |
| 110 |
532 |
return mainWikiReference; |
| 111 |
|
} |
| 112 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 113 |
280 |
private SecurityReference newEntityReference(EntityReference reference)... |
| 114 |
|
{ |
| 115 |
280 |
return new SecurityReference(reference, getMainWikiReference()); |
| 116 |
|
} |
| 117 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 118 |
196 |
private UserSecurityReference newUserReference(DocumentReference reference)... |
| 119 |
|
{ |
| 120 |
196 |
return new UserSecurityReference(reference, getMainWikiReference()); |
| 121 |
|
} |
| 122 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 123 |
56 |
private GroupSecurityReference newGroupReference(DocumentReference reference)... |
| 124 |
|
{ |
| 125 |
56 |
return new GroupSecurityReference(reference, getMainWikiReference()); |
| 126 |
|
} |
| 127 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (47) |
Complexity: 1 |
Complexity Density: 0.02 |
|
| 128 |
14 |
@Before... |
| 129 |
|
public void setUp() throws Exception |
| 130 |
|
{ |
| 131 |
14 |
xwikiRef = newEntityReference(new WikiReference("xwiki")); |
| 132 |
14 |
wikiRef = newEntityReference(new WikiReference("wiki")); |
| 133 |
14 |
anotherWikiRef = newEntityReference(new WikiReference("anotherWiki")); |
| 134 |
|
|
| 135 |
14 |
wikiRefs = Arrays.asList(xwikiRef, wikiRef, anotherWikiRef); |
| 136 |
|
|
| 137 |
14 |
xspaceRef = newEntityReference(new SpaceReference("space", xwikiRef.getOriginalWikiReference())); |
| 138 |
14 |
anotherXspaceRef = newEntityReference(new SpaceReference("anotherSpace", |
| 139 |
|
xwikiRef.getOriginalWikiReference())); |
| 140 |
14 |
spaceRef = newEntityReference(new SpaceReference("space", wikiRef.getOriginalWikiReference())); |
| 141 |
14 |
anotherSpaceRef = newEntityReference(new SpaceReference("anotherSpace", |
| 142 |
|
wikiRef.getOriginalWikiReference())); |
| 143 |
14 |
anotherWikiSpaceRef = newEntityReference(new SpaceReference("space", |
| 144 |
|
anotherWikiRef.getOriginalWikiReference())); |
| 145 |
|
|
| 146 |
14 |
xdocRef = newEntityReference(new DocumentReference("page", xspaceRef.getOriginalSpaceReference())); |
| 147 |
14 |
anotherXdocRef = newEntityReference(new DocumentReference("anotherPage", |
| 148 |
|
xspaceRef.getOriginalSpaceReference())); |
| 149 |
14 |
docRef = newEntityReference(new DocumentReference("page", spaceRef.getOriginalSpaceReference())); |
| 150 |
14 |
anotherDocRef = newEntityReference(new DocumentReference("anotherPage", |
| 151 |
|
spaceRef.getOriginalSpaceReference())); |
| 152 |
14 |
anotherSpaceDocRef = newEntityReference(new DocumentReference("page", |
| 153 |
|
anotherSpaceRef.getOriginalSpaceReference())); |
| 154 |
14 |
anotherWikiDocRef = newEntityReference(new DocumentReference("page", |
| 155 |
|
anotherWikiSpaceRef.getOriginalSpaceReference())); |
| 156 |
|
|
| 157 |
14 |
xattachmentRef = newEntityReference(new AttachmentReference("file.ext", xdocRef.getOriginalDocumentReference())); |
| 158 |
|
|
| 159 |
14 |
xXWikiSpace = newEntityReference(new SpaceReference("XWiki", xwikiRef.getOriginalWikiReference())); |
| 160 |
14 |
xwikiSpace = newEntityReference(new SpaceReference("XWiki", wikiRef.getOriginalWikiReference())); |
| 161 |
14 |
anotherWikiXWikiSpace = newEntityReference(new SpaceReference("XWiki", |
| 162 |
|
anotherWikiRef.getOriginalWikiReference())); |
| 163 |
|
|
| 164 |
14 |
xwikiPreferencesDocRef = newEntityReference(new DocumentReference("XWikiPreferences", xwikiSpace.getOriginalSpaceReference())); |
| 165 |
14 |
webPreferencesDocRef = newEntityReference(new DocumentReference("WebPreferences", spaceRef.getOriginalSpaceReference())); |
| 166 |
|
|
| 167 |
14 |
xuserRef = newUserReference(new DocumentReference("user", xXWikiSpace.getOriginalSpaceReference())); |
| 168 |
14 |
ownerRef = newUserReference(new DocumentReference("owner", xXWikiSpace.getOriginalSpaceReference())); |
| 169 |
14 |
userRef = newUserReference(new DocumentReference("user", xwikiSpace.getOriginalSpaceReference())); |
| 170 |
14 |
creatorRef = newUserReference(new DocumentReference("creator", xwikiSpace.getOriginalSpaceReference())); |
| 171 |
14 |
anotherXuserRef = newUserReference(new DocumentReference("anotherUser", |
| 172 |
|
xXWikiSpace.getOriginalSpaceReference())); |
| 173 |
14 |
anotherUserRef = newUserReference(new DocumentReference("anotherUser", |
| 174 |
|
xwikiSpace.getOriginalSpaceReference())); |
| 175 |
14 |
anotherWikiUserRef = newUserReference(new DocumentReference("user", |
| 176 |
|
anotherWikiXWikiSpace.getOriginalSpaceReference())); |
| 177 |
14 |
defaultUserRef = newUserReference(new DocumentReference("default", xwikiSpace.getOriginalSpaceReference())); |
| 178 |
|
|
| 179 |
14 |
groupRef = newGroupReference(new DocumentReference("group", xwikiSpace.getOriginalSpaceReference())); |
| 180 |
14 |
anotherGroupRef = newGroupReference( |
| 181 |
|
new DocumentReference("anotherGroup", xwikiSpace.getOriginalSpaceReference())); |
| 182 |
|
|
| 183 |
14 |
xgroupRef = newGroupReference(new DocumentReference("xgroup", xXWikiSpace.getOriginalSpaceReference())); |
| 184 |
14 |
anotherXGroupRef = newGroupReference( |
| 185 |
|
new DocumentReference("anotherXGroup", xXWikiSpace.getOriginalSpaceReference())); |
| 186 |
|
|
| 187 |
14 |
groupUserRef = newUserReference(new DocumentReference("groupUser", xwikiSpace.getOriginalSpaceReference())); |
| 188 |
14 |
anotherGroupUserRef = newUserReference(new DocumentReference("anotherGroupUser", xwikiSpace.getOriginalSpaceReference())); |
| 189 |
14 |
bothGroupUserRef = newUserReference(new DocumentReference("bothGroupUserRef", xwikiSpace.getOriginalSpaceReference())); |
| 190 |
|
|
| 191 |
14 |
groupXUserRef = newUserReference(new DocumentReference("groupXUser", xXWikiSpace.getOriginalSpaceReference())); |
| 192 |
14 |
anotherGroupXUserRef = newUserReference(new DocumentReference("anotherGroupXUser", xXWikiSpace.getOriginalSpaceReference())); |
| 193 |
14 |
bothGroupXUserRef = newUserReference(new DocumentReference("bothGroupXUserRef", xXWikiSpace.getOriginalSpaceReference())); |
| 194 |
|
|
| 195 |
14 |
entityRefs = Arrays.asList(xwikiRef, wikiRef, xspaceRef, spaceRef, xdocRef, docRef, anotherXspaceRef, |
| 196 |
|
anotherXdocRef, anotherSpaceRef, anotherSpaceDocRef, anotherDocRef, anotherWikiRef, anotherWikiSpaceRef, |
| 197 |
|
anotherWikiDocRef); |
| 198 |
|
|
| 199 |
14 |
xwikiSpaceRefs = Arrays.asList(xXWikiSpace, xwikiSpace, anotherWikiXWikiSpace); |
| 200 |
|
|
| 201 |
14 |
userRefs = Arrays.asList(xuserRef, userRef, anotherXuserRef, anotherUserRef, anotherWikiUserRef); |
| 202 |
|
|
| 203 |
14 |
groupUserRefs = Arrays.asList(groupUserRef, anotherGroupUserRef, bothGroupUserRef, groupXUserRef, anotherGroupXUserRef, bothGroupXUserRef); |
| 204 |
14 |
groupRefs.put(groupRef, Arrays.asList(groupUserRef, bothGroupUserRef, groupXUserRef, bothGroupXUserRef)); |
| 205 |
14 |
groupRefs.put(anotherGroupRef, Arrays.asList(anotherGroupUserRef, bothGroupUserRef, anotherGroupXUserRef, bothGroupXUserRef)); |
| 206 |
14 |
groupRefs.put(xgroupRef, Arrays.asList(groupXUserRef, bothGroupXUserRef)); |
| 207 |
14 |
groupRefs.put(anotherXGroupRef, Arrays.asList(anotherGroupXUserRef, bothGroupXUserRef)); |
| 208 |
|
} |
| 209 |
|
} |