Commit 9e30723e authored by Paff's avatar Paff
Browse files

test coverage > 90% for cocos

parent 74aaf16c
......@@ -64,7 +64,7 @@ public final class MontiSecArcConstants extends Interfaces2Constants {
/**
* Argument for Analysis configuration
*/
public static final String ARG_ANALYSISCONFPATH = "-analsisconf";
public static final String ARG_ANALYSISCONFPATH = "-analsisconfpath";
/**
* name for pep entry
......
......@@ -11,15 +11,9 @@ import mc.types._ast.ASTQualifiedName;
import mc.umlp.arc.ets.check.MontiArcCheckCoCoVisitor;
import mc.umlp.arcd._ast.ASTArcComponent;
import mc.umlp.arcd._ast.ASTArcComponentBody;
import mc.umlp.arcd._ast.ASTArcConnector;
import mc.umlp.arcd._ast.ASTArcPort;
import mc.umlp.arcd._ast.ASTArcSimpleConnector;
import mc.umlp.arcd._ast.ASTArcSubComponent;
import mc.umlp.arcd.ets.check.coco.checker.ISubComponentChecker;
import mc.umlp.arcd.ets.entries.ComponentEntry;
import mc.umlp.arcd.ets.entries.ConnectorEntry;
import mc.umlp.arcd.ets.entries.PortEntry;
import mc.umlp.arcd.ets.entries.SubComponentEntry;
import secarc.MontiSecArcConstants;
import secarc._ast.ASTMCCompilationUnit;
......@@ -29,36 +23,28 @@ import secarc._ast.ASTSecArcIdentity;
import secarc._ast.ASTSecArcRefRole;
import secarc._ast.ASTSecArcRole;
import secarc._ast.ASTSecArcTrustlevelRelation;
import secarc._ast.ASTSecArcCPE;
import secarc._ast.ASTSecArcPEP;
import secarc.ets.cocos.checkers.ISecComponentBodyChecker;
import secarc.ets.cocos.checkers.ISecComponentChecker;
import secarc.ets.cocos.checkers.ISecConfigurationChecker;
import secarc.ets.cocos.checkers.ISecConnectorChecker;
import secarc.ets.cocos.checkers.ISecFilterChecker;
import secarc.ets.cocos.checkers.ISecIdentityChecker;
import secarc.ets.cocos.checkers.ISecPepChecker;
import secarc.ets.cocos.checkers.ISecPortChecker;
import secarc.ets.cocos.checkers.ISecRefRoleChecker;
import secarc.ets.cocos.checkers.ISecRoleChecker;
import secarc.ets.cocos.checkers.ISecSubComponentChecker;
import secarc.ets.cocos.checkers.ISecTrustlevelRelationChecker;
import secarc.ets.cocos.checkers.ISecCPEChecker;
import secarc.ets.entries.ConfigurationEntry;
import secarc.ets.entries.FilterEntry;
import secarc.ets.entries.IdentityEntry;
import secarc.ets.entries.PEPEntry;
import secarc.ets.entries.RoleEntry;
import secarc.ets.entries.SecComponentEntry;
import secarc.ets.entries.SecConnectorEntry;
import secarc.ets.entries.SecPortEntry;
import secarc.ets.entries.SecSubComponentEntry;
import secarc.ets.entries.TrustlevelRelationEntry;
import secarc.ets.entries.CPEEntry;
import secarc.ets.graph.ArchitectureGraph;
import secarc.ets.graph.ArchitectureGraphBuilder;
import interfaces2.STEntryState;
import interfaces2.coco.ContextCondition;
import interfaces2.resolvers.AmbigousException;
......@@ -76,84 +62,64 @@ import interfaces2.resolvers.AmbigousException;
*/
public class MontiSecArcCheckVisitor extends MontiArcCheckCoCoVisitor {
private String packageName = "";
/**
* Architecture graph for analysis
*/
private ArchitectureGraph graph;
/**
* Cocos that check connector related conditions
*/
private Set<ISecConnectorChecker> secConnectorChecker;
protected ArchitectureGraph graph;
/**
* Cocos that check the component related conditions
*/
private Set<ISecComponentChecker> secComponentChecker;
/**
* Cocos that check the subcomponent related conditions
*/
private Set<ISecSubComponentChecker> secSubComponentChecker;
/**
* Cocos that check the version related conditions
*/
private Set<ISecCPEChecker> secVersionChecker;
protected Set<ISecComponentChecker> secComponentChecker;
/**
* Cocos that check the body of a component
*/
private Set<ISecComponentBodyChecker> secComponentBodyChecker;
protected Set<ISecComponentBodyChecker> secComponentBodyChecker;
/**
* Cocos that check the identity related conditions
*/
private Set<ISecIdentityChecker> secIdentityChecker;
protected Set<ISecIdentityChecker> secIdentityChecker;
/**
* Cocos that check pep related conditions
*/
private Set<ISecPepChecker> secPepChecker;
protected Set<ISecPepChecker> secPepChecker;
/**
* Cocos that check port roles related conditions
*/
private Set<ISecRefRoleChecker> secRefRoleChecker;
protected Set<ISecRefRoleChecker> secRefRoleChecker;
/**
* Cocos that check port related conditions
*/
private Set<ISecPortChecker> secPortChecker;
protected Set<ISecPortChecker> secPortChecker;
/**
* Cocos that check configuration related conditions
*/
private Set<ISecConfigurationChecker> secConfigurationChecker;
protected Set<ISecConfigurationChecker> secConfigurationChecker;
/**
* Cocos that check role related conditions
*/
private Set<ISecRoleChecker> secRoleChecker;
protected Set<ISecRoleChecker> secRoleChecker;
/**
* Cocos that check filter related conditions
*/
private Set<ISecFilterChecker> secFilterChecker;
protected Set<ISecFilterChecker> secFilterChecker;
/**
* Cocos that check trustlevel relation related conditions
*/
private Set<ISecTrustlevelRelationChecker> secTrustlevelRelationChecker;
protected Set<ISecTrustlevelRelationChecker> secTrustlevelRelationChecker;
public MontiSecArcCheckVisitor() {
secConnectorChecker = new HashSet<ISecConnectorChecker>();
secComponentChecker = new HashSet<ISecComponentChecker>();
secSubComponentChecker = new HashSet<ISecSubComponentChecker>();
secVersionChecker = new HashSet<ISecCPEChecker>();
secComponentBodyChecker = new HashSet<ISecComponentBodyChecker>();
secIdentityChecker = new HashSet<ISecIdentityChecker>();
secPepChecker = new HashSet<ISecPepChecker>();
......@@ -183,18 +149,9 @@ public class MontiSecArcCheckVisitor extends MontiArcCheckCoCoVisitor {
super.createUsefulCollections();
for(ContextCondition coco : getEnabledConditions()) {
if(coco instanceof ISecConnectorChecker) {
secConnectorChecker.add((ISecConnectorChecker) coco);
}
if(coco instanceof ISecComponentChecker) {
secComponentChecker.add((ISecComponentChecker) coco);
}
if(coco instanceof ISecSubComponentChecker) {
secSubComponentChecker.add((ISecSubComponentChecker) coco);
}
if(coco instanceof ISecCPEChecker) {
secVersionChecker.add((ISecCPEChecker) coco);
}
if(coco instanceof ISecComponentBodyChecker) {
secComponentBodyChecker.add((ISecComponentBodyChecker) coco);
}
......@@ -231,10 +188,6 @@ public class MontiSecArcCheckVisitor extends MontiArcCheckCoCoVisitor {
* @param node ast node to visit
*/
public void visit(ASTMCCompilationUnit node) {
packageName = NameHelper.dotSeparatedStringFromList(node.getPackage());
if (!packageName.isEmpty()) {
packageName += ".";
}
SecComponentEntry componentEntry = null;
......@@ -307,75 +260,6 @@ public class MontiSecArcCheckVisitor extends MontiArcCheckCoCoVisitor {
}
}
/**
* Visits version
*
* @param node ast node to visit
*/
public void visit(ASTSecArcCPE node) {
try {
CPEEntry entry = (CPEEntry) resolver.resolve(MontiSecArcConstants.CPE_NAME, CPEEntry.KIND, getNameSpaceFor(node.getMainParent()));
if (entry != null) {
for (ISecCPEChecker cc : secVersionChecker) {
cc.check(node, entry);
}
}
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
}
/**
* Visits connectors
*
* @param node ast node to visit
*/
public void visit(ASTArcConnector node) {
super.visit(node);
for (ASTQualifiedName name : node.getTargets()) {
try {
SecConnectorEntry entry = (SecConnectorEntry) resolver.resolve(NameHelper.dotSeparatedStringFromList(name.getParts()), ConnectorEntry.KIND,
getNameSpaceFor(node.getMainParent()));
if (entry != null) {
for (ISecConnectorChecker cc : secConnectorChecker) {
cc.check(node, entry);
}
}
} catch (AmbigousException e) {
// not handled here
MCG.getLogger().info(e.getMessage());
}
}
}
/**
* Visits simple connectors
*
* @param node ast node to visit
*/
public void visit(ASTArcSimpleConnector node) {
super.visit(node);
for (ASTQualifiedName name : node.getTargets()) {
try {
SecConnectorEntry entry = (SecConnectorEntry) resolver.resolve(NameHelper.dotSeparatedStringFromList(name.getParts()), ConnectorEntry.KIND,
getNameSpaceFor(node.getMainParent()));
if (entry != null) {
for (ISecConnectorChecker cc : secConnectorChecker) {
cc.check(node, entry);
}
}
} catch (AmbigousException e) {
// not handled here
MCG.getLogger().info(e.getMessage());
}
}
}
/**
* Visits component body
*
......@@ -431,31 +315,6 @@ public class MontiSecArcCheckVisitor extends MontiArcCheckCoCoVisitor {
}
}
/**
* Visits subcomponents
*
* @param node ast node to visit
*/
@Override
public void visit(ASTArcSubComponent node) {
super.visit(node);
if (!node.hasNames()) {
try {
SecSubComponentEntry entry = (SecSubComponentEntry) resolver.resolve(node.printName(), SubComponentEntry.KIND, getNameSpaceFor(node.getMainParent()));
if (entry != null && entry.getComponentType().getEntryState() != STEntryState.UNQUALIFIED) {
for (ISubComponentChecker rc : subcomponentChecker) {
rc.check(node, entry);
}
}
} catch (AmbigousException e) {
// not checked here
MCG.getLogger().info(e.getMessage());
}
}
}
/**
* Visits configuration
*
......@@ -520,7 +379,13 @@ public class MontiSecArcCheckVisitor extends MontiArcCheckCoCoVisitor {
*/
public void visit(ASTSecArcTrustlevelRelation node) {
try {
TrustlevelRelationEntry entry = (TrustlevelRelationEntry) resolver.resolve(NameHelper.dotSeparatedStringFromList(node.getServer().getParts()), TrustlevelRelationEntry.KIND, getNameSpaceFor(node.getMainParent()));
String name = "";
if(node.isGT()) {
name = NameHelper.dotSeparatedStringFromList(node.getClient().getParts());
} else {
name = NameHelper.dotSeparatedStringFromList(node.getServer().getParts());
}
TrustlevelRelationEntry entry = (TrustlevelRelationEntry) resolver.resolve(name, TrustlevelRelationEntry.KIND, getNameSpaceFor(node.getMainParent()));
if (entry != null) {
for (ISecTrustlevelRelationChecker cc : secTrustlevelRelationChecker) {
cc.check(node, entry);
......
package secarc.ets.cocos.checkers;
import interfaces2.resolvers.AmbigousException;
import mc.umlp.arcd._ast.ASTArcConnector;
import mc.umlp.arcd._ast.ASTArcSimpleConnector;
import secarc.ets.entries.SecConnectorEntry;
/**
* Context condition checker interface for checking secconnector
* related context conditions
*
* <br>
* <br>
* Copyright (c) 2011 RWTH Aachen. All rights reserved
*
* @author (last commit) $Author$
* @version $Date$<br>
* $Revision$
*
*/
public interface ISecConnectorChecker {
/**
*
* @param node ast node to be checked
* @param entry entry related connector entry to be checked
* @throws AmbigousException
*/
void check(ASTArcConnector node, SecConnectorEntry entry) throws AmbigousException;
/**
*
* @param node ast node to be checked
* @param entry entry related connector entry to be checked
* @throws AmbigousException
*/
void check(ASTArcSimpleConnector node, SecConnectorEntry entry) throws AmbigousException;
}
package secarc.ets.cocos.checkers;
import interfaces2.resolvers.AmbigousException;
import secarc.ets.entries.SecSubComponentEntry;
import mc.umlp.arcd._ast.ASTArcSubComponent;
/**
* Context condition checker interface for checking SecSubComponent
* related context conditions
*
* <br>
* <br>
* Copyright (c) 2011 RWTH Aachen. All rights reserved
*
* @author (last commit) $Author$
* @version $Date$<br>
* $Revision$
*
*/
public interface ISecSubComponentChecker {
/**
*
* @param node ast node to be checked
* @param entry entry related subcomponent entry to be checked
* @throws AmbigousException
*/
void check(ASTArcSubComponent node, SecSubComponentEntry entry) throws AmbigousException;
}
......@@ -116,7 +116,7 @@ public class UniqueDefinitionWithFullQualifiedNames extends ComponentExistence {
SubComponentEntry higherTrustlevelSubComoponent = innerCheck(node, node.getMainParent(), refHigherTrustlevelComponent);
//Checked in other coco
if(lowerTrustlevelSubComoponent != null | higherTrustlevelSubComoponent != null) {
if(lowerTrustlevelSubComoponent == null | higherTrustlevelSubComoponent == null) {
return;
}
......@@ -164,7 +164,7 @@ public class UniqueDefinitionWithFullQualifiedNames extends ComponentExistence {
}
if(count > 1) {
addReport("There is more than one identity link of the form: trustlevelrelation " + entry.getComponentWithLowerTrustlevel() + relation + entry.getComponentWithHigherTrustlevel(), node.get_SourcePositionStart());
addReport("There is more than one relation of the form: trustlevelrelation " + entry.getComponentWithLowerTrustlevel() + relation + entry.getComponentWithHigherTrustlevel(), node.get_SourcePositionStart());
}
}
......@@ -174,8 +174,8 @@ public class UniqueDefinitionWithFullQualifiedNames extends ComponentExistence {
SubComponentEntry higherTrustlevelComoponentCompare = null;
for(TrustlevelRelationEntry trustlevelRelationEntrySource : entry.getAllTrustlevelRelation()) {
lowerTrustlevelComoponentCompare = innerCheck(trustlevelRelationEntrySource.getNode(), ((ASTSecArcIdentity) trustlevelRelationEntrySource.getNode()).getMainParent(), trustlevelRelationEntrySource.getComponentWithLowerTrustlevel());
higherTrustlevelComoponentCompare = innerCheck(trustlevelRelationEntrySource.getNode(), ((ASTSecArcIdentity) trustlevelRelationEntrySource.getNode()).getMainParent(), trustlevelRelationEntrySource.getComponentWithHigherTrustlevel());
lowerTrustlevelComoponentCompare = innerCheck(trustlevelRelationEntrySource.getNode(), ((ASTSecArcTrustlevelRelation) trustlevelRelationEntrySource.getNode()).getMainParent(), trustlevelRelationEntrySource.getComponentWithLowerTrustlevel());
higherTrustlevelComoponentCompare = innerCheck(trustlevelRelationEntrySource.getNode(), ((ASTSecArcTrustlevelRelation) trustlevelRelationEntrySource.getNode()).getMainParent(), trustlevelRelationEntrySource.getComponentWithHigherTrustlevel());
if(lowerTrustlevelComoponent.equals(lowerTrustlevelComoponentCompare) && higherTrustlevelComoponent.equals(higherTrustlevelComoponentCompare)) {
count++;
}
......
......@@ -29,9 +29,9 @@ public class IdentityCycleCheck extends ContextCondition implements ISecIdentity
CycleDetector<Vertex<? extends STEntry>, Edge> cycleDetector = new CycleDetector<Vertex<? extends STEntry>, Edge>(graph.getRawGraph());
Set<Vertex<? extends STEntry>> setCycle = cycleDetector.findCyclesContainingVertex(Vertex.of(entry));
Set<Vertex<? extends STEntry>> setCycle = cycleDetector.findCycles();
if(setCycle != null && !setCycle.isEmpty()) {
if(setCycle.contains(Vertex.of(entry))) {
addReport("There is a cycle of identity links starting in " + entry, node.get_SourcePositionStart());
}
......
......@@ -67,7 +67,7 @@ public class RoleWithIdentity extends ContextCondition implements
//First element is not needed
if(!(element instanceof IdentityEntry)) {
addReport("For the component " + NameHelper.getSimpleGenericNameFromComplexname(entry.getName()) + " are roles defined. These roles must be authenticated by an identity link.", node.get_SourcePositionStart());
addReport("For the component " + entry.getName() + " are roles defined. These roles must be authenticated by an identity link.", node.get_SourcePositionStart());
}
}
......
......@@ -94,8 +94,8 @@ public class CorrectRelationBetweenTrustlevel extends ComponentExistence {
}
if(entry.isEqual() && higherTrustlevelAsInteger != lowerTrustlevelAsInteger) {
addReport("The relation between the components " + refLowerTrustlevelComponent + " (trustlevel " + lowerTrustlevelAsString + ") and " + refHigherTrustlevelComponent + " (trustlevel " + higherTrustlevelAsString + ") is defined ad equals.", node.get_SourcePositionStart());
} else if (entry.isEqual() && higherTrustlevelAsInteger < lowerTrustlevelAsInteger) {
addReport("The relation between the components " + refLowerTrustlevelComponent + " (trustlevel " + lowerTrustlevelAsString + ") and " + refHigherTrustlevelComponent + " (trustlevel " + higherTrustlevelAsString + ") is defined as equals.", node.get_SourcePositionStart());
} else if (!entry.isEqual() && higherTrustlevelAsInteger < lowerTrustlevelAsInteger) {
addReport("The trustlevel of the component " + refLowerTrustlevelComponent + " (trustlevel " + lowerTrustlevelAsString + ") must be lower than the trustlevel of component " + refHigherTrustlevelComponent + " (trustlevel " + higherTrustlevelAsString + ") regarding the defined relation.", node.get_SourcePositionStart());
}
......
......@@ -78,7 +78,7 @@ public class MontiSecArcCoCoTest extends TestWithSymtab<MontiSecArcTestTool> {
*/
@Test
public void testIdentity() {
MontiSecArcTool tool = createTestToolWithoutJava(new String[] { "src/test/resources/secarc/coco/identity/" });
MontiSecArcTool tool = createTestToolWithoutJava(new String[] { "src/test/resources/secarc/coco/identity" });
tool.init();
assertTrue(tool.run());
......@@ -87,8 +87,9 @@ public class MontiSecArcCoCoTest extends TestWithSymtab<MontiSecArcTestTool> {
errorCodes.add(MontiSecArcErrorCodes.ComponentExistence);
errorCodes.add(MontiSecArcErrorCodes.UniqueDefinitionWithFullQualifiedName);
errorCodes.add(MontiSecArcErrorCodes.DifferentSourceTarget);
errorCodes.add(MontiSecArcErrorCodes.IdentityCycleCheck);
assertEquals(4, handler.getErrors().size());
assertEquals(8, handler.getErrors().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
......@@ -130,7 +131,8 @@ public class MontiSecArcCoCoTest extends TestWithSymtab<MontiSecArcTestTool> {
assertTrue(tool.run());
assertEquals(0, handler.getErrors().size());
assertEquals(1, handler.getWarnings().size());
assertEquals(MontiSecArcErrorCodes.NamingConventions, handler.getWarnings().get(0).getErrorcode());
}
/**
......@@ -175,11 +177,13 @@ public class MontiSecArcCoCoTest extends TestWithSymtab<MontiSecArcTestTool> {
errorCodes.add(MontiSecArcErrorCodes.PortExistence);
errorCodes.add(MontiSecArcErrorCodes.UniqueRoleDefinitionForComponent);
errorCodes.add(MontiSecArcErrorCodes.UniqueRoleDefinitionForPort);
errorCodes.add(MontiSecArcErrorCodes.RoleWithIdentity);
assertEquals(5, handler.getErrors().size());
assertEquals(7, handler.getErrors().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
assertEquals(1, handler.getWarnings().size());
}
/**
......@@ -208,6 +212,7 @@ public class MontiSecArcCoCoTest extends TestWithSymtab<MontiSecArcTestTool> {
assertEquals(1, handler.getErrors().size());
assertEquals(MontiSecArcErrorCodes.UniqueConfiguration, handler.getErrors().get(0).getErrorcode());
assertEquals(1, handler.getWarnings().size());
}
/**
......@@ -233,8 +238,15 @@ public class MontiSecArcCoCoTest extends TestWithSymtab<MontiSecArcTestTool> {
tool.init();
assertTrue(tool.run());
List<MontiSecArcErrorCodes> errorCodes = new ArrayList<MontiSecArcErrorCodes>();
errorCodes.add(MontiSecArcErrorCodes.CorrectRelationBetweenTrustlevel);
errorCodes.add(MontiSecArcErrorCodes.ComponentExistence);
errorCodes.add(MontiSecArcErrorCodes.UniqueDefinitionWithFullQualifiedName);
assertEquals(0, handler.getErrors().size());
assertEquals(6, handler.getErrors().size());
for(ProblemReport error : handler.getErrors()) {
assertTrue(errorCodes.contains(error.getErrorcode()));
}
}
}
package secarc.coco.configuration;
component WrongNaming {
accesscontrol on;
trustlevel +1;
configuration Test;
cpe "1.2";
identity weak help -> targetHelp;
component Help help {
trustlevel +1;
}
component TargetHelp targetHelp {
access user;
}
}
\ No newline at end of file
package secarc.coco.version;
package secarc.coco.cpe;
component VersionCorrect {
component CPECorrect {
accesscontrol on;
......
package secarc.coco.version;
package secarc.coco.cpe;
component VersionTwice {
component CPETwice {
accesscontrol on;
......
package secarc.coco.filtercomponent;
component WrongNaming {
accesscontrol on;
trustlevel +1;
identity weak help -> targetHelp;
component Help help {
trustlevel +1;
}
component TargetHelp targetHelp {
access user;
}