use of won.utils.content.model.AtomContent in project webofneeds by researchstudio-sat.
the class AclTests method testCreateAtomWithACL_isNotPubliclyReadable.
@Test(timeout = 60 * 1000)
public void testCreateAtomWithACL_isNotPubliclyReadable() throws Exception {
runTest(ctx -> {
EventBus bus = ctx.getEventBus();
final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
final URI atomUri = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
final String atomUriString = atomUri.toString();
final AtomContent atomContent = AtomContent.builder(atomUri).addTitle("Unit Test Atom ACL Test 3 (with acl)").addSocket(Socket.builder(atomUriString + "#holderSocket").setSocketDefinition(WXHOLD.HolderSocket.asURI()).build()).addSocket(Socket.builder(atomUriString + "#buddySocket").setSocketDefinition(WXBUDDY.BuddySocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
// create an acl allowing only the atom itself to read everything
Authorization auth = Authorization.builder().addGrant(ase -> ase.addOperationsSimpleOperationExpression(OP_READ)).addGranteesAtomExpression(ae -> ae.addAtomsURI(URI.create("https://example.com/nobody"))).build();
WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(// add the acl graph
won.auth.model.RdfOutput.toGraph(auth)).build();
createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
ctx.getBotContextWrapper().rememberAtomUri(atomUri);
final String action = "Create Atom action";
EventListener successCallback = event -> {
URI connContainerUri = uriService.createConnectionContainerURIForAtom(atomUri);
URI createMessageUri = ((SuccessResponseEvent) event).getOriginalMessageURI();
boolean passed = true;
passed = passed && testLinkedDataRequestOk(ctx, bus, "test1.", atomUri, atomUri, createMessageUri);
passed = passed && testLinkedDataRequestOk_emptyDataset(ctx, bus, "test2.", atomUri, connContainerUri);
passed = passed && testLinkedDataRequestFailsNoWebId(ctx, bus, "test3.", LinkedDataFetchingException.class, atomUri, connContainerUri, createMessageUri);
if (passed) {
passTest(bus);
}
};
EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
ctx.getWonMessageSender().sendMessage(createMessage);
});
}
use of won.utils.content.model.AtomContent in project webofneeds by researchstudio-sat.
the class AclTests method testCreateAtomWithEmptyACL_isPubliclyReadable.
@Test(timeout = 60 * 1000)
public void testCreateAtomWithEmptyACL_isPubliclyReadable() throws Exception {
runTest(ctx -> {
EventBus bus = ctx.getEventBus();
final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
final URI atomUri = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
final String atomUriString = atomUri.toString();
final AtomContent atomContent = new AtomContent(atomUriString);
atomContent.addTitle("Unit Test Atom ACL Test 1");
atomContent.addType(URI.create(WON.Atom.getURI()));
atomContent.addSocket(Socket.builder(atomUri.toString() + "#chatSocket").setSocketDefinition(WXCHAT.ChatSocket.asURI()).build());
WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(// add an empty acl graph
GraphFactory.createGraphMem()).build();
createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
ctx.getBotContextWrapper().rememberAtomUri(atomUri);
final String action = "Create Atom action";
EventListener successCallback = event -> {
((CachingLinkedDataSource) ctx.getLinkedDataSource()).clear();
boolean passed = true;
passed = passed && testLinkedDataRequestOk(ctx, bus, "withWebid", atomUri, atomUri);
passed = passed && testLinkedDataRequestOkNoWebId(ctx, bus, "withoutWebId", atomUri);
if (passed) {
passTest(bus);
}
};
EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
ctx.getWonMessageSender().sendMessage(createMessage);
});
}
use of won.utils.content.model.AtomContent in project webofneeds by researchstudio-sat.
the class AclTests method testAtomWithoutACL_fallbackToLegacyImpl.
@Test(timeout = 60 * 1000)
public void testAtomWithoutACL_fallbackToLegacyImpl() throws Exception {
runTest(ctx -> {
EventBus bus = ctx.getEventBus();
final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
final URI atomUri = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
final String atomUriString = atomUri.toString();
final AtomContent atomContent = AtomContent.builder(atomUri).addTitle("Unit Test Atom ACL Test 2").addSocket(Socket.builder(atomUri.toString() + "#chatSocket").setSocketDefinition(WXCHAT.ChatSocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri).content().graph(RdfOutput.toGraph(atomContent)).build();
createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
ctx.getBotContextWrapper().rememberAtomUri(atomUri);
final String action = "Create Atom action";
EventListener successCallback = event -> {
((CachingLinkedDataSource) ctx.getLinkedDataSource()).clear();
URI connContainerUri = uriService.createConnectionContainerURIForAtom(atomUri);
URI createMessageUri = ((SuccessResponseEvent) event).getOriginalMessageURI();
boolean passed = true;
passed = passed && testLinkedDataRequestOk(ctx, bus, "test1.", atomUri, atomUri, createMessageUri);
passed = passed && testLinkedDataRequestOk_emptyDataset(ctx, bus, "test2.", atomUri, connContainerUri);
passed = passed && testLinkedDataRequestOkNoWebId(ctx, bus, "test3.", atomUri);
passed = passed && testLinkedDataRequestOkNoWebId_emptyDataset(ctx, bus, "test4.", connContainerUri);
passed = passed && testLinkedDataRequestFailsNoWebId(ctx, bus, "test5.", LinkedDataFetchingException.class, createMessageUri);
if (passed) {
passTest(bus);
}
};
EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
ctx.getWonMessageSender().sendMessage(createMessage);
});
}
use of won.utils.content.model.AtomContent in project webofneeds by researchstudio-sat.
the class AclTests method testSocketCapacity_nonConcurrentAccepts.
@Test(timeout = 60 * 1000)
public void testSocketCapacity_nonConcurrentAccepts() throws Exception {
runTest(ctx -> {
EventBus bus = ctx.getEventBus();
final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
final URI atomUri1 = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
final URI atomUri2 = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
final URI atomUri3 = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
final BotBehaviour bbCreateAtom1 = new BotBehaviour(ctx, "bbCreateAtom1") {
@Override
protected void onActivate(Optional<Object> message) {
final String atomUriString = atomUri1.toString();
AtomContent atomContent = AtomContent.builder(atomUri1).addTitle("Holdable atom (1/3)").addSocket(Socket.builder(atomUriString + "#holdableSocket").setSocketDefinition(WXHOLD.HoldableSocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri1).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(won.auth.model.RdfOutput.toGraph(getAnyoneMayConnectAuth())).content().aclGraph(won.auth.model.RdfOutput.toGraph(getAnyoneMayReadAnything())).build();
createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
ctx.getBotContextWrapper().rememberAtomUri(atomUri1);
EventListener successCallback = event -> {
logger.debug("holdable atom created");
deactivate();
};
EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, "Create holdable atom");
EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
ctx.getWonMessageSender().sendMessage(createMessage);
}
};
final BotBehaviour bbCreateAtom2 = new BotBehaviour(ctx, "bbCreateAtom2") {
@Override
protected void onActivate(Optional<Object> message) {
final String atomUriString = atomUri2.toString();
AtomContent atomContent = AtomContent.builder(atomUri2).addTitle("holder atom A (2/3)").addSocket(Socket.builder(atomUriString + "#holderSocket").setSocketDefinition(WXHOLD.HolderSocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri2).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(won.auth.model.RdfOutput.toGraph(getAnyoneMayConnectAuth())).content().aclGraph(won.auth.model.RdfOutput.toGraph(getAnyoneMayReadAnything())).build();
createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
ctx.getBotContextWrapper().rememberAtomUri(atomUri2);
EventListener successCallback = event -> {
logger.debug("holder atom A created");
deactivate();
};
EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, "Create holder atom A");
EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
ctx.getWonMessageSender().sendMessage(createMessage);
}
};
final BotBehaviour bbCreateAtom3 = new BotBehaviour(ctx, "bbCreateAtom3") {
@Override
protected void onActivate(Optional<Object> message) {
final String atomUriString = atomUri3.toString();
AtomContent atomContent = AtomContent.builder(atomUri3).addTitle("holder atom B (3/3)").addSocket(Socket.builder(atomUriString + "#holderSocket").setSocketDefinition(WXHOLD.HolderSocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri3).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(won.auth.model.RdfOutput.toGraph(getAnyoneMayConnectAuth())).content().aclGraph(won.auth.model.RdfOutput.toGraph(getAnyoneMayReadAnything())).build();
createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
ctx.getBotContextWrapper().rememberAtomUri(atomUri3);
EventListener successCallback = event -> {
logger.debug("holder atom B created");
deactivate();
};
EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, "Creating holder atom B");
EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
ctx.getWonMessageSender().sendMessage(createMessage);
}
};
BotBehaviour bbSendConnect21 = new BotBehaviour(ctx, "bbSendConnect21") {
@Override
protected void onActivate(Optional<Object> message) {
WonMessage connectMessage = WonMessageBuilder.connect().sockets().sender(URI.create(atomUri2.toString() + "#holderSocket")).recipient(URI.create(atomUri1.toString() + "#holdableSocket")).direction().fromOwner().build();
connectMessage = ctx.getWonMessageSender().prepareMessage(connectMessage);
EventListener successCallback = event -> {
logger.debug("holder A -> holdable connection requested");
deactivate();
};
EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, "Requesting connection holder A -> holdable");
EventBotActionUtils.makeAndSubscribeResponseListener(connectMessage, successCallback, failureCallback, ctx);
ctx.getWonMessageSender().sendMessage(connectMessage);
}
};
BotBehaviour bbAcceptConnect12 = new BotBehaviour(ctx, "bbAcceptConnect12") {
@Override
protected void onActivate(Optional<Object> message) {
WonMessage connectMessage = WonMessageBuilder.connect().sockets().sender(URI.create(atomUri1.toString() + "#holdableSocket")).recipient(URI.create(atomUri2.toString() + "#holderSocket")).direction().fromOwner().build();
connectMessage = ctx.getWonMessageSender().prepareMessage(connectMessage);
EventListener successCallback = event -> {
logger.debug("Holder A <-> holdable connection accepted");
deactivate();
};
EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, "Accepting connection holder A <-> holdable");
EventBotActionUtils.makeAndSubscribeResponseListener(connectMessage, successCallback, failureCallback, ctx);
ctx.getWonMessageSender().sendMessage(connectMessage);
}
};
BotBehaviour bbSendConnect31 = new BotBehaviour(ctx, "bbSendConnect31") {
@Override
protected void onActivate(Optional<Object> message) {
WonMessage connectMessage = WonMessageBuilder.connect().sockets().sender(URI.create(atomUri3.toString() + "#holderSocket")).recipient(URI.create(atomUri1.toString() + "#holdableSocket")).direction().fromOwner().build();
connectMessage = ctx.getWonMessageSender().prepareMessage(connectMessage);
EventListener successCallback = event -> {
logger.debug("holder B -> holdable connection requested");
deactivate();
};
EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, "Requesting connection holder B -> holdable");
EventBotActionUtils.makeAndSubscribeResponseListener(connectMessage, successCallback, failureCallback, ctx);
ctx.getWonMessageSender().sendMessage(connectMessage);
}
};
BotBehaviour bbAcceptConnect13 = new BotBehaviour(ctx, "bbAcceptConnect") {
@Override
protected void onActivate(Optional<Object> message) {
WonMessage connectMessage = WonMessageBuilder.connect().sockets().sender(URI.create(atomUri1.toString() + "#holdableSocket")).recipient(URI.create(atomUri3.toString() + "#holderSocket")).direction().fromOwner().build();
connectMessage = ctx.getWonMessageSender().prepareMessage(connectMessage);
EventListener successCallback = event -> {
logger.debug("Unexpected: Holder B <-> holdable connection accepted");
failTest(bus, String.format("Unexpectedly, holdable %s accepted connection to another holder", atomUri1.toString()));
};
EventListener failureCallback = event -> {
logger.debug("As expected, accepting second holder conneciton failed");
passTest(bus);
};
EventBotActionUtils.makeAndSubscribeResponseListener(connectMessage, successCallback, failureCallback, ctx);
ctx.getWonMessageSender().sendMessage(connectMessage);
}
};
BotBehaviour bbPassTest = new BotBehaviour(ctx) {
@Override
protected void onActivate(Optional<Object> message) {
passTest(bus);
}
};
BehaviourBarrier barrier = new BehaviourBarrier(ctx);
barrier.waitFor(bbCreateAtom1, bbCreateAtom2, bbCreateAtom3);
barrier.thenStart(bbSendConnect21);
barrier.activate();
bbSendConnect21.onDeactivateActivate(bbAcceptConnect12);
bbAcceptConnect12.onDeactivateActivate(bbSendConnect31);
bbSendConnect31.onDeactivateActivate(bbAcceptConnect13);
bbCreateAtom1.activate();
bbCreateAtom2.activate();
bbCreateAtom3.activate();
});
}
use of won.utils.content.model.AtomContent in project webofneeds by researchstudio-sat.
the class AclTests method testModifyOnBehalf_fail.
@Test(timeout = 60 * 1000)
public void testModifyOnBehalf_fail() throws Exception {
final AtomicBoolean atom1Created = new AtomicBoolean(false);
final AtomicBoolean atom2Created = new AtomicBoolean(false);
final CountDownLatch latch = new CountDownLatch(2);
final AtomicReference<URI> createMessageUri1 = new AtomicReference();
final AtomicReference<URI> createMessageUri2 = new AtomicReference();
runTest(ctx -> {
EventBus bus = ctx.getEventBus();
final URI wonNodeUri = ctx.getNodeURISource().getNodeURI();
final URI atomUri1 = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
final URI atomUri2 = ctx.getWonNodeInformationService().generateAtomURI(wonNodeUri);
BotBehaviour bbAtom1 = new BotBehaviour(ctx) {
@Override
protected void onActivate(Optional<Object> message) {
final String atomUriString = atomUri1.toString();
final AtomContent atomContent = AtomContent.builder(atomUriString).addTitle("Granting atom").addSocket(Socket.builder(atomUriString + "#chatSocket").setSocketDefinition(WXCHAT.ChatSocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
Authorization auth = Authorization.builder().addGranteesAtomExpression(ae -> ae.addAtomsURI(atomUri2)).addGrant(ase -> ase.addOperationsSimpleOperationExpression(OP_READ)).build();
WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri1).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(won.auth.model.RdfOutput.toGraph(auth)).build();
createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
ctx.getBotContextWrapper().rememberAtomUri(atomUri1);
final String action = "Create granting atom";
EventListener successCallback = event -> {
logger.debug("Granting atom created");
createMessageUri1.set(((SuccessResponseEvent) event).getOriginalMessageURI());
deactivate();
};
EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
ctx.getWonMessageSender().sendMessage(createMessage);
}
};
BotBehaviour bbAtom2 = new BotBehaviour(ctx) {
@Override
protected void onActivate(Optional<Object> message) {
final String atomUriString = atomUri2.toString();
final AtomContent atomContent = AtomContent.builder(atomUriString).addTitle("Grantee atom").addSocket(Socket.builder(atomUriString + "#chatSocket").setSocketDefinition(WXCHAT.ChatSocket.asURI()).build()).addType(URI.create(WON.Atom.getURI())).build();
WonMessage createMessage = WonMessageBuilder.createAtom().atom(atomUri2).content().graph(RdfOutput.toGraph(atomContent)).content().aclGraph(won.auth.model.RdfOutput.toGraph(getNobodyMayDoNothing())).build();
createMessage = ctx.getWonMessageSender().prepareMessage(createMessage);
ctx.getBotContextWrapper().rememberAtomUri(atomUri2);
final String action = "Create grantee atom";
EventListener successCallback = event -> {
logger.debug("Grantee atom created");
createMessageUri2.set(((SuccessResponseEvent) event).getOriginalMessageURI());
deactivate();
};
EventListener failureCallback = makeFailureCallbackToFailTest(bot, ctx, bus, action);
EventBotActionUtils.makeAndSubscribeResponseListener(createMessage, successCallback, failureCallback, ctx);
ctx.getWonMessageSender().sendMessage(createMessage);
}
};
BotBehaviour bbReplaceAtom1FromAtom2 = new BotBehaviour(ctx) {
@Override
protected void onActivate(Optional<Object> message) {
WonMessage replaceMessage = WonMessageBuilder.replace().atom(atomUri1).content().graph(RdfOutput.toGraph(AtomContent.builder().addTitle("Replaced title").addTag("ANewTag").addType(URI.create(WON.Persona.getURI())).addSocket(Socket.builder().setSocketDefinition(WXBUDDY.BuddySocket.asURI()).build()).addSocket(Socket.builder().setSocketDefinition(WXHOLD.HolderSocket.asURI()).build()).build())).build();
EventListener passIfFailure = event -> {
logger.debug("Illegal replace denied successfully");
deactivate();
passTest(bus);
};
replaceMessage = ctx.getWonMessageSender().prepareMessageOnBehalf(replaceMessage, atomUri2);
EventListener failIfSuccess = makeSuccessCallbackToFailTest(bot, ctx, bus, "modifying atom1 using atom2's WebID");
EventBotActionUtils.makeAndSubscribeResponseListener(replaceMessage, failIfSuccess, passIfFailure, ctx);
ctx.getWonMessageSender().sendMessage(replaceMessage);
}
};
BehaviourBarrier barrier = new BehaviourBarrier(ctx);
barrier.waitFor(bbAtom1, bbAtom2);
barrier.thenStart(bbReplaceAtom1FromAtom2);
barrier.activate();
bbAtom1.activate();
bbAtom2.activate();
logger.debug("Finished initializing test 'testQueryBasedMatch()'");
});
}
Aggregations