use of org.apache.jena.rdf.model.Statement in project webofneeds by researchstudio-sat.
the class WonMessageValidatorTest method testInvalidContentChain.
@Test
@Ignore
public void testInvalidContentChain() throws IOException {
Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(new WonMessage(createMessageDataset)).getCompleteDataset();
Model env1Model = invalidDataset.getNamedModel(CREATE_ENV1_NAME);
Model env2Model = invalidDataset.getNamedModel(CREATE_ENV2_NAME);
// test 4
// create invalid dataset by adding a triple that references a content from the second envelope (additionally to
// the first envelope)
Statement stmtNew = env2Model.createStatement(ResourceFactory.createResource(CREATE_ENV1_ENV2_MSG_URI), WONMSG.HAS_CONTENT_PROPERTY, ResourceFactory.createResource(CREATE_CONTENT_NAME));
env2Model.add(stmtNew);
// 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/signature_chain.rq"));
// reset for further testing
env2Model.remove(stmtNew);
// TODO test 5
// create invalid dataset by removing a reference to the content from the envelope
Statement stmtOld = env1Model.createStatement(ResourceFactory.createResource(CREATE_ENV1_ENV2_MSG_URI), WONMSG.HAS_CONTENT_PROPERTY, ResourceFactory.createResource(CREATE_CONTENT_NAME));
env1Model.remove(stmtOld);
// 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/signature_chain.rq"));
// reset for further testing
env1Model.add(stmtOld);
}
use of org.apache.jena.rdf.model.Statement 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 org.apache.jena.rdf.model.Statement 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 org.apache.jena.rdf.model.Statement in project webofneeds by researchstudio-sat.
the class WonMessageValidatorTest method testEventConsistency.
@Test
@Ignore
public void testEventConsistency() throws IOException {
// create a dataset with invalid remoteEvent uri by replacing the original remote event uri
// with the dummy uri
Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(new WonMessage(textMessageDataset)).getCompleteDataset();
Model envModel = invalidDataset.getNamedModel(TEXT_ENV3_NAME);
String dummyName = TEXT_ENV3_NAME;
StmtIterator iter = envModel.listStatements(null, WONMSG.HAS_CORRESPONDING_REMOTE_MESSAGE, RdfUtils.EMPTY_RDF_NODE);
Statement stmtOld = iter.removeNext();
Statement stmtNew = envModel.createStatement(stmtOld.getSubject(), stmtOld.getPredicate(), ResourceFactory.createResource(dummyName));
envModel.add(stmtNew);
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("number_of_events"));
// reset for further testing:
// env2sigModel.add(stmtOld);
// env2sigModel.remove(stmtNew);
}
use of org.apache.jena.rdf.model.Statement in project webofneeds by researchstudio-sat.
the class WonMessageValidatorTest method testInvalidDefaultGraph.
@Test
public void testInvalidDefaultGraph() throws IOException {
// create invalid dataset by adding a triple into the default graph
Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(new WonMessage(createMessageDataset)).getCompleteDataset();
Model defaultModel = invalidDataset.getDefaultModel();
Statement stmt = defaultModel.createStatement(ResourceFactory.createResource(), ResourceFactory.createProperty("test:property:uri"), ResourceFactory.createPlainLiteral("test literal"));
defaultModel.add(stmt);
// 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("invalid_default_graph"));
}
Aggregations