NIHVIVO-1232 refactor the SelfEditingPolicyTest
This commit is contained in:
parent
10dc4d3e1f
commit
6702667ccf
1 changed files with 184 additions and 266 deletions
|
@ -2,6 +2,12 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.auth.policy;
|
package edu.cornell.mannlib.vitro.webapp.auth.policy;
|
||||||
|
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization.AUTHORIZED;
|
||||||
|
import static edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization.INCONCLUSIVE;
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
import static junit.framework.Assert.assertNotNull;
|
||||||
|
import static junit.framework.Assert.assertNull;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -17,7 +23,6 @@ import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddDataPropStmt;
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddDataPropStmt;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddObjectPropStmt;
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddObjectPropStmt;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropDataPropStmt;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropObjectPropStmt;
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropObjectPropStmt;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditDataPropStmt;
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditDataPropStmt;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditObjPropStmt;
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditObjPropStmt;
|
||||||
|
@ -39,18 +44,19 @@ import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
|
|
||||||
public class SelfEditingPolicyTest extends AbstractTestClass {
|
public class SelfEditingPolicyTest extends AbstractTestClass {
|
||||||
|
|
||||||
String SAFE_NS = "http://test.mannlib.cornell.edu/ns/01#";
|
private static final String SAFE_NS = "http://test.mannlib.cornell.edu/ns/01#";
|
||||||
String UNSAFE_NS = VitroVocabulary.vitroURI;
|
private static final String UNSAFE_NS = VitroVocabulary.vitroURI;
|
||||||
|
|
||||||
String SELFEDITOR_URI =SAFE_NS + "individual244";
|
private static final String SELFEDITOR_URI = SAFE_NS + "individual244";
|
||||||
String SAFE_RESOURCE = SAFE_NS + "otherIndividual77777";
|
private static final String SAFE_RESOURCE = SAFE_NS + "otherIndividual77777";
|
||||||
String UNSAFE_RESOURCE = UNSAFE_NS + "otherIndividual99999";
|
private static final String UNSAFE_RESOURCE = UNSAFE_NS + "otherIndividual99999";
|
||||||
|
|
||||||
String SAFE_PREDICATE= SAFE_NS + "hasHairStyle";
|
private static final String SAFE_PREDICATE = SAFE_NS + "hasHairStyle";
|
||||||
String UNSAFE_PREDICATE = UNSAFE_NS + "hasSuperPowers";
|
private static final String UNSAFE_PREDICATE = UNSAFE_NS + "hasSuperPowers";
|
||||||
|
|
||||||
SelfEditingPolicy policy ;
|
private SelfEditingPolicy policy;
|
||||||
IdentifierBundle ids;
|
private IdentifierBundle ids;
|
||||||
|
private RequestedAction whatToAuth;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
@ -94,90 +100,62 @@ public class SelfEditingPolicyTest extends AbstractTestClass {
|
||||||
badProps.add("http://mannlib.cornell.edu/bad#prp0020");
|
badProps.add("http://mannlib.cornell.edu/bad#prp0020");
|
||||||
SelfEditingPolicy badPropPolicy = new SelfEditingPolicy(badProps, null, null, null, null);
|
SelfEditingPolicy badPropPolicy = new SelfEditingPolicy(badProps, null, null, null, null);
|
||||||
|
|
||||||
RequestedAction whatToAuth = new AddObjectPropStmt(
|
whatToAuth = new AddObjectPropStmt(SELFEDITOR_URI,
|
||||||
SELFEDITOR_URI,"http://mannlib.cornell.edu/bad#prp234" ,SAFE_RESOURCE);
|
"http://mannlib.cornell.edu/bad#prp234", SAFE_RESOURCE);
|
||||||
PolicyDecision dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, badPropPolicy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddObjectPropStmt(
|
whatToAuth = new AddObjectPropStmt(SAFE_RESOURCE,
|
||||||
SAFE_RESOURCE ,"http://mannlib.cornell.edu/bad#prp234", SELFEDITOR_URI);
|
"http://mannlib.cornell.edu/bad#prp234", SELFEDITOR_URI);
|
||||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, badPropPolicy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddObjectPropStmt(
|
whatToAuth = new AddObjectPropStmt(SELFEDITOR_URI,
|
||||||
SELFEDITOR_URI,"http://mannlib.cornell.edu/bad#prp999" ,SAFE_RESOURCE);
|
"http://mannlib.cornell.edu/bad#prp999", SAFE_RESOURCE);
|
||||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, badPropPolicy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddObjectPropStmt(
|
whatToAuth = new AddObjectPropStmt(
|
||||||
SAFE_RESOURCE ,"http://mannlib.cornell.edu/bad#prp999", SELFEDITOR_URI);
|
SAFE_RESOURCE ,"http://mannlib.cornell.edu/bad#prp999", SELFEDITOR_URI);
|
||||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, badPropPolicy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddObjectPropStmt(
|
whatToAuth = new AddObjectPropStmt(
|
||||||
SAFE_RESOURCE ,SAFE_PREDICATE, SELFEDITOR_URI);
|
SAFE_RESOURCE ,SAFE_PREDICATE, SELFEDITOR_URI);
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
assertDecision(AUTHORIZED, policy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddObjectPropStmt(
|
whatToAuth = new AddObjectPropStmt(
|
||||||
SELFEDITOR_URI,SAFE_PREDICATE,SAFE_RESOURCE);
|
SELFEDITOR_URI,SAFE_PREDICATE,SAFE_RESOURCE);
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
assertDecision(AUTHORIZED, policy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddObjectPropStmt(
|
whatToAuth = new AddObjectPropStmt(
|
||||||
SELFEDITOR_URI, UNSAFE_PREDICATE, SAFE_RESOURCE);
|
SELFEDITOR_URI, UNSAFE_PREDICATE, SAFE_RESOURCE);
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
//now with dataprop statements
|
//now with dataprop statements
|
||||||
whatToAuth = new AddDataPropStmt(
|
whatToAuth = new AddDataPropStmt(
|
||||||
SELFEDITOR_URI,"http://mannlib.cornell.edu/bad#prp234" ,SAFE_RESOURCE, null, null);
|
SELFEDITOR_URI,"http://mannlib.cornell.edu/bad#prp234" ,SAFE_RESOURCE, null, null);
|
||||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, badPropPolicy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddDataPropStmt(
|
whatToAuth = new AddDataPropStmt(
|
||||||
SAFE_RESOURCE ,"http://mannlib.cornell.edu/bad#prp234", SELFEDITOR_URI, null, null);
|
SAFE_RESOURCE ,"http://mannlib.cornell.edu/bad#prp234", SELFEDITOR_URI, null, null);
|
||||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, badPropPolicy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddDataPropStmt(
|
whatToAuth = new AddDataPropStmt(
|
||||||
SELFEDITOR_URI,"http://mannlib.cornell.edu/bad#prp999" ,SAFE_RESOURCE, null, null);
|
SELFEDITOR_URI,"http://mannlib.cornell.edu/bad#prp999" ,SAFE_RESOURCE, null, null);
|
||||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, badPropPolicy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddDataPropStmt(
|
whatToAuth = new AddDataPropStmt(
|
||||||
SAFE_RESOURCE ,"http://mannlib.cornell.edu/bad#prp999", SELFEDITOR_URI, null, null);
|
SAFE_RESOURCE ,"http://mannlib.cornell.edu/bad#prp999", SELFEDITOR_URI, null, null);
|
||||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, badPropPolicy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddDataPropStmt(
|
whatToAuth = new AddDataPropStmt(
|
||||||
SAFE_RESOURCE ,SAFE_PREDICATE, SELFEDITOR_URI, null, null);
|
SAFE_RESOURCE ,SAFE_PREDICATE, SELFEDITOR_URI, null, null);
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddDataPropStmt(
|
whatToAuth = new AddDataPropStmt(
|
||||||
SELFEDITOR_URI,SAFE_PREDICATE,SAFE_RESOURCE, null, null);
|
SELFEDITOR_URI,SAFE_PREDICATE,SAFE_RESOURCE, null, null);
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
assertDecision(AUTHORIZED, policy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddDataPropStmt(
|
whatToAuth = new AddDataPropStmt(
|
||||||
SELFEDITOR_URI, UNSAFE_PREDICATE, SAFE_RESOURCE, null, null);
|
SELFEDITOR_URI, UNSAFE_PREDICATE, SAFE_RESOURCE, null, null);
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -186,28 +164,20 @@ public class SelfEditingPolicyTest extends AbstractTestClass {
|
||||||
badProps.add(VitroVocabulary.MONIKER);
|
badProps.add(VitroVocabulary.MONIKER);
|
||||||
SelfEditingPolicy badPropPolicy = new SelfEditingPolicy(badProps,null,null,null,null);
|
SelfEditingPolicy badPropPolicy = new SelfEditingPolicy(badProps,null,null,null,null);
|
||||||
|
|
||||||
RequestedAction whatToAuth = null;
|
|
||||||
|
|
||||||
whatToAuth = new AddDataPropStmt(
|
whatToAuth = new AddDataPropStmt(
|
||||||
SELFEDITOR_URI, VitroVocabulary.MONIKER ,"someValue", null, null);
|
SELFEDITOR_URI, VitroVocabulary.MONIKER ,"someValue", null, null);
|
||||||
PolicyDecision dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, badPropPolicy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddDataPropStmt(
|
whatToAuth = new AddDataPropStmt(
|
||||||
SAFE_RESOURCE ,VitroVocabulary.MONIKER , "somevalue", null, null);
|
SAFE_RESOURCE ,VitroVocabulary.MONIKER , "somevalue", null, null);
|
||||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, badPropPolicy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
DataPropertyStatement dps = new DataPropertyStatementImpl();
|
DataPropertyStatement dps = new DataPropertyStatementImpl();
|
||||||
dps.setIndividualURI(SELFEDITOR_URI);
|
dps.setIndividualURI(SELFEDITOR_URI);
|
||||||
dps.setDatapropURI(VitroVocabulary.MONIKER);
|
dps.setDatapropURI(VitroVocabulary.MONIKER);
|
||||||
dps.setData("some moniker");
|
dps.setData("some moniker");
|
||||||
whatToAuth = new EditDataPropStmt(dps);
|
whatToAuth = new EditDataPropStmt(dps);
|
||||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, badPropPolicy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
|
|
||||||
//try where moniker is permitted
|
//try where moniker is permitted
|
||||||
|
@ -216,59 +186,39 @@ public class SelfEditingPolicyTest extends AbstractTestClass {
|
||||||
|
|
||||||
whatToAuth = new AddDataPropStmt(
|
whatToAuth = new AddDataPropStmt(
|
||||||
SELFEDITOR_URI, VitroVocabulary.MONIKER ,"somevalue", null, null);
|
SELFEDITOR_URI, VitroVocabulary.MONIKER ,"somevalue", null, null);
|
||||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
assertDecision(AUTHORIZED, badPropPolicy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddDataPropStmt(
|
whatToAuth = new AddDataPropStmt(
|
||||||
UNSAFE_RESOURCE ,VitroVocabulary.MONIKER , "somevalue", null, null);
|
UNSAFE_RESOURCE ,VitroVocabulary.MONIKER , "somevalue", null, null);
|
||||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, badPropPolicy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
dps = new DataPropertyStatementImpl();
|
dps = new DataPropertyStatementImpl();
|
||||||
dps.setIndividualURI(SAFE_RESOURCE);
|
dps.setIndividualURI(SAFE_RESOURCE);
|
||||||
dps.setDatapropURI(VitroVocabulary.MONIKER);
|
dps.setDatapropURI(VitroVocabulary.MONIKER);
|
||||||
dps.setData("some moniker");
|
dps.setData("some moniker");
|
||||||
whatToAuth = new EditDataPropStmt(dps);
|
whatToAuth = new EditDataPropStmt(dps);
|
||||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, badPropPolicy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVisitIdentifierBundleAddObjectPropStmt() {
|
public void testVisitIdentifierBundleAddObjectPropStmt() {
|
||||||
AddObjectPropStmt whatToAuth = new AddObjectPropStmt(
|
AddObjectPropStmt whatToAuth = new AddObjectPropStmt(SELFEDITOR_URI, SAFE_PREDICATE, SAFE_RESOURCE);
|
||||||
SELFEDITOR_URI,SAFE_PREDICATE,SAFE_RESOURCE);
|
assertDecision(AUTHORIZED, policy.isAuthorized(ids, whatToAuth));
|
||||||
PolicyDecision dec = policy.isAuthorized(ids, whatToAuth);
|
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddObjectPropStmt(
|
whatToAuth = new AddObjectPropStmt(SAFE_RESOURCE, SAFE_PREDICATE, SELFEDITOR_URI);
|
||||||
SAFE_RESOURCE ,SAFE_PREDICATE, SELFEDITOR_URI);
|
assertDecision(AUTHORIZED, policy.isAuthorized(ids, whatToAuth));
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
|
||||||
|
|
||||||
// this is the case where the editor is not part of the stmt
|
// this is the case where the editor is not part of the stmt
|
||||||
whatToAuth = new AddObjectPropStmt(
|
whatToAuth = new AddObjectPropStmt(SAFE_RESOURCE, SAFE_PREDICATE, SAFE_RESOURCE);
|
||||||
SAFE_RESOURCE, SAFE_PREDICATE, SAFE_RESOURCE);
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddObjectPropStmt(
|
whatToAuth = new AddObjectPropStmt(SELFEDITOR_URI, UNSAFE_PREDICATE, SAFE_RESOURCE);
|
||||||
SELFEDITOR_URI, UNSAFE_PREDICATE, SAFE_RESOURCE);
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new AddObjectPropStmt(
|
whatToAuth = new AddObjectPropStmt(SELFEDITOR_URI, SAFE_PREDICATE, UNSAFE_RESOURCE);
|
||||||
SELFEDITOR_URI, SAFE_PREDICATE, UNSAFE_RESOURCE);
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// @Test
|
// @Test
|
||||||
// public void testVisitIdentifierBundleDropResource() {
|
// public void testVisitIdentifierBundleDropResource() {
|
||||||
|
@ -284,34 +234,24 @@ public class SelfEditingPolicyTest extends AbstractTestClass {
|
||||||
public void testVisitIdentifierBundleDropObjectPropStmt() {
|
public void testVisitIdentifierBundleDropObjectPropStmt() {
|
||||||
DropObjectPropStmt whatToAuth = new DropObjectPropStmt(
|
DropObjectPropStmt whatToAuth = new DropObjectPropStmt(
|
||||||
SELFEDITOR_URI,SAFE_PREDICATE,SAFE_RESOURCE);
|
SELFEDITOR_URI,SAFE_PREDICATE,SAFE_RESOURCE);
|
||||||
PolicyDecision dec = policy.isAuthorized(ids, whatToAuth);
|
assertDecision(AUTHORIZED, policy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new DropObjectPropStmt(
|
whatToAuth = new DropObjectPropStmt(
|
||||||
SAFE_RESOURCE ,SAFE_PREDICATE, SELFEDITOR_URI);
|
SAFE_RESOURCE ,SAFE_PREDICATE, SELFEDITOR_URI);
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
assertDecision(AUTHORIZED, policy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
|
||||||
|
|
||||||
// this is the case where the editor is not part of the stmt
|
// this is the case where the editor is not part of the stmt
|
||||||
whatToAuth = new DropObjectPropStmt(
|
whatToAuth = new DropObjectPropStmt(
|
||||||
SAFE_RESOURCE, SAFE_PREDICATE, SAFE_RESOURCE);
|
SAFE_RESOURCE, SAFE_PREDICATE, SAFE_RESOURCE);
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new DropObjectPropStmt(
|
whatToAuth = new DropObjectPropStmt(
|
||||||
SELFEDITOR_URI, UNSAFE_PREDICATE, SAFE_RESOURCE);
|
SELFEDITOR_URI, UNSAFE_PREDICATE, SAFE_RESOURCE);
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new DropObjectPropStmt(
|
whatToAuth = new DropObjectPropStmt(
|
||||||
SELFEDITOR_URI, SAFE_PREDICATE, UNSAFE_RESOURCE);
|
SELFEDITOR_URI, SAFE_PREDICATE, UNSAFE_RESOURCE);
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// @Test
|
// @Test
|
||||||
|
@ -338,143 +278,121 @@ public class SelfEditingPolicyTest extends AbstractTestClass {
|
||||||
dps.setDatapropURI(SAFE_PREDICATE);
|
dps.setDatapropURI(SAFE_PREDICATE);
|
||||||
dps.setData("junk");
|
dps.setData("junk");
|
||||||
EditDataPropStmt whatToAuth = new EditDataPropStmt(dps);
|
EditDataPropStmt whatToAuth = new EditDataPropStmt(dps);
|
||||||
PolicyDecision dec = policy.isAuthorized(ids, whatToAuth);
|
assertDecision(AUTHORIZED, policy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
|
||||||
|
|
||||||
dps = new DataPropertyStatementImpl();
|
dps = new DataPropertyStatementImpl();
|
||||||
dps.setIndividualURI(SELFEDITOR_URI);
|
dps.setIndividualURI(SELFEDITOR_URI);
|
||||||
dps.setDatapropURI(UNSAFE_PREDICATE);
|
dps.setDatapropURI(UNSAFE_PREDICATE);
|
||||||
dps.setData("junk");
|
dps.setData("junk");
|
||||||
whatToAuth = new EditDataPropStmt(dps);
|
whatToAuth = new EditDataPropStmt(dps);
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
dps = new DataPropertyStatementImpl();
|
dps = new DataPropertyStatementImpl();
|
||||||
dps.setIndividualURI(UNSAFE_RESOURCE);
|
dps.setIndividualURI(UNSAFE_RESOURCE);
|
||||||
dps.setDatapropURI(SAFE_PREDICATE);
|
dps.setDatapropURI(SAFE_PREDICATE);
|
||||||
whatToAuth = new EditDataPropStmt(dps);
|
whatToAuth = new EditDataPropStmt(dps);
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
dps = new DataPropertyStatementImpl();
|
dps = new DataPropertyStatementImpl();
|
||||||
dps.setIndividualURI(SAFE_RESOURCE);
|
dps.setIndividualURI(SAFE_RESOURCE);
|
||||||
dps.setDatapropURI(SAFE_PREDICATE);
|
dps.setDatapropURI(SAFE_PREDICATE);
|
||||||
whatToAuth = new EditDataPropStmt(dps);
|
whatToAuth = new EditDataPropStmt(dps);
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
}
|
}
|
||||||
//
|
|
||||||
@Test
|
@Test
|
||||||
public void testVisitIdentifierBundleEditObjPropStmt() {
|
public void testVisitIdentifierBundleEditObjPropStmt() {
|
||||||
EditObjPropStmt whatToAuth = new EditObjPropStmt(
|
EditObjPropStmt whatToAuth = new EditObjPropStmt(SELFEDITOR_URI, SAFE_PREDICATE, SAFE_RESOURCE);
|
||||||
SELFEDITOR_URI,SAFE_PREDICATE,SAFE_RESOURCE);
|
assertDecision(AUTHORIZED, policy.isAuthorized(ids, whatToAuth));
|
||||||
PolicyDecision dec = policy.isAuthorized(ids, whatToAuth);
|
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new EditObjPropStmt(
|
whatToAuth = new EditObjPropStmt(SAFE_RESOURCE, SAFE_PREDICATE, SELFEDITOR_URI);
|
||||||
SAFE_RESOURCE ,SAFE_PREDICATE, SELFEDITOR_URI);
|
assertDecision(AUTHORIZED, policy.isAuthorized(ids, whatToAuth));
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
|
||||||
|
|
||||||
// this is the case where the editor is not part of the stmt
|
// this is the case where the editor is not part of the stmt
|
||||||
whatToAuth = new EditObjPropStmt(
|
whatToAuth = new EditObjPropStmt(SAFE_RESOURCE, SAFE_PREDICATE, SAFE_RESOURCE);
|
||||||
SAFE_RESOURCE, SAFE_PREDICATE, SAFE_RESOURCE);
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new EditObjPropStmt(
|
whatToAuth = new EditObjPropStmt(SELFEDITOR_URI, UNSAFE_PREDICATE, SAFE_RESOURCE);
|
||||||
SELFEDITOR_URI, UNSAFE_PREDICATE, SAFE_RESOURCE);
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
|
|
||||||
whatToAuth = new EditObjPropStmt(
|
whatToAuth = new EditObjPropStmt(SELFEDITOR_URI, SAFE_PREDICATE, UNSAFE_RESOURCE);
|
||||||
SELFEDITOR_URI, SAFE_PREDICATE, UNSAFE_RESOURCE);
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, whatToAuth));
|
||||||
dec = policy.isAuthorized(ids, whatToAuth);
|
|
||||||
Assert.assertNotNull(dec);
|
|
||||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Ignore administrative requests.
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVisitIdentifierBundleServerStatus() {
|
public void testServerStatus() {
|
||||||
PolicyDecision dec = policy.isAuthorized(ids, new ServerStatus() );
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, new ServerStatus()));
|
||||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVisitIdentifierBundleCreateOwlClass() {
|
public void testCreateOwlClass() {
|
||||||
CreateOwlClass a = new CreateOwlClass();
|
CreateOwlClass a = new CreateOwlClass();
|
||||||
a.setSubjectUri("http://someClass/test");
|
a.setSubjectUri("http://someClass/test");
|
||||||
PolicyDecision dec = policy.visit(ids, a );
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, a));
|
||||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVisitIdentifierBundleRemoveOwlClass() {
|
public void testRemoveOwlClass() {
|
||||||
RemoveOwlClass a = new RemoveOwlClass();
|
RemoveOwlClass a = new RemoveOwlClass();
|
||||||
a.setSubjectUri("http://someClass/test");
|
a.setSubjectUri("http://someClass/test");
|
||||||
PolicyDecision dec = policy.visit(ids, a );
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, a));
|
||||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVisitIdentifierBundleDefineDataProperty() {
|
public void testDefineDataProperty() {
|
||||||
DefineDataProperty a = new DefineDataProperty();
|
DefineDataProperty a = new DefineDataProperty();
|
||||||
a.setSubjectUri("http://someClass/test");
|
a.setSubjectUri("http://someClass/test");
|
||||||
PolicyDecision dec = policy.visit(ids, a );
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, a));
|
||||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVisitIdentifierBundleDefineObjectProperty() {
|
public void testDefineObjectProperty() {
|
||||||
DefineObjectProperty a = new DefineObjectProperty();
|
DefineObjectProperty a = new DefineObjectProperty();
|
||||||
a.setSubjectUri("http://someClass/test");
|
a.setSubjectUri("http://someClass/test");
|
||||||
PolicyDecision dec = policy.visit(ids, a );
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, a));
|
||||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVisitIdentifierBundleAddNewUser() {
|
public void testAddNewUser() {
|
||||||
AddNewUser a = new AddNewUser();
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, new AddNewUser()));
|
||||||
PolicyDecision dec = policy.visit(ids, a );
|
|
||||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVisitIdentifierBundleRemoveUser() {
|
public void testRemoveUser() {
|
||||||
RemoveUser a = new RemoveUser();
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, new RemoveUser()));
|
||||||
PolicyDecision dec = policy.visit(ids, a );
|
|
||||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVisitIdentifierBundleLoadOntology() {
|
public void testLoadOntology() {
|
||||||
LoadOntology a = new LoadOntology();
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, new LoadOntology()));
|
||||||
PolicyDecision dec = policy.visit(ids, a );
|
|
||||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVisitIdentifierBundleRebuildTextIndex() {
|
public void testRebuildTextIndex() {
|
||||||
RebuildTextIndex a = new RebuildTextIndex();
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, new RebuildTextIndex()));
|
||||||
PolicyDecision dec = policy.visit(ids, a );
|
|
||||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVisitIdentifierBundleUpdateTextIndex() {
|
public void testVisitIdentifierBundleUpdateTextIndex() {
|
||||||
UpdateTextIndex a = new UpdateTextIndex();
|
assertDecision(INCONCLUSIVE, policy.isAuthorized(ids, new UpdateTextIndex()));
|
||||||
PolicyDecision dec = policy.visit(ids, a );
|
|
||||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Helper methods
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
private void assertDecision(Authorization expectedAuth,
|
||||||
|
PolicyDecision decision) {
|
||||||
|
if (expectedAuth == null) {
|
||||||
|
assertNull("expecting null decision", decision);
|
||||||
|
} else {
|
||||||
|
assertNotNull("expecting a decision", decision);
|
||||||
|
assertEquals("wrong authorization", expectedAuth,
|
||||||
|
decision.getAuthorized());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue