use of org.apache.jena.rdf.model.Statement in project webofneeds by researchstudio-sat.
the class WonMessageValidatorTest method testMissingAndInvalidMessageType.
@Test
@Ignore
public void testMissingAndInvalidMessageType() throws IOException {
// create invalid dataset by removing a triple with message type
Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(new WonMessage(createMessageDataset)).getCompleteDataset();
Model env1Model = invalidDataset.getNamedModel(CREATE_ENV1_NAME);
Statement stmtOld = env1Model.createStatement(ResourceFactory.createResource(CREATE_ENV1_ENV2_MSG_URI), WONMSG.HAS_MESSAGE_TYPE_PROPERTY, WONMSG.TYPE_CREATE);
env1Model.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("missing_type"));
// create invalid dataset by adding a triple with invalid message type
Statement stmtNew = env1Model.createStatement(ResourceFactory.createResource(CREATE_ENV1_ENV2_MSG_URI), WONMSG.HAS_MESSAGE_TYPE_PROPERTY, ResourceFactory.createProperty("test:property: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("invalid_type"));
}
use of org.apache.jena.rdf.model.Statement in project webofneeds by researchstudio-sat.
the class WonMessageValidatorTest method testSignatureReferenceValues.
@Test
@Ignore
public void testSignatureReferenceValues() throws IOException {
// Test signature of the 1st envelope: replace value of the signature with some dummy value
Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(new WonMessage(createMessageDataset)).getCompleteDataset();
Model env1sigModel = invalidDataset.getNamedModel(CREATE_ENV1_SIG_NAME);
StmtIterator iter = env1sigModel.listStatements(ResourceFactory.createResource(CREATE_ENV1_SIG_NAME), SFSIG.HAS_SIGNATURE_VALUE, RdfUtils.EMPTY_RDF_NODE);
Statement stmtOld = iter.removeNext();
Statement stmtNew = env1sigModel.createStatement(ResourceFactory.createResource(CREATE_ENV1_SIG_NAME), SFSIG.HAS_SIGNATURE_VALUE, ResourceFactory.createPlainLiteral("eve's value"));
env1sigModel.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);
Assert.assertTrue(message.toString().contains("signature_reference_values"));
// reset for further testing:
env1sigModel.add(stmtOld);
}
use of org.apache.jena.rdf.model.Statement in project webofneeds by researchstudio-sat.
the class WonMessageValidatorTest method testMetaAndSignerConsistencyFromSystem.
@Test
public void testMetaAndSignerConsistencyFromSystem() throws IOException {
// Test fromSystem envelopes signer consistency
Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(new WonMessage(responseMessageDataset)).getCompleteDataset();
// Model env1Model = invalidDataset.getNamedModel(RESPONSE_LOCAL_ENV1_NAME);
Model env1sigModel = invalidDataset.getNamedModel(RESPONSE_LOCAL_ENV1_SIG_NAME);
// Model env2Model = invalidDataset.getNamedModel(RESPONSE_LOCAL_ENV2_NAME);
// create invalid dataset by replacing a signer
Statement stmtOld = env1sigModel.createStatement(ResourceFactory.createResource(RESPONSE_LOCAL_ENV1_SIG_NAME), SFSIG.HAS_VERIFICATION_CERT, ResourceFactory.createResource(NODE_LOCAL_URI));
env1sigModel.remove(stmtOld);
Statement stmtNew = env1sigModel.createStatement(ResourceFactory.createResource(RESPONSE_LOCAL_ENV1_SIG_NAME), SFSIG.HAS_VERIFICATION_CERT, ResourceFactory.createResource(NEED_LOCAL_URI));
env1sigModel.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);
Assert.assertTrue(message.toString().contains("invalid_from_system_signer"));
// reset for further testing:
env1sigModel.remove(stmtNew);
env1sigModel.add(stmtOld);
}
use of org.apache.jena.rdf.model.Statement in project webofneeds by researchstudio-sat.
the class WonMessageValidatorTest method testMissingTimestamp.
@Test
@Ignore
public void testMissingTimestamp() throws IOException {
// create invalid dataset by removing a triple with received timestamp
Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(new WonMessage(createMessageDataset)).getCompleteDataset();
Model env1Model = invalidDataset.getNamedModel(CREATE_ENV1_NAME);
Model env2Model = invalidDataset.getNamedModel(CREATE_ENV2_NAME);
Statement stmt1Old = env1Model.createStatement(ResourceFactory.createResource(CREATE_ENV1_ENV2_MSG_URI), WONMSG.HAS_SENT_TIMESTAMP, ResourceFactory.createTypedLiteral("1433774711093", XSDDatatype.XSDlong));
Statement stmt2Old = env2Model.createStatement(ResourceFactory.createResource(CREATE_ENV1_ENV2_MSG_URI), WONMSG.HAS_RECEIVED_TIMESTAMP, ResourceFactory.createTypedLiteral("1433774714580", XSDDatatype.XSDlong));
env1Model.remove(stmt1Old);
env2Model.remove(stmt2Old);
// 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("missing_timestamp"));
}
use of org.apache.jena.rdf.model.Statement 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);
}
Aggregations