Search in sources :

Example 1 with WonMessageValidator

use of won.protocol.validation.WonMessageValidator in project webofneeds by researchstudio-sat.

the class WonMessageValidatorTest method testSignatureRequiredProperties.

@Test
@Ignore
public void testSignatureRequiredProperties() throws IOException {
    // Test signature of the 1st envelope
    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_GRAPH_SIGNING_METHOD, RdfUtils.EMPTY_RDF_NODE);
    Statement stmtOld = iter.removeNext();
    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_properties"));
    // reset for further testing:
    env1sigModel.add(stmtOld);
    iter = env1sigModel.listStatements(ResourceFactory.createResource(CREATE_ENV1_SIG_NAME), WONMSG.HAS_SIGNED_GRAPH_PROPERTY, RdfUtils.EMPTY_RDF_NODE);
    Statement stmtModified = iter.nextStatement();
    stmtModified.changeObject(ResourceFactory.createResource("test:object:uri"));
    env1sigModel.add(stmtModified);
    // String test = RdfUtils.writeDatasetToString(invalidDataset, Lang.TRIG);
    // System.out.println("OUT:\n" + test);
    validator = new WonMessageValidator();
    message = new StringBuilder();
    // validate this invalid dataset
    valid = validator.validate(invalidDataset, message);
    Assert.assertTrue("validation is expected to fail", !valid);
    Assert.assertTrue(message.toString().contains("signature_properties"));
    // 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 2 with WonMessageValidator

use of won.protocol.validation.WonMessageValidator in project webofneeds by researchstudio-sat.

the class WonMessageValidatorTest method testMetaAndSignerConsistencyFromOwner.

@Test
@Ignore
public void testMetaAndSignerConsistencyFromOwner() throws IOException {
    // Test fromOwner leaf envelope signer consistency
    Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(WonMessage.of(createMessageDataset)).getCompleteDataset();
    Model env1sigModel = invalidDataset.getNamedModel(CREATE_CONTENT_NAME_SIG);
    // create invalid dataset by replacing a signer in leaf envelope
    Statement stmtOld = env1sigModel.createStatement(ResourceFactory.createResource(CREATE_CONTENT_NAME_SIG), WONMSG.signer, ResourceFactory.createResource(ATOM_LOCAL_URI));
    env1sigModel.remove(stmtOld);
    Statement stmtNew = env1sigModel.createStatement(ResourceFactory.createResource(CREATE_CONTENT_NAME_SIG), WONMSG.signer, ResourceFactory.createResource(NODE_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);
    Assert.assertTrue(message.toString().contains("invalid_from_owner_signer"));
    // reset for further testing:
    env1sigModel.remove(stmtNew);
    env1sigModel.add(stmtOld);
    // Test fromOwner non-leaf envelopes signer consistency
    invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(WonMessage.of(textMessageDataset)).getCompleteDataset();
    Model env2sigModel = invalidDataset.getNamedModel(TEXT_ENV2_SIG_NAME);
    // create invalid dataset by replacing a signer in non-leaf envelope
    stmtOld = env2sigModel.createStatement(ResourceFactory.createResource(TEXT_ENV2_SIG_NAME), WONMSG.signer, ResourceFactory.createResource(NODE_LOCAL_URI));
    env2sigModel.remove(stmtOld);
    stmtNew = env2sigModel.createStatement(ResourceFactory.createResource(TEXT_ENV2_SIG_NAME), WONMSG.signer, ResourceFactory.createResource(ATOM_LOCAL_URI));
    env2sigModel.add(stmtNew);
    validator = new WonMessageValidator();
    message = new StringBuilder();
    // validate this invalid dataset
    valid = validator.validate(invalidDataset, message);
    Assert.assertFalse(valid);
    Assert.assertTrue(message.toString().contains("invalid_from_owner_signer"));
    // 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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with WonMessageValidator

use of won.protocol.validation.WonMessageValidator in project webofneeds by researchstudio-sat.

the class WonMessageValidatorTest method testValidForwardToRecipientMessage.

@Test
@Ignore
public void testValidForwardToRecipientMessage() throws IOException {
    WonMessageValidator validator = new WonMessageValidator();
    StringBuilder message = new StringBuilder();
    boolean valid = validator.validate(Utils.createTestDataset("/validation/valid/conversation_msg_with_forward.trig"), message);
    Assert.assertTrue("validation is expected not to fail at " + message, valid);
}
Also used : WonMessageValidator(won.protocol.validation.WonMessageValidator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with WonMessageValidator

use of won.protocol.validation.WonMessageValidator in project webofneeds by researchstudio-sat.

the class WonMessageValidatorTest method testValidCreateMessage.

@Test
@Ignore
public void testValidCreateMessage() throws IOException {
    WonMessageValidator validator = new WonMessageValidator();
    StringBuilder message = new StringBuilder();
    boolean valid = validator.validate(createMessageDataset, message);
    Assert.assertTrue("validation is expected not to fail at " + message, valid);
}
Also used : WonMessageValidator(won.protocol.validation.WonMessageValidator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with WonMessageValidator

use of won.protocol.validation.WonMessageValidator in project webofneeds by researchstudio-sat.

the class WonMessageValidatorTest method testMetaAndSignerConsistencyFromExternal.

@Test
@Ignore
public void testMetaAndSignerConsistencyFromExternal() throws IOException {
    // Test fromExternal close to leaf envelope signer consistency
    Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(WonMessage.of(textMessageDataset)).getCompleteDataset();
    Model env3sigModel = invalidDataset.getNamedModel(TEXT_ENV3_SIG_NAME);
    // create invalid dataset by replacing a signer - sender node - in close to leaf
    // envelope
    Statement stmtOld = env3sigModel.createStatement(ResourceFactory.createResource(TEXT_ENV3_SIG_NAME), WONMSG.signer, ResourceFactory.createResource(NODE_LOCAL_URI));
    env3sigModel.remove(stmtOld);
    Statement stmtNew = env3sigModel.createStatement(ResourceFactory.createResource(TEXT_ENV3_SIG_NAME), WONMSG.signer, ResourceFactory.createResource(NODE_REMOTE_URI));
    env3sigModel.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("invalid_from_external_signer"));
    // reset for further testing:
    env3sigModel.remove(stmtNew);
    env3sigModel.add(stmtOld);
    // Test fromExternal non-leaf envelopes signer consistency
    Model env4sigModel = invalidDataset.getNamedModel(TEXT_ENV4_SIG_NAME);
    // create invalid dataset by replacing a signer in non-leaf envelope
    stmtOld = env4sigModel.createStatement(ResourceFactory.createResource(TEXT_ENV4_SIG_NAME), WONMSG.signer, ResourceFactory.createResource(NODE_LOCAL_URI));
    env4sigModel.remove(stmtOld);
    stmtNew = env4sigModel.createStatement(ResourceFactory.createResource(TEXT_ENV4_SIG_NAME), WONMSG.signer, ResourceFactory.createResource(ATOM_LOCAL_URI));
    env4sigModel.add(stmtNew);
    validator = new WonMessageValidator();
    message = new StringBuilder();
    // validate this invalid dataset
    valid = validator.validate(invalidDataset, message);
    Assert.assertFalse(valid);
    Assert.assertTrue(message.toString().contains("invalid_from_external_signer"));
    // reset for further testing:
    env4sigModel.remove(stmtNew);
    env4sigModel.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) Ignore(org.junit.Ignore) 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