use of won.protocol.validation.WonMessageValidator in project webofneeds by researchstudio-sat.
the class WonMessageValidatorTest method testAllGraphsSigned.
@Test
public void testAllGraphsSigned() throws IOException {
// this check actually is redundant with other checks,
// therefore the error message can be from any of those...
// create a dataset where there is a non-signature graph that is not signed
Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(new WonMessage(createMessageDataset)).getCompleteDataset();
Model env2sigModel = invalidDataset.getNamedModel(CREATE_ENV2_SIG_NAME);
StmtIterator iter = env2sigModel.listStatements(ResourceFactory.createResource(CREATE_ENV2_SIG_NAME), WONMSG.HAS_SIGNED_GRAPH_PROPERTY, RdfUtils.EMPTY_RDF_NODE);
Statement stmtOld = iter.removeNext();
Statement stmtNew = env2sigModel.createStatement(ResourceFactory.createResource(CREATE_ENV2_SIG_NAME), WONMSG.HAS_SIGNED_GRAPH_PROPERTY, ResourceFactory.createResource("test:resource:uri"));
env2sigModel.add(stmtNew);
WonMessageValidator validator = new WonMessageValidator();
StringBuilder message = new StringBuilder();
// validate this invalid dataset
boolean valid = validator.validate(invalidDataset, message);
Assert.assertTrue("validation is expected to fail", !valid);
// actually
Assert.assertTrue(message.toString().contains("signed_or_signature") || message.toString().contains("signer") || message.toString().contains("graph_uris"));
// reset for further testing:
env2sigModel.add(stmtOld);
env2sigModel.remove(stmtNew);
}
use of won.protocol.validation.WonMessageValidator in project webofneeds by researchstudio-sat.
the class WonMessageValidatorTest method testSignatureChainParallelToEnvelopeChain.
@Test
@Ignore
public void testSignatureChainParallelToEnvelopeChain() throws IOException {
// create a dataset where the first envelope references the signature of the second envelope instead of content's
// and the 2nd references the signature of the content
Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(new WonMessage(createMessageDataset)).getCompleteDataset();
Model env1Model = invalidDataset.getNamedModel(CREATE_ENV1_NAME);
StmtIterator iter = env1Model.listStatements(null, WONMSG.HAS_SIGNATURE_GRAPH_PROPERTY, RdfUtils.EMPTY_RDF_NODE);
Statement stmtOld = iter.removeNext();
iter = env1Model.listStatements(null, WONMSG.HAS_SIGNED_GRAPH_PROPERTY, RdfUtils.EMPTY_RDF_NODE);
Statement stmtOld2 = iter.removeNext();
Statement stmtNew = stmtOld.changeObject(ResourceFactory.createResource(CREATE_ENV1_SIG_NAME));
env1Model.add(stmtNew);
Statement stmtNew2 = stmtOld2.changeObject(ResourceFactory.createResource(CREATE_ENV1_NAME));
env1Model.add(stmtNew2);
Model env2Model = invalidDataset.getNamedModel(CREATE_ENV2_NAME);
iter = env2Model.listStatements(null, WONMSG.HAS_SIGNATURE_GRAPH_PROPERTY, RdfUtils.EMPTY_RDF_NODE);
Statement stmtOld3 = iter.removeNext();
iter = env2Model.listStatements(null, WONMSG.HAS_SIGNED_GRAPH_PROPERTY, RdfUtils.EMPTY_RDF_NODE);
Statement stmtOld4 = iter.removeNext();
Statement stmtNew3 = stmtOld3.changeObject(ResourceFactory.createResource(CREATE_CONTENT_NAME_SIG));
env2Model.add(stmtNew3);
Statement stmtNew4 = stmtOld4.changeObject(ResourceFactory.createResource(CREATE_CONTENT_NAME));
env2Model.add(stmtNew4);
// String test = RdfUtils.writeDatasetToString(invalidDataset, Lang.TRIG);
// System.out.println("OUT:\n" + test);
WonMessageValidator validator = new WonMessageValidator();
StringBuilder message = new StringBuilder();
// validate this invalid dataset
boolean valid = validator.validate(invalidDataset, message);
Assert.assertTrue("validation is expected to fail", !valid);
// actually
Assert.assertTrue(message.toString().contains("signature_chain"));
// reset for further testing:
env1Model.add(stmtOld);
env1Model.remove(stmtNew);
env1Model.add(stmtOld2);
env1Model.remove(stmtNew2);
env2Model.add(stmtOld3);
env2Model.remove(stmtNew3);
env2Model.add(stmtOld4);
env2Model.remove(stmtNew4);
}
use of won.protocol.validation.WonMessageValidator in project webofneeds by researchstudio-sat.
the class WonMessageValidatorTest method testInvalidEnvelopeChain.
@Test
@Ignore
public void testInvalidEnvelopeChain() throws IOException {
// test 1
// create invalid dataset by removing a triple that references envelope 1 from envelope 2
Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(new WonMessage(createMessageDataset)).getCompleteDataset();
Model env2Model = invalidDataset.getNamedModel(CREATE_ENV2_NAME);
Model env1Model = invalidDataset.getNamedModel(CREATE_ENV1_NAME);
Statement stmtOld = env2Model.createStatement(ResourceFactory.createResource(CREATE_ENV2_NAME), WONMSG.CONTAINS_ENVELOPE, ResourceFactory.createResource(CREATE_ENV1_NAME));
env2Model.remove(stmtOld);
// validate this invalid dataset
WonMessageValidator validator = new WonMessageValidator();
StringBuilder message = new StringBuilder();
boolean valid = validator.validate(invalidDataset, message);
Assert.assertTrue("validation is expected to fail", !valid);
Assert.assertTrue(message.toString().contains("validation/05_sign/invalid_from_owner_signer.rq"));
// reset for further testing
env2Model.add(stmtOld);
// test 2
// create invalid dataset by adding a triple that references envelope 2 from envelope 1,
// thus creating a cycle in the envelope chain
Statement stmtNew = env1Model.createStatement(ResourceFactory.createResource(CREATE_ENV1_NAME), WONMSG.CONTAINS_ENVELOPE, ResourceFactory.createResource(CREATE_ENV2_NAME));
env1Model.add(stmtNew);
// validate this invalid dataset
valid = validator.validate(invalidDataset, message);
Assert.assertTrue("validation is expected to fail", !valid);
Assert.assertTrue(message.toString().contains("validation/05_sign/invalid_from_owner_signer.rq"));
// reset for further testing
env1Model.remove(stmtNew);
// test 3
// create invalid dataset by adding a triple that references an envelope that is not present in the dataset
stmtNew = env1Model.createStatement(ResourceFactory.createResource(CREATE_ENV1_NAME), WONMSG.CONTAINS_ENVELOPE, ResourceFactory.createResource("test:resource:uri"));
env1Model.add(stmtNew);
// validate this invalid dataset
valid = validator.validate(invalidDataset, message);
Assert.assertTrue("validation is expected to fail", !valid);
Assert.assertTrue(message.toString().contains("validation/05_sign/invalid_from_owner_signer.rq"));
// reset for further testing
env1Model.remove(stmtNew);
}
use of won.protocol.validation.WonMessageValidator in project webofneeds by researchstudio-sat.
the class WonMessageValidatorTest method testValidCreateMessage2.
@Test
public void testValidCreateMessage2() throws IOException {
WonMessageValidator validator = new WonMessageValidator();
StringBuilder message = new StringBuilder();
boolean valid = validator.validate(Utils.createTestDataset("/validation/valid/create_msg2.trig"), message);
Assert.assertTrue("validation is expected not to fail at " + message, valid);
}
use of won.protocol.validation.WonMessageValidator in project webofneeds by researchstudio-sat.
the class WonMessageValidatorTest method testMissingAndInvalidMessageDirection.
@Test
@Ignore
public void testMissingAndInvalidMessageDirection() throws IOException {
// create invalid dataset by removing a triple with message direction
Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(WonMessage.of(createMessageDataset)).getCompleteDataset();
Model env1Model = invalidDataset.getNamedModel(CREATE_ENV_NAME);
Model env2Model = invalidDataset.getNamedModel(CREATE_ENV_NAME);
Statement stmtOld = env2Model.createStatement(ResourceFactory.createResource(CREATE_MSG_URI), RDF.type, WONMSG.FromOwner);
env1Model.remove(stmtOld);
env2Model.remove(stmtOld);
// validate this invalid dataset
WonMessageValidator validator = new WonMessageValidator();
StringBuilder message = new StringBuilder();
boolean valid = validator.validate(invalidDataset, message);
Assert.assertFalse(valid);
Assert.assertTrue(message.toString().contains("missing_direction"));
// create invalid dataset by adding a triple with invalid message direction
Statement stmtNew = env2Model.createStatement(ResourceFactory.createResource(CREATE_MSG_URI), RDF.type, ResourceFactory.createProperty("test:property:uri"));
env2Model.add(stmtNew);
// validate this invalid dataset
valid = validator.validate(invalidDataset, message);
Assert.assertFalse(valid);
Assert.assertTrue(message.toString().contains("invalid_direction"));
}
Aggregations