use of org.structr.core.property.PropertyMap in project structr by structr.
the class AccessControlTest method test09PrivilegeEscalation.
@Test
public void test09PrivilegeEscalation() {
// remove auto-generated resource access objects
clearResourceAccess();
try {
final Class principalType = StructrApp.getConfiguration().getNodeEntityClass("Principal");
Principal nonAdmin = (Principal) createTestNode(principalType);
final PropertyKey<Boolean> isAdminKey = StructrApp.key(principalType, "isAdmin");
final SecurityContext userContext = SecurityContext.getInstance(nonAdmin, AccessMode.Frontend);
nonAdmin.setSecurityContext(userContext);
App userApp = StructrApp.getInstance(userContext);
try (final Tx tx = userApp.tx()) {
assertFalse(nonAdmin.isAdmin());
nonAdmin.setProperty(isAdminKey, true);
fail("Privilege escalation using setProperty()-method! Non-admin may not set an admin flag!");
tx.success();
} catch (FrameworkException ex) {
assertFalse("Privilege escalation using setProperty()-method! Non-admin may not set an admin flag!", nonAdmin.isAdmin());
}
try (final Tx tx = userApp.tx()) {
assertFalse(nonAdmin.isAdmin());
PropertyMap props = new PropertyMap();
props.put(isAdminKey, true);
nonAdmin.setProperties(userContext, props);
fail("Privilege escalation using setProperties()-method! Non-admin may not set an admin flag!");
tx.success();
} catch (FrameworkException ex) {
assertFalse("Privilege escalation using setProperties()-method! Non-admin may not set an admin flag!", nonAdmin.isAdmin());
}
} catch (FrameworkException ex) {
fail("Unexpected Exception");
}
}
use of org.structr.core.property.PropertyMap in project structr by structr.
the class BasicTest method test02CreateTwoNodesWithSameUuidInSameTx.
@Test
public void test02CreateTwoNodesWithSameUuidInSameTx() {
try {
final PropertyMap props = new PropertyMap();
TestOne node = null;
final String uuid = StringUtils.replace(UUID.randomUUID().toString(), "-", "");
props.put(GraphObject.id, uuid);
try (final Tx tx = app.tx()) {
node = app.create(TestOne.class, props);
assertTrue(node != null);
assertTrue(node instanceof TestOne);
assertEquals(node.getUuid(), uuid);
node = app.create(TestOne.class, props);
tx.success();
fail("Validation failed!");
}
} catch (FrameworkException ex) {
}
}
use of org.structr.core.property.PropertyMap in project structr by structr.
the class BasicTest method test01DeleteNode.
/**
* Test successful deletion of a node.
*
* The node shouldn't be found afterwards.
* Creation and deletion are executed in two different transactions.
*/
@Test
public void test01DeleteNode() {
try {
final PropertyMap props = new PropertyMap();
final String type = "GenericNode";
final String name = "GenericNode-name";
NodeInterface node = null;
String uuid = null;
props.put(AbstractNode.type, type);
props.put(AbstractNode.name, name);
try (final Tx tx = app.tx()) {
node = app.create(GenericNode.class, props);
tx.success();
}
assertTrue(node != null);
try (final Tx tx = app.tx()) {
uuid = node.getUuid();
}
try (final Tx tx = app.tx()) {
app.delete(node);
tx.success();
}
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery().uuid(uuid).getResult();
assertEquals("Node should have been deleted", 0, result.size());
} catch (FrameworkException fe) {
}
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.property.PropertyMap in project structr by structr.
the class BasicTest method test02CreateNodeWithExistingUuid.
@Test
public void test02CreateNodeWithExistingUuid() {
try {
final PropertyMap props = new PropertyMap();
TestOne node = null;
final String uuid = StringUtils.replace(UUID.randomUUID().toString(), "-", "");
props.put(GraphObject.id, uuid);
try (final Tx tx = app.tx()) {
node = app.create(TestOne.class, props);
tx.success();
}
try (final Tx tx = app.tx()) {
assertTrue(node != null);
assertTrue(node instanceof TestOne);
assertEquals(node.getUuid(), uuid);
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.property.PropertyMap in project structr by structr.
the class BasicTest method test00SimpleCreateOperation.
@Test
public void test00SimpleCreateOperation() {
try (final Tx tx = app.tx()) {
final PropertyMap properties = new PropertyMap();
properties.put(TestSix.name, "name");
// test null value for a 1:1 related property
properties.put(TestSix.oneToOneTestThree, null);
app.create(TestSix.class, properties);
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception");
}
try (final Tx tx = app.tx()) {
final TestSix test = app.nodeQuery(TestSix.class).getFirst();
assertNotNull("Invalid simple object creation result", test);
assertEquals("Invalid simple object creation result", "name", test.getProperty(AbstractNode.name));
assertEquals("Invalid simple object creation result", null, test.getProperty(TestSix.oneToOneTestThree));
tx.success();
} catch (FrameworkException fex) {
fail("Unexpected exception");
}
}
Aggregations