Skip to content

Commit

Permalink
Changes in the RiskCalculatorTest class, plus some diagnostics in Ris…
Browse files Browse the repository at this point in the history
…kCalculator show that issue #75 is caused by a problem with domain model registration. Not a solution, but shows what the problem is.
  • Loading branch information
mike1813 committed Sep 4, 2023
1 parent 2c239e1 commit e70b60e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public RiskCalculator(IQuerierDB querier) {

// Load system model assets, matching patterns and nodes
assets = querier.getAssets("system", "system-inf");
logger.info("Found {} system assets", assets.size());
matchingPatterns = querier.getMatchingPatterns("system-inf");
nodes = querier.getNodes("system-inf");

Expand Down Expand Up @@ -416,9 +417,19 @@ private void createMaps(){
for (ThreatDB threat : threats.values()) {
List<String> causesThisThreat = new ArrayList<>();
for(String twasURI : threat.getEntryPoints()){
String msURI = entryPointMisbehaviour.get(twasURI).getUri();
if(!causesThisThreat.contains(msURI))
causesThisThreat.add(msURI);
if(twasURI == null){
logger.info("Found null entry point for threat = {}", threat.getUri());
}
String msURI;
MisbehaviourSetDB ms = entryPointMisbehaviour.get(twasURI);
if(ms != null){
msURI = entryPointMisbehaviour.get(twasURI).getUri();
if(!causesThisThreat.contains(msURI))
causesThisThreat.add(msURI);
} else {
logger.info("Found null MS in entryPointMisbehaviour for TWAS = {}, threat {}", twasURI, threat.getUri());
throw new RuntimeException(String.format("Found null MS in entryPointMisbehaviour for TWAS = {}", twasURI));
}
}
for(String msURI : threat.getSecondaryEffectConditions()){
if(!causesThisThreat.contains(msURI))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public static void beforeClass() {

tester = new TestHelper("jena-tdb");

/*
tester.addDomain(0, "modelvalidator/domain-network.rdf.gz", "http://it-innovation.soton.ac.uk/ontologies/trustworthiness/domain-network");
tester.addDomain(1, "modelvalidator/domain-shield.rdf.gz", "http://it-innovation.soton.ac.uk/ontologies/trustworthiness/domain-shield");
tester.addDomain(2, "modelvalidator/FOGPROTECT-3j1-5.nq.gz", "http://it-innovation.soton.ac.uk/ontologies/trustworthiness/domain-fogprotect");
Expand All @@ -99,6 +100,9 @@ public static void beforeClass() {
//Test domain model for population support
tester.addDomain(6, "modelvalidator/domain-ssm-testing-6a3.nq", "http://it-innovation.soton.ac.uk/ontologies/trustworthiness/ssm-testing-6a3");
tester.addDomain(7, "modelvalidator/ssm-testing-6a3-0-16-auto-expanded.nq", "http://it-innovation.soton.ac.uk/ontologies/trustworthiness/ssm-testing-6a3-expanded");
tester.addDomain(8, "modelvalidator/domain-network-v6a3-1-4.nq.gz", "http://it-innovation.soton.ac.uk/ontologies/trustworthiness/domain-network");
*/
tester.addDomain(0, "modelvalidator/domain-network-v6a3-2-2.nq.gz", "http://it-innovation.soton.ac.uk/ontologies/trustworthiness/domain-network");

//unvalidated system model for testing risk calculator
tester.addSystem(0, "modelvalidator/system-network.nq.gz",
Expand Down Expand Up @@ -139,7 +143,10 @@ public static void beforeClass() {
tester.addSystem(9, "modelvalidator/Test-6a3-1ANB-HighSatC-asserted.nq",
"http://it-innovation.soton.ac.uk/system/63b2f38af03b473a0ce2a3b9");

tester.setUp();
tester.addSystem(10, "modelvalidator/system-dataflow-test-singles-validated.nq.gz",
"http://it-innovation.soton.ac.uk/system/63d9308f8f6a206408be9010");

tester.setUp();

tester.switchModels(0, 0);

Expand Down Expand Up @@ -418,10 +425,10 @@ public void testAttackPaths() {
}

//TODO: fix or delete this test
@Ignore("This test fails for refactored validator but we don't yet know why. Testing the two risk calculations separately works fine (see below).")
//@Ignore("This test fails for refactored validator but we don't yet know why. Testing the two risk calculations separately works fine (see below).")
@Test
public void testCurrentOrFutureRiskCalculation() {
tester.switchModels(2, 3);
tester.switchModels(0, 10);

try {
IQuerierDB querierDB = new JenaQuerierDB(dataset, tester.getModel(), true);
Expand All @@ -430,15 +437,18 @@ public void testCurrentOrFutureRiskCalculation() {
rc.calculateRiskLevels(RiskCalculationMode.CURRENT, true, new Progress(tester.getGraph("system"))); //save results, as queried below

MisbehaviourSet ms = smq.getMisbehaviourSet(tester.getStore(),
"http://it-innovation.soton.ac.uk/ontologies/trustworthiness/system#MS-LossOfAvailability-d7369b42",
"http://it-innovation.soton.ac.uk/ontologies/trustworthiness/system#MS-LossOfAuthenticity-a40e98cc",
false); //no need for causes here
assertEquals(2, ms.getLikelihood().getValue());
logger.info("Future risk: MS-LossOfAuthenticity-a40e98cc has likelihood {}, value {}",ms.getLikelihood(),ms.getLikelihood().getValue());
assertEquals(0, ms.getLikelihood().getValue());

rc.calculateRiskLevels(RiskCalculationMode.FUTURE, true, new Progress(tester.getGraph("system"))); //save results, as queried below
ms = smq.getMisbehaviourSet(tester.getStore(),
"http://it-innovation.soton.ac.uk/ontologies/trustworthiness/system#MS-LossOfAvailability-d7369b42",
"http://it-innovation.soton.ac.uk/ontologies/trustworthiness/system#MS-LossOfAuthenticity-a40e98cc",
false); //no need for causes here
assertEquals(1, ms.getLikelihood().getValue());
logger.info("Current risk: MS-LossOfAuthenticity-a40e98cc has likelihood {}, value {}",ms.getLikelihood(),ms.getLikelihood().getValue());
assertEquals(3, ms.getLikelihood().getValue());

} catch (Exception e) {
logger.error("Exception thrown by risk level calculator", e);
fail("Exception thrown by risk level calculator");
Expand Down

0 comments on commit e70b60e

Please sign in to comment.