Skip to content

Commit

Permalink
adding tests and reorging file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
summitt committed Jan 14, 2024
1 parent 3c06ade commit e4305c2
Show file tree
Hide file tree
Showing 33 changed files with 128 additions and 52 deletions.
11 changes: 3 additions & 8 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<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="src" path="FactionExtender/src"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<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"/>
Expand All @@ -19,5 +13,6 @@
<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>
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>
3 changes: 0 additions & 3 deletions FactionExtender/src/META-INF/MANIFEST.MF

This file was deleted.

26 changes: 0 additions & 26 deletions src/com/faction/unittests/ExtenderTestCase.java

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class BaseExtension {

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

public BaseExtension() {
logger = new Logger();
Expand All @@ -25,7 +25,7 @@ public List<Log> getLogs(){
}

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

public void setConfigs(HashMap<String,String>configs) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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 All @@ -21,6 +21,6 @@ public interface ApplicationInventory {
* @param Name is the name of the application
* @return InvetoryResult[] is an array of Applications
*/
public InventoryResult[] search(String id, String Name, HashMap<String,String> configs);
public InventoryResult[] search(String id, String Name);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import com.faction.elements.Vulnerability;
import com.faction.elements.results.AssessmentManagerResult;
import com.faction.elements.utils.Log;
import com.faction.elements.BaseExtension;


public interface AssessmentManager{
public interface AssessmentManager extends BaseInterface{
static public enum Operation { Create, Update, Delete,
Finalize, PeerReviewCreated, PeerReviewCompleted,
PeerReviewAccepted};
Expand All @@ -26,9 +25,7 @@ static public enum Operation { Create, Update, Delete,
* null if the Operation is Create.
* @param Operation is Create Update or Delete as defined by the Operation Static variable
*/
public AssessmentManagerResult assessmentChange(Assessment asmt, List<Vulnerability> vulns, Operation Operation, HashMap<String,String> configs);


public AssessmentManagerResult assessmentChange(Assessment asmt, List<Vulnerability> vulns, Operation Operation);



Expand Down
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
Expand Up @@ -6,7 +6,7 @@
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 All @@ -17,7 +17,7 @@ static public enum Operation { Cancel, PASS,FAIL,Assigned};
* @return All Operations return the updated vulnerability. If return value is null then
* Faction will not update the internal database.
*/
public Vulnerability verificationChange(User changer, Vulnerability vulnerability, Verification verification, Operation Operation, HashMap<String,String> configs);
public Vulnerability verificationChange(User changer, Vulnerability vulnerability, Verification verification, Operation Operation);


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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 All @@ -16,7 +16,7 @@ static public enum Operation { Create, Update, Delete }
* @return All Operations return the updated vulnerability.
*
*/
public Vulnerability vulnChange(Assessment asmt, Vulnerability vuln, Operation Operation, HashMap<String,String> configs);
public Vulnerability vulnChange(Assessment asmt, Vulnerability vuln, Operation Operation);


}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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;
}
}

}


0 comments on commit e4305c2

Please sign in to comment.