use of won.protocol.validation.WonMessageValidator in project webofneeds by researchstudio-sat.
the class WonMessageValidatorTest method testInvalidForwardToRecipientMessage.
@Test
@Ignore
public void testInvalidForwardToRecipientMessage() throws IOException {
WonMessageValidator validator = new WonMessageValidator();
StringBuilder message = new StringBuilder();
boolean valid = validator.validate(Utils.createTestDataset("/validation/invalid/create_msg_with_forward.trig"), message);
Assert.assertFalse("validation is expected to fail at " + message, valid);
}
use of won.protocol.validation.WonMessageValidator 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(WonMessage.of(createMessageDataset)).getCompleteDataset();
Model env1Model = invalidDataset.getNamedModel(CREATE_ENV_NAME);
Statement stmt1Old = env1Model.createStatement(ResourceFactory.createResource(CREATE_MSG_URI), WONMSG.timestamp, ResourceFactory.createTypedLiteral("1433774711093", XSDDatatype.XSDlong));
env1Model.remove(stmt1Old);
// 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_timestamp"));
}
use of won.protocol.validation.WonMessageValidator 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(WonMessage.of(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.assertFalse(valid);
Assert.assertEquals("Default graph is not empty", message.toString());
}
use of won.protocol.validation.WonMessageValidator 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(WonMessage.of(createMessageDataset)).getCompleteDataset();
Model env1sigModel = invalidDataset.getNamedModel(CREATE_CONTENT_NAME_SIG);
StmtIterator iter = env1sigModel.listStatements(ResourceFactory.createResource(CREATE_CONTENT_NAME_SIG), WONMSG.signatureValue, RdfUtils.EMPTY_RDF_NODE);
Statement stmtOld = iter.removeNext();
Statement stmtNew = env1sigModel.createStatement(ResourceFactory.createResource(CREATE_CONTENT_NAME_SIG), WONMSG.signatureValue, 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.assertFalse(valid);
Assert.assertTrue(message.toString().contains("signature_reference_values"));
// reset for further testing:
env1sigModel.add(stmtOld);
}
use of won.protocol.validation.WonMessageValidator 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(WonMessage.of(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), WONMSG.signer, ResourceFactory.createResource(NODE_LOCAL_URI));
env1sigModel.remove(stmtOld);
Statement stmtNew = env1sigModel.createStatement(ResourceFactory.createResource(RESPONSE_LOCAL_ENV1_SIG_NAME), WONMSG.signer, ResourceFactory.createResource(ATOM_LOCAL_URI));
env1sigModel.add(stmtNew);
WonMessageValidator validator = new WonMessageValidator();
StringBuilder message = new StringBuilder();
// validate this invalid dataset
boolean valid = validator.validate(invalidDataset, message);
Assert.assertFalse(valid);
// reset for further testing:
env1sigModel.remove(stmtNew);
env1sigModel.add(stmtOld);
}
Aggregations