Search in sources :

Example 16 with WonMessageValidator

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);
}
Also used : WonMessageValidator(won.protocol.validation.WonMessageValidator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with WonMessageValidator

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"));
}
Also used : Dataset(org.apache.jena.query.Dataset) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) WonMessageValidator(won.protocol.validation.WonMessageValidator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with WonMessageValidator

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());
}
Also used : Dataset(org.apache.jena.query.Dataset) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) WonMessageValidator(won.protocol.validation.WonMessageValidator) Test(org.junit.Test)

Example 19 with WonMessageValidator

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);
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Dataset(org.apache.jena.query.Dataset) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) WonMessageValidator(won.protocol.validation.WonMessageValidator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 20 with WonMessageValidator

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);
}
Also used : Dataset(org.apache.jena.query.Dataset) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) WonMessageValidator(won.protocol.validation.WonMessageValidator) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)24 WonMessageValidator (won.protocol.validation.WonMessageValidator)24 Ignore (org.junit.Ignore)18 Dataset (org.apache.jena.query.Dataset)15 Model (org.apache.jena.rdf.model.Model)15 Statement (org.apache.jena.rdf.model.Statement)14 StmtIterator (org.apache.jena.rdf.model.StmtIterator)5