Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appstore enhancements #2

Merged
merged 2 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="FactionExtender/src"/>
<classpathentry kind="lib" path="FactionExtender/target/FactionExtender-0.0.1-SNAPSHOT.jar"/>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
4 changes: 2 additions & 2 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
Expand Down
7 changes: 5 additions & 2 deletions .settings/org.eclipse.wst.common.component
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">

<wb-module deploy-name="FactionExtender">
<wb-resource deploy-path="/" source-path="/FactionExtender/src"/>
<wb-resource deploy-path="/" source-path="/src"/>
<wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/test/java"/>

</wb-module>

</project-modules>
2 changes: 2 additions & 0 deletions .settings/org.eclipse.wst.validation.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
disabled=06target
eclipse.preferences.version=1
3 changes: 0 additions & 3 deletions FactionExtender/src/META-INF/MANIFEST.MF

This file was deleted.

12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
Expand Down
10 changes: 0 additions & 10 deletions src/com/faction/extender/ExtensionMetaData.java

This file was deleted.

36 changes: 36 additions & 0 deletions src/main/java/com/faction/elements/BaseExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.faction.elements;

import com.faction.elements.utils.Logger;
import com.faction.elements.utils.Log;

import java.util.HashMap;
import java.util.List;


public class BaseExtension {

private Logger logger;
private HashMap<String,String> configs = new HashMap<>();

public BaseExtension() {
logger = new Logger();
}

public Logger getLogger() {
return logger;
}

public List<Log> getLogs(){
return logger.getLogs();
}

public HashMap<String,String> getConfigs(){
return this.configs;
}

public void setConfigs(HashMap<String,String>configs) {
this.configs = configs;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,45 @@

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Date;

public class Logger {
public class Log {

public enum LEVEL { INFO, WARNING, ERROR, DEBUG };
private LEVEL level;
private String message;
private String stackTrace;
private Date timestamp;

public Logger(LEVEL level, Exception exception) {
public Log(LEVEL level, Exception exception) {
this.timestamp = new Date();
this.level = level;
this.message = exception.getMessage();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
exception.printStackTrace(pw);
this.stackTrace = sw.toString();

}
public Log(LEVEL level, String message) {
this.timestamp = new Date();
this.level = level;
this.message = message;
this.stackTrace = "";

}
public LEVEL getLevel() {
return level;
}
public void setLevel(LEVEL level) {
this.level = level;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getStackTrace() {
return this.stackTrace;
}







public Date getTimeStamp() {
return this.timestamp;
}

}
26 changes: 26 additions & 0 deletions src/main/java/com/faction/elements/utils/Logger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.faction.elements.utils;

import java.util.ArrayList;
import java.util.List;

import com.faction.elements.utils.Log.LEVEL;

public class Logger {

List<Log> logs = new ArrayList<Log>();

public void addLog(LEVEL level, Exception exception) {
logs.add(new Log(level, exception));
}
public void addLog(LEVEL level, String message) {
logs.add(new Log(level, message));
}
public List<Log> getLogs() {
logs.sort((l1,l2) -> l1.getTimeStamp().compareTo(l2.getTimeStamp()));
return logs;

}



}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.faction.extender;

import java.util.HashMap;

import com.faction.elements.results.InventoryResult;

public interface ApplicationInventory {
public interface ApplicationInventory extends BaseInterface {

/**
* This is an interface for the Faction API that allows
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package com.faction.extender;

import java.util.HashMap;

import java.util.List;

import com.faction.elements.Assessment;
import com.faction.elements.Vulnerability;
import com.faction.elements.results.AssessmentManagerResult;
import com.faction.elements.utils.Log;


public interface AssessmentManager {
public interface AssessmentManager extends BaseInterface{
static public enum Operation { Create, Update, Delete,
Finalize, PeerReviewCreated, PeerReviewCompleted,
PeerReviewAccepted};


/**
* This function allows you to update other interfaces when the command is run. This can also up
Expand All @@ -24,7 +27,6 @@ static public enum Operation { Create, Update, Delete,
*/
public AssessmentManagerResult assessmentChange(Assessment asmt, List<Vulnerability> vulns, Operation Operation);




}
27 changes: 27 additions & 0 deletions src/main/java/com/faction/extender/BaseInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.faction.extender;

import java.util.HashMap;
import java.util.List;

import com.faction.elements.utils.Log;

public interface BaseInterface {
/**
* This function is used by Faction to set the configurations for the extension. This should not be called
* locally in your classes
*
* @param configs
*/
public void setConfigs(HashMap<String,String>configs);


/**
* This function is used by Faction to get all logs for the extension. This should not be called locally in
* your classes
*
* @return List<Log> logs : Returns a list of logs that can be displayed in the Faction UI
*/
public List<Log> getLogs();


}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.faction.extender;

import java.util.HashMap;

import com.faction.elements.User;
import com.faction.elements.Verification;
import com.faction.elements.Vulnerability;

public interface VerificationManager {
public interface VerificationManager extends BaseInterface {
static public enum Operation { Cancel, PASS,FAIL,Assigned};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.faction.extender;

import java.util.HashMap;

import com.faction.elements.Assessment;
import com.faction.elements.Vulnerability;
import com.faction.extender.AssessmentManager.Operation;

public interface VulnerabilityManager {
public interface VulnerabilityManager extends BaseInterface {
static public enum Operation { Create, Update, Delete }

/**
Expand Down
83 changes: 83 additions & 0 deletions src/test/java/com/faction/unittests/ExtenderTestCase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.faction.unittests;

import static org.junit.jupiter.api.Assertions.*;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.ServiceLoader;

import org.junit.jupiter.api.Test;

import com.faction.elements.Assessment;
import com.faction.elements.BaseExtension;
import com.faction.elements.Vulnerability;
import com.faction.elements.results.AssessmentManagerResult;
import com.faction.elements.utils.Log;
import com.faction.elements.utils.Log.LEVEL;
import com.faction.extender.AssessmentManager;
import com.faction.extender.AssessmentManager.Operation;



public class ExtenderTestCase {

@Test
void test() {
AssessmentManager asmtMgr = new MyAssmtMgr();
HashMap<String,String>configs = new HashMap<>();
configs.put("Test1", "Test Config 1");
configs.put("Test2", "Test Config 2");

asmtMgr.setConfigs(configs);

Assessment asmt = new Assessment();
asmt.setSummary("Default");

Vulnerability vuln = new Vulnerability();
List<Vulnerability> vulns = new ArrayList<>();
vulns.add(vuln);

AssessmentManagerResult result = asmtMgr.assessmentChange(asmt, vulns, Operation.Create);

assertTrue(result.getAssessment().getSummary().equals("This is a test"));

assertTrue(asmtMgr.getLogs().size() == 2);

List<Log> logs = asmtMgr.getLogs();
assertTrue(logs.stream().anyMatch( log -> log.getMessage().equals("Got Config1: Test Config 1")));
assertTrue(logs.stream().anyMatch( log -> log.getMessage().equals("Got Config2: Test Config 2")));



assertTrue(true);

}

public class MyAssmtMgr extends BaseExtension implements AssessmentManager{

@Override
public AssessmentManagerResult assessmentChange(Assessment asmt, List<Vulnerability> vulns,
Operation Operation) {
String config1 = this.getConfigs().get("Test1");
String config2 = this.getConfigs().get("Test2");

asmt.setSummary("This is a test");

this.getLogger().addLog(LEVEL.INFO, "Got Config1: " + config1);
this.getLogger().addLog(LEVEL.INFO, "Got Config2: " + config2);

AssessmentManagerResult result = new AssessmentManagerResult();
result.setAssessment(asmt);
result.setVulnerabilities(vulns);
return result;
}
}

}