1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.security.authorization

File AbstractAdditionalRightsTestCase.java

 

Coverage histogram

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

Code metrics

0
25
11
2
138
94
11
0.44
2.27
5.5
1

Classes

Class Line # Actions
AbstractAdditionalRightsTestCase 44 12 0% 2 0
1.0100%
AbstractAdditionalRightsTestCase.TestRightDescription 46 13 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.authorization;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24    import java.util.Set;
25   
26    import org.junit.BeforeClass;
27    import org.junit.runner.RunWith;
28    import org.xwiki.model.EntityType;
29    import org.xwiki.security.AbstractSecurityTestCase;
30    import org.xwiki.test.isolation.IsolatedTestRunner;
31    import org.xwiki.test.isolation.IsolatedClassPrefix;
32   
33    import static org.xwiki.security.authorization.RuleState.ALLOW;
34    import static org.xwiki.security.authorization.RuleState.DENY;
35   
36    /**
37    * A base class for authorization tests, defining some additional Rights.
38    *
39    * @version $Id: 0e37d232422392afd11f6ba7aa71f607baeef134 $
40    * @since 4.0M2
41    */
42    @RunWith(IsolatedTestRunner.class)
43    @IsolatedClassPrefix("org.xwiki.security")
 
44    public abstract class AbstractAdditionalRightsTestCase extends AbstractSecurityTestCase
45    {
 
46    private static class TestRightDescription implements RightDescription
47    {
48    private String name;
49    private RuleState defaultState;
50    private RuleState tieResolution;
51    private boolean override;
52    private Set<Right> impliedRights;
53   
 
54  11 toggle TestRightDescription(String name, RuleState defaultState, RuleState tieResolution, boolean override)
55    {
56  11 this.name = name;
57  11 this.defaultState = defaultState;
58  11 this.tieResolution = tieResolution;
59  11 this.override = override;
60    }
61   
 
62  2 toggle TestRightDescription(String name, RuleState defaultState, RuleState tieResolution, boolean override,
63    Set<Right> impliedRights)
64    {
65  2 this(name, defaultState, tieResolution, override);
66  2 this.impliedRights = impliedRights;
67    }
68   
 
69  11 toggle @Override
70    public String getName()
71    {
72  11 return name;
73    }
74   
 
75  11 toggle @Override
76    public RuleState getDefaultState()
77    {
78  11 return defaultState;
79    }
80   
 
81  11 toggle @Override
82    public RuleState getTieResolutionPolicy()
83    {
84  11 return tieResolution;
85    }
86   
 
87  11 toggle @Override
88    public boolean getInheritanceOverridePolicy()
89    {
90  11 return override;
91    }
92   
 
93  11 toggle @Override
94    public Set<Right> getImpliedRights()
95    {
96  11 return impliedRights;
97    }
98   
 
99  11 toggle @Override
100    public Set<EntityType> getTargetedEntityType()
101    {
102  11 return Right.WIKI_SPACE_DOCUMENT;
103    }
104   
 
105  11 toggle @Override
106    public boolean isReadOnly()
107    {
108  11 return false;
109    }
110    }
111   
112    protected static List<Right> allTestRights = new ArrayList<Right>();
113   
114    protected static Right impliedTestRightsADT;
115    protected static Right impliedTestRightsDAF;
116   
 
117  1 toggle @BeforeClass
118    public static void oneTimeSetUp()
119    {
120  1 allTestRights.add(getNewTestRight("AllowAllowTrue", ALLOW, ALLOW, true));
121  1 allTestRights.add(getNewTestRight("AllowAllowFalse", ALLOW, ALLOW, false));
122  1 allTestRights.add(getNewTestRight("AllowDenyTrue", ALLOW, DENY, true));
123  1 allTestRights.add(getNewTestRight("AllowDenyFalse", ALLOW, DENY, false));
124  1 allTestRights.add(getNewTestRight("DenyAllowTrue", DENY, ALLOW, true));
125  1 allTestRights.add(getNewTestRight("DenyAllowFalse", DENY, ALLOW, false));
126  1 allTestRights.add(getNewTestRight("DenyDenyTrue", DENY, DENY, true));
127  1 allTestRights.add(getNewTestRight("DenyDenyFalse", DENY, DENY, false));
128   
129  1 Set<Right> allTestRightSet = new RightSet(allTestRights);
130   
131  1 impliedTestRightsADT = new Right(new TestRightDescription("impliedTestRightsADT", ALLOW, DENY, true, allTestRightSet));
132  1 impliedTestRightsDAF = new Right(new TestRightDescription("impliedTestRightsDAF", DENY, ALLOW, false, allTestRightSet));
133    }
134   
 
135  9 toggle public static Right getNewTestRight(String name, RuleState defaultValue, RuleState tieResolution, boolean overridePolicy) {
136  9 return new Right(new TestRightDescription(name, defaultValue, tieResolution, overridePolicy));
137    }
138    }