1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.security

File AbstractSecurityTestCase.java

 

Coverage histogram

../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
53
5
1
209
145
6
0.11
10.6
5
1.2

Classes

Class Line # Actions
AbstractSecurityTestCase 40 53 0% 6 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * A base class for security tests, defining some useful SecurityReference.
36    *
37    * @version $Id: ee0c5fa0cf836750bbf0910b0312bce3bd31686e $
38    * @since 4.0M2
39    */
 
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    /** Cache the main wiki reference. */
102    private SecurityReference mainWikiReference;
103   
104    /** @return the main wiki reference. */
 
105  532 toggle private SecurityReference getMainWikiReference()
106    {
107  532 if (mainWikiReference == null) {
108  14 mainWikiReference = new SecurityReference(new WikiReference("xwiki"));
109    }
110  532 return mainWikiReference;
111    }
112   
 
113  280 toggle private SecurityReference newEntityReference(EntityReference reference)
114    {
115  280 return new SecurityReference(reference, getMainWikiReference());
116    }
117   
 
118  196 toggle private UserSecurityReference newUserReference(DocumentReference reference)
119    {
120  196 return new UserSecurityReference(reference, getMainWikiReference());
121    }
122   
 
123  56 toggle private GroupSecurityReference newGroupReference(DocumentReference reference)
124    {
125  56 return new GroupSecurityReference(reference, getMainWikiReference());
126    }
127   
 
128  14 toggle @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    }