Search in sources :

Example 56 with Statement

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"));
}
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 57 with Statement

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);
}
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 58 with Statement

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);
}
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 59 with Statement

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"));
}
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 60 with Statement

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);
}
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) Test(org.junit.Test)

Aggregations

Statement (org.apache.jena.rdf.model.Statement)72 Model (org.apache.jena.rdf.model.Model)43 StmtIterator (org.apache.jena.rdf.model.StmtIterator)28 Test (org.junit.Test)25 Dataset (org.apache.jena.query.Dataset)24 Resource (org.apache.jena.rdf.model.Resource)19 WonMessageValidator (won.protocol.validation.WonMessageValidator)15 Property (org.apache.jena.rdf.model.Property)13 RDFNode (org.apache.jena.rdf.model.RDFNode)13 ArrayList (java.util.ArrayList)11 Ignore (org.junit.Ignore)11 Triple (org.apache.jena.graph.Triple)7 BaseTest (org.apache.jena.atlas.junit.BaseTest)6 Iterator (java.util.Iterator)4 RdfUtils (won.protocol.util.RdfUtils)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 OntModel (org.apache.jena.ontology.OntModel)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 GraphCollection (de.uni_koblenz.aggrimm.icp.crypto.sign.graph.GraphCollection)1