Commit 4f022868 authored by Jonathan Shahen's avatar Jonathan Shahen
Browse files

Added regression tests, test 3 and 4 of positive take too long and thus...

Added regression tests, test 3 and 4 of positive take too long and thus timeout (either increase the timeout time or figure out why  they are taking so long); moved Mohawk into an instance for better testing; fixed build script so you can now run 'java -jar mohawk.jar <params here>' (before it would ask you to put in the class name you wanted to run
parent eafe469d
......@@ -2,10 +2,31 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="lib/antlr-3.2.jar"/>
<classpathentry kind="lib" path="lib/stringtemplate.jar"/>
<classpathentry kind="lib" path="lib/commons-cli-1.2/commons-cli-1.2.jar"/>
<classpathentry kind="lib" path="lib/commons-lang3-3.3.2/commons-lang3-3.3.2.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="lib/antlr-3.2.jar">
<attributes>
<attribute name="javadoc_location" value="http://www.antlr.org/api/Java/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/commons-cli-1.2.jar">
<attributes>
<attribute name="javadoc_location" value="http://commons.apache.org/proper/commons-cli/javadocs/api-1.2/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/commons-lang3-3.3.2.jar">
<attributes>
<attribute name="javadoc_location" value="http://commons.apache.org/proper/commons-lang/javadocs/api-3.3.2/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="lib/junit-4.12.jar">
<attributes>
<attribute name="javadoc_location" value="http://junit.org/javadoc/latest/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/stringtemplate.jar">
<attributes>
<attribute name="javadoc_location" value="http://www.stringtemplate.org/api/"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
......@@ -2,3 +2,4 @@
data/testcases/mohawk.jar
*.csv
mohawk.log*
src/mohawk/rbac/generated/
<!--
@author Karthick Jayaraman, Jonathan Shahen
-->
<project name="mohawk" default="compile" basedir=".">
<description>Mohawk Tool Implementation.</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="lib" location="lib"/>
<property name="bin" location="bin" />
<property name="data" location="data"/>
<property name="build" location="${bin}/build"/>
<property name="dist" location="${bin}/dist"/>
<property name="qtest" location="${data}/testcases"/>
<project name="mohawk" default="dist" basedir=".">
<description>Mohawk Tool Implementation.</description>
<target name="init">
<!-- create the build directory structure used by compile -->
<mkdir dir="${build}"/>
<!-- create the distribution directory -->
<mkdir dir="${dist}"/>
</target>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="lib" location="lib"/>
<property name="bin" location="bin" />
<property name="data" location="data"/>
<property name="build" location="${bin}/build"/>
<property name="dist" location="${bin}/dist"/>
<property name="qtest" location="${data}/testcases"/>
<property name="mohawksrc" location="${src}/mohawk"/>
<property name="rbac" location="${mohawksrc}/rbac/generated"/>
<target name="parser" depends="init" description="generate parser files" >
<!-- Create the parser files -->
<antlr target="${lib}/rbac.g" outputdirectory="${src}/mohawk" >
<classpath>
<pathelement location="${lib}/antlr-3.2.jar" />
</classpath>
</antlr>
</target>
<target name="init">
<!-- create the bin directory -->
<mkdir dir="${bin}"/>
<!-- create the build directory -->
<mkdir dir="${build}"/>
<!-- create the distribution directory -->
<mkdir dir="${dist}"/>
</target>
<target name="compile" depends="parser" description="compile the source " >
<!-- compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" debug="on" deprecation="true">
<classpath>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
<copy file="${lib}/smvtemplate.st" todir="${build}/mohawk" />
<copy file="${lib}/transitions.st" todir="${build}/mohawk" />
<copy file="${lib}/rbac.st" todir="${build}/mohawk" />
</target>
<target name="parser" depends="init" description="generate parser files" >
<!-- Create the parser files -->
<antlr target="${lib}/rbac.g" outputdirectory="${rbac}" >
<classpath>
<pathelement location="${lib}/antlr-3.2.jar" />
</classpath>
</antlr>
</target>
<target name="dist" depends="compile" description="generate the distribution" >
<!-- put everything in ${build} into the jar file -->
<jar destfile="${dist}/${ant.project.name}.jar" basedir="${build}">
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Main-Class" value="mohawk.MohawkMain" />
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="${build}" />
<zipfileset src="${lib}/stringtemplate.jar" />
<zipfileset src="${lib}/antlr-3.2.jar" />
</jar>
</target>
<target name="qtest" depends="compile" description="generate a JAR file that will be placed close to the data for quick testing" >
<!-- @author Jonathan Shahen -->
<!-- put everything in ${build} into the jar file -->
<jar destfile="${qtest}/${ant.project.name}.jar" basedir="${build}">
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Main-Class" value="mohawk.MohawkMain" />
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="${build}" />
<zipfileset src="${lib}/stringtemplate.jar" />
<zipfileset src="${lib}/antlr-3.2.jar" />
</jar>
</target>
<target name="compile" depends="parser" description="compile the source " >
<!-- compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" debug="on" deprecation="true">
<classpath>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
<!--<copy file="${lib}/smvtemplate.st" todir="${build}/mohawk" />
<copy file="${lib}/transitions.st" todir="${build}/mohawk" />
<copy file="${lib}/rbac.st" todir="${build}/mohawk" /> -->
</target>
<target name="clean" description="clean up">
<!-- delete the ${build} and ${dist} directory trees -->
<delete dir="${bin}"/>
<delete>
<fileset dir="." defaultexcludes="no">
<include name="**/*.*~"/>
</fileset>
</delete>
</target>
<target name="dist" depends="compile" description="generate the distribution" >
<!-- put everything in ${build} into the jar file -->
<jar destfile="${dist}/${ant.project.name}.jar" basedir="${build}">
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Main-Class" value="mohawk.Mohawk" />
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="${build}" />
<zipfileset src="${lib}/stringtemplate.jar" />
<zipfileset src="${lib}/antlr-3.2.jar" />
<zipfileset src="${lib}/commons-cli-1.2.jar" />
<zipfileset src="${lib}/commons-lang3-3.3.2.jar" />
<zipfileset src="${lib}/hamcrest-core-1.3.jar" />
<zipfileset src="${lib}/junit-4.12.jar" />
</jar>
</target>
<target name="qtest" depends="compile" description="generate a JAR file that will be placed close to the data for quick testing" >
<!-- @author Jonathan Shahen -->
<!-- put everything in ${build} into the jar file -->
<jar destfile="${qtest}/${ant.project.name}.jar" basedir="${build}">
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Main-Class" value="mohawk.MohawkMain" />
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="${build}" />
<zipfileset src="${lib}/stringtemplate.jar" />
<zipfileset src="${lib}/antlr-3.2.jar" />
</jar>
</target>
<target name="clean" description="clean up">
<!-- delete the ${build} and ${dist} directory trees -->
<delete dir="${bin}"/>
<delete>
<fileset dir="." defaultexcludes="no">
<include name="**/*.*~"/>
</fileset>
</delete>
</target>
</project>
Roles role0 role1 role2 role3;
Users user0 user1 user2 user3 user4;
UA <user4,role3>;
CR <FALSE,role0> <FALSE,role2>;
CA <role3,role2,role0> <role3,role2&role1,role0> <role3,role2&role0,role1> <role3,TRUE,role1> <role3,role0,role1> <role3,role1&role0,role2> <role3,role0,role2> <role3,role1,role2> <role3,TRUE,role2>;
ADMIN user4;
SPEC user0 role1;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
header {
package mohawk.rbac.generated;
import java.util.Vector;
import java.util.Stack;
import java.util.HashMap;
import java.util.Map;
import mohawk.collections.PreCondProcessorInt;
import mohawk.pieces.CAEntry;
import mohawk.pieces.CREntry;
import mohawk.pieces.PreCondition;
import mohawk.rbac.RBACInstance;
}
class RBACParser extends Parser;
options { k=3; }
{
Vector<String> vRoles;
Vector<String> vUsers;
Vector<String> vAdmin;
Map<Integer, String> mRoleIndex;
Map<String, Integer> mRole2Index;
Map<Integer, String> mUserIndex;
Map<String,Vector<Integer>> mUA;
Map<String,Vector<CREntry>> mCR;
Map<String,Vector<CAEntry>> mCA;
PreCondProcessorInt preCndP;
Stack<Integer> stackOperators;
Vector<String> vSpec; // This vector holds two strings - user and role that will be used in the LTL formulae
// Indices for user and roles while parsing
// Each user has an index corresponding to the order in which the name appears in the list.
int iRoleIndex;
int iUserIndex;
public void initRbac() {
vRoles = new Vector<String>();
vUsers = new Vector<String>();
vAdmin = new Vector<String>();
mRoleIndex = new HashMap<Integer, String>();
mRole2Index = new HashMap<String,Integer>();
mUserIndex = new HashMap<Integer, String>();
mUA = new HashMap<String,Vector<Integer>>();
mCR = new HashMap<String,Vector<CREntry>>();
mCA = new HashMap<String,Vector<CAEntry>>();
vSpec = new Vector<String>();
}
public RBACInstance getRBAC() {
return new RBACInstance(vRoles, vUsers, vAdmin, mUA, mCR, mCA,vSpec);
}
public void setUA(String strUser, String strRole) {
Vector<Integer> vUserUA = mUA.get(strUser);
if(vUserUA == null)
{
vUserUA = new Vector<Integer>();
mUA.put(strUser,vUserUA);
}
int iRoleIndex = mRole2Index.get(strRole); //getMapKey(mRoleIndex, strRole);
vUserUA.add(iRoleIndex);
}
public void addCREntry(String inStrPreCond, String inStrRole) {
CREntry crEntry = new CREntry(inStrPreCond, inStrRole);
Vector<CREntry> vCR = mCR.get(inStrRole);
if(vCR == null)
vCR = new Vector<CREntry>();
vCR.add(new CREntry(inStrPreCond, inStrRole));
mCR.put(inStrRole,vCR);
}
public void addCAEntry(String inStrAdminRole, PreCondition pcPreCond, String inStrRole) {
CAEntry caEntry = new CAEntry(inStrAdminRole, pcPreCond, inStrRole);
Vector<CAEntry> vCA = mCA.get(inStrRole);
if(vCA == null)
vCA = new Vector<CAEntry>();
vCA.add(caEntry);
mCA.put(inStrRole,vCA);
}
/*
private int getMapKey(Map<Integer,String> inMap, String inString) {
for(int i=0; i<inMap.size(); i++) {
if(inMap.get(i).equals(inString)) {
return i;
}
}
System.out.println("Error - BTree::getMapIndex - Value not found in map");
return 0;
}
*/
public void addSpec(String inStrUser, String inStrRole) {
vSpec.add(inStrUser);
vSpec.add(inStrRole);
}
}
roles : ("Roles" {iRoleIndex=0;} ) (n:ID {vRoles.add(n.getText());
mRoleIndex.put(iRoleIndex,n.getText());
mRole2Index.put(n.getText(),iRoleIndex);
iRoleIndex++; })+ SEMI;
users : ("Users" {iUserIndex=0;} ) (u:ID {vUsers.add(u.getText());
mUserIndex.put(iUserIndex,u.getText());
iUserIndex++; })+ SEMI;
ua : "UA" (LANGLE x:ID COMMA y:ID RANGLE { setUA(x.getText(),y.getText()); })+ SEMI;
ca : "CA" (caentry)* SEMI;
caentry : (LANGLE {preCndP = new PreCondProcessorInt(mRole2Index);}) d:ID COMMA e:precondition COMMA f:ID (RANGLE
{
try {
PreCondition pcPreCond = preCndP.result();
addCAEntry(d.getText(), pcPreCond, f.getText());
}catch(Exception e) {
e.printStackTrace();
}
}
);
precondition : atom (COND atom)* | "TRUE";
atom : {int iNeg=0; } (n:NOT { iNeg=1; } )? (a:ID
{
try {
if(iNeg == 0)
preCndP.add(a.getText());
else
preCndP.addNeg(a.getText());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
);
cr : "CR" (LANGLE mm:ID COMMA nn:ID RANGLE { addCREntry(mm.getText(),nn.getText()); })* SEMI;
admin : "ADMIN" (u:ID { vAdmin.add(u.getText()); })+ SEMI;
spec : "SPEC" (su:ID sr:ID { addSpec(su.getText(),sr.getText()); }) SEMI;
class RBACLexer extends Lexer;
options { k=2;}
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
;
LANGLE : '<'
;
RANGLE : '>'
;
COMMA : ','
;
COND : '&';
NOT : '-';
SEMI : ';';
WS : (' ' | '\t' | '\r' { newline();} | "\r\n" { newline();} | '\n' { newline(); } ) {$setType(Token.SKIP);};
COMMENT : "//" (~( '\n' | '\r' ))* ('\r')? '\n' {$setType(Token.SKIP);} ;
package mohawk;
public class Mohawk {
public static void main(String[] args) {
MohawkInstance mohawk = new MohawkInstance();
mohawk.run(args);
}
}
......@@ -32,24 +32,29 @@ import org.apache.commons.lang3.StringUtils;
*
*/
public class MohawkMain {
private static final String VERSION = "v2.0.1";
public static String NuSMV_filepath = "NuSMV2";
public static TestingSuite tests;
public static SMVSpecHelper SMV_helper = new SMVSpecHelper();
public class MohawkInstance {
private final String VERSION = "v2.0.1";
// Logger Fields
public final static Logger logger = Logger.getLogger("mohawk");
public static String Logger_filepath = "mohawk.log";
public static String Logger_folderpath = "";
private static ConsoleHandler consoleHandler = new ConsoleHandler();
private static Level LoggerLevel;
private static FileHandler fileHandler;
private static Boolean WriteCSVFileHeader = true;
private static String resultsFile = "latestMohawkResults.csv";
private static TestingResults results;
private static MohawkTiming timing;
public static void main(String[] args) {
public static final Logger logger = Logger.getLogger("mohawk");
private String Logger_filepath = "mohawk.log";
private String Logger_folderpath = "";
private ConsoleHandler consoleHandler = new ConsoleHandler();
private Level LoggerLevel;
private FileHandler fileHandler;
private Boolean WriteCSVFileHeader = true;
private String resultsFile = "latestMohawkResults.csv";
// Reference
private String NuSMV_filepath = "NuSMV2";
// Helpers
private TestingResults results;
private MohawkTiming timing;
private TestingSuite tests;
private SMVSpecHelper SMV_helper = new SMVSpecHelper();
public int run(String[] args) {
// create Options object
Options options = new Options();
......@@ -103,24 +108,34 @@ public class MohawkMain {
e.printStackTrace();
}
logger.severe(e.getMessage());
return -2;
} catch (Exception e) {
if (logger.getLevel() == Level.FINEST) {
e.printStackTrace();
}
logger.severe(e.getMessage());
return -1;
}
return 0;
}
public static Level getLoggerLevel() {
public Level getLoggerLevel() {
return LoggerLevel;
}
public static void setLoggerLevel(Level loggerLevel) {
public TestingSuite getTestingSuite() {
return tests;
}
public void setLoggerLevel(Level loggerLevel) {
LoggerLevel = loggerLevel;
}
@SuppressWarnings("static-access")
private static void setupOptions(Options options, String[] args) {
private void setupOptions(Options options, String[] args) {
// Add Information Options
options.addOption("help", false, "Print this message");
options.addOption("version", false, "Prints the version (" + VERSION
......@@ -228,7 +243,7 @@ public class MohawkMain {
.hasArg().create("run"));
}
private static void setupSmvSpecOptions(CommandLine cmd, Options options,
private void setupSmvSpecOptions(CommandLine cmd, Options options,
String[] args) {
// Load in SPEC Files
// SMV File
......@@ -300,8 +315,8 @@ public class MohawkMain {
}
}
private static void setupUserPreferenceOptions(CommandLine cmd,
Options options, String[] args) {
private void setupUserPreferenceOptions(CommandLine cmd, Options options,
String[] args) {
// Set the Console's Max Width
if (cmd.hasOption("maxw")) {
logger.fine("[OPTION] Setting the console's maximum width");
......@@ -329,7 +344,7 @@ public class MohawkMain {
}
private static void setupLoggerOptions(CommandLine cmd, Options options,
private void setupLoggerOptions(CommandLine cmd, Options options,
String[] args) throws SecurityException, IOException {
// Logging Level
logger.setUseParentHandlers(false);
......@@ -415,7 +430,7 @@ public class MohawkMain {
}
}
private static void setupReturnImmediatelyOptions(CommandLine cmd,
private void setupReturnImmediatelyOptions(CommandLine cmd,
Options options, String[] args) {
if (cmd.hasOption("help") == true || args.length < 1) {
HelpFormatter f = new HelpFormatter();
......@@ -424,13 +439,15 @@ public class MohawkMain {
Integer maxw = Integer.decode(cmd.getOptionValue("maxw"));
f.printHelp(maxw, "mohawk", StringUtils.repeat("-", maxw),
options, StringUtils.repeat("-", maxw), true);
return;
} catch (Exception e) {
System.out
.println("An error occured when trying to print out the help options!");
}
}
f.printHelp("mohawk", options, true);
} else {
f.printHelp(80, "mohawk", StringUtils.repeat("-", 80), options,
StringUtils.repeat("-", 80), true);
}
return;
}
......@@ -480,7 +497,7 @@ public class MohawkMain {
}
}
private static void setupResultOptions(CommandLine cmd, Options options,
private void setupResultOptions(CommandLine cmd, Options options,
String[] args) {
if (cmd.hasOption("results")) {
logger.fine("[OPTION] Changing the results file");
......
......@@ -16,7 +16,7 @@ public class MohawkConsoleFormatter extends Formatter {
private static final DateFormat df = new SimpleDateFormat(
"yyyy/MM/dd hh:mm:ss.SSSZ");
public Integer padLeft = Level.WARNING.toString().length() + 1;
public Integer maxWidth = 120;
public Integer maxWidth = 0;
public String newLineStr = "\n ";
public String format(LogRecord record) {
......
......@@ -13,6 +13,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.Vector;