-
Notifications
You must be signed in to change notification settings - Fork 28
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
ASA 8404 (#218) #220
ASA 8404 (#218) #220
Changes from 13 commits
5a957ff
a610cb5
300cac0
c60f1c4
408cf84
0bf9eac
c5883be
a61f127
96e802a
41ad20c
bd2616b
236f7f2
dc400a0
a2d52b1
b1bcb55
10fa048
57ce2b8
14859aa
bb5900b
2a17e9f
1d9332f
ed7fc17
8d33f1d
db9021c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.hcl.appscan.jenkins.plugin.results; | ||
|
||
import com.hcl.appscan.jenkins.plugin.scanners.Scanner; | ||
import com.hcl.appscan.sdk.CoreConstants; | ||
import com.hcl.appscan.sdk.results.IResultsProvider; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class CombinedResultsInspector { | ||
|
||
private List<FailureCondition> m_conditions; | ||
private IResultsProvider m_resultsProvider; | ||
|
||
public CombinedResultsInspector(List<FailureCondition> conditions, IResultsProvider resultsProvider) { | ||
m_conditions = conditions; | ||
m_resultsProvider = resultsProvider; | ||
} | ||
|
||
public boolean shouldFail(Map<String,String> properties) { | ||
for(FailureCondition condition : m_conditions) { | ||
String type = condition.getFailureType(); | ||
int threshold = condition.getThreshold(); | ||
if(exceedsThresholdCombined(type, threshold, properties)) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
private void issuesCountSAST(Map<String,String> properties) { | ||
properties.put("totalCountSAST", String.valueOf(m_resultsProvider.getFindingsCount())); | ||
properties.put("criticalCountSAST", String.valueOf(m_resultsProvider.getCriticalCount())); | ||
properties.put("highCountSAST", String.valueOf(m_resultsProvider.getHighCount())); | ||
properties.put("mediumCountSAST", String.valueOf(m_resultsProvider.getMediumCount())); | ||
properties.put("lowCountSAST", String.valueOf(m_resultsProvider.getLowCount())); | ||
} | ||
|
||
private boolean exceedsThresholdCombined(String type, int threshold, Map<String,String> properties) { | ||
String scanType = properties.get(CoreConstants.SCANNER_TYPE); | ||
if (scanType.equals(Scanner.STATIC_ANALYZER)) { | ||
issuesCountSAST(properties); | ||
} else { | ||
switch(type.toLowerCase()) { | ||
case "total": //$NON-NLS-1$ | ||
if(properties.containsKey("totalCountSAST")) { | ||
int totalCountSAST = Integer.parseInt(properties.remove("totalCountSAST")); | ||
return (totalCountSAST+m_resultsProvider.getFindingsCount()) > threshold; | ||
} | ||
return m_resultsProvider.getFindingsCount() > threshold; | ||
case "critical": //$NON-NLS-1$ | ||
if(properties.containsKey("criticalCountSAST")) { | ||
int criticalCountSAST = Integer.parseInt(properties.remove("criticalCountSAST")); | ||
return (criticalCountSAST+m_resultsProvider.getCriticalCount()) > threshold; | ||
} | ||
return m_resultsProvider.getCriticalCount() > threshold; | ||
case "high": //$NON-NLS-1$ | ||
if(properties.containsKey("highCountSAST")) { | ||
int highCountSAST = Integer.parseInt(properties.remove("highCountSAST")); | ||
return (highCountSAST+m_resultsProvider.getHighCount()) > threshold; | ||
} | ||
return m_resultsProvider.getHighCount() > threshold; | ||
case "medium": //$NON-NLS-1$ | ||
if(properties.containsKey("mediumCountSAST")) { | ||
int mediumCountSAST = Integer.parseInt(properties.remove("mediumCountSAST")); | ||
return (mediumCountSAST+m_resultsProvider.getMediumCount()) > threshold; | ||
} | ||
return m_resultsProvider.getMediumCount() > threshold; | ||
case "low": //$NON-NLS-1$ | ||
if(properties.containsKey("lowCountSAST")) { | ||
int lowCountSAST = Integer.parseInt(properties.remove("lowCountSAST")); | ||
return (lowCountSAST+m_resultsProvider.getLowCount()) > threshold; | ||
} | ||
return m_resultsProvider.getLowCount() > threshold; | ||
default: | ||
return false; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,13 @@ | |
|
||
import com.hcl.appscan.sdk.results.IResultsProvider; | ||
|
||
public class ResultsInspector { | ||
public class ResultsInspector extends CombinedResultsInspector { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does the ResultsInspector extend the CombinedResultsInseptor? It seems this should be the other way around, where the CombinedResultsInspector adds to the logic of the ResultsInspector. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the CombinedResultsInspector class as we are now handling the results in the SDK. |
||
|
||
private List<FailureCondition> m_conditions; | ||
private IResultsProvider m_resultsProvider; | ||
|
||
public ResultsInspector(List<FailureCondition> conditions, IResultsProvider resultsProvider) { | ||
m_conditions = conditions; | ||
m_resultsProvider = resultsProvider; | ||
super(conditions, resultsProvider); | ||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
|
||
import com.hcl.appscan.jenkins.plugin.auth.ASoCCredentials; | ||
import com.hcl.appscan.jenkins.plugin.builders.AppScanBuildStep; | ||
import com.hcl.appscan.sdk.CoreConstants; | ||
import com.hcl.appscan.sdk.logging.IProgress; | ||
import org.jenkinsci.Symbol; | ||
import org.kohsuke.stapler.AncestorInPath; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
@@ -196,8 +198,18 @@ public String upgradeLoginScenario(){ | |
} | ||
} | ||
|
||
public void validations(IAuthenticationProvider authProvider, Map<String, String> properties, IProgress progress) throws AbortException { | ||
if (((JenkinsAuthenticationProvider) authProvider).isAppScan360()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 2 "if" conditions should be "anded" together rather than nesting them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, sure. |
||
if (properties.containsKey(Scanner.PRESENCE_ID)) { | ||
throw new AbortException(Messages.error_presence_AppScan360()); | ||
} | ||
} else if (!properties.containsKey(Scanner.PRESENCE_ID) && !ServiceUtil.isValidUrl(properties.get(TARGET), authProvider, authProvider.getProxy())) { | ||
throw new AbortException(Messages.error_url_validation(properties.get(TARGET))); | ||
} | ||
} | ||
|
||
@Override | ||
public Map<String, String> getProperties(VariableResolver<String> resolver) throws hudson.AbortException { | ||
public Map<String, String> getProperties(VariableResolver<String> resolver) throws AbortException { | ||
Map<String, String> properties = new HashMap<String, String>(); | ||
if (resolver == null) { | ||
properties.put(TARGET, getTarget()); | ||
|
@@ -327,9 +339,9 @@ public FormValidation doCheckScanFile(@QueryParameter String scanFile) { | |
|
||
public FormValidation doCheckTarget(@QueryParameter String target,@RelativePath("..") @QueryParameter String credentials, @AncestorInPath ItemGroup<?> context, @QueryParameter String presenceId) { | ||
JenkinsAuthenticationProvider authProvider = new JenkinsAuthenticationProvider(credentials,context); | ||
if(presenceId != null && presenceId.equals(EMPTY) && !target.equals(EMPTY) && !ServiceUtil.isValidUrl(target, authProvider, authProvider.getProxy())) { | ||
return FormValidation.error(Messages.error_url_validation_ui()); | ||
} | ||
if(!authProvider.isAppScan360() && presenceId != null && presenceId.equals(EMPTY) && !target.equals(EMPTY) && !ServiceUtil.isValidUrl(target, authProvider, authProvider.getProxy())) { | ||
return FormValidation.error(Messages.error_url_validation_ui()); | ||
} | ||
return FormValidation.validateRequired(target); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
package com.hcl.appscan.jenkins.plugin.scanners; | ||
|
||
import com.hcl.appscan.sdk.auth.IAuthenticationProvider; | ||
import com.hcl.appscan.sdk.logging.IProgress; | ||
import hudson.AbortException; | ||
import hudson.Util; | ||
import hudson.model.AbstractDescribableImpl; | ||
|
@@ -38,7 +40,9 @@ public String getTarget() { | |
} | ||
|
||
public abstract Map<String, String> getProperties(VariableResolver<String> resolver) throws AbortException; | ||
|
||
|
||
public abstract void validations(IAuthenticationProvider authProvider, Map<String, String> properties, IProgress progress) throws AbortException; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function name should be a verb, like "validate" or "validateSettings". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, Now, Using the "validateSettings()" method name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In all instances, the IAuthenticationProvider is being passed in and then cast to a JenkinsAuthenticationProvider just to check if this is AppScan 360. Why not just pass a boolean here instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In DynamicAnalyzer class we are doing the URL validity check & for that we need to call the getProxy() method from authProvider class. Instead of passing the IAuthenticationProvider, I will pass the JenkinsAuthenaticationProvider itself. |
||
|
||
public abstract String getType(); | ||
|
||
protected String resolvePath(String path, VariableResolver<String> resolver) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The results inspector should not require knowledge of the scan type or issue types (there are mentions of totalCountSAST for example).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the CombinedResultsInspector class as we are now handling the results in the SDK.