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

ASA 8404 (#218) #220

Merged
merged 24 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* © Copyright IBM Corporation 2016.
* @ Copyright HCL Technologies Ltd. 2019, 2020.
* @ Copyright HCL Technologies Ltd. 2019, 2024.
* LICENSE: Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0
*/

Expand Down Expand Up @@ -151,7 +151,7 @@ public File getReport() {
}

private String getReportName() {
String name = (getScanType() + FileUtil.getValidFilename(getName())).replaceAll(" ", ""); //$NON-NLS-1$ //$NON-NLS-2$
String name = (FileUtil.getValidFilename(getName())).replaceAll(" ", ""); //$NON-NLS-1$ //$NON-NLS-2$
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra ( ) should be removed around the FileUtil.getValidFileName() call.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, Matt.

return name + REPORT_SUFFIX + "." + m_provider.getResultsFormat().toLowerCase(); //$NON-NLS-1$
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,27 +305,19 @@ private void shouldFailBuild(IResultsProvider provider,Run<?,?> build) throws Ab
}
}

private void validations(boolean isAppScan360, Map<String, String> properties, IProgress progress, String target) throws AbortException {
private void validateGeneralSettings(boolean isAppScan360, Map<String, String> properties, IProgress progress) {
if(isAppScan360) {
if (m_type.equals(Scanner.DYNAMIC_ANALYZER) && properties.containsKey(Scanner.PRESENCE_ID)) {
throw new AbortException(Messages.error_presence_AppScan360());
} if (m_type.equals(CoreConstants.SOFTWARE_COMPOSITION_ANALYZER)) {
throw new AbortException(Messages.error_sca_AppScan360());
} if (m_intervention) {
if (m_intervention) {
progress.setStatus(new Message(Message.WARNING, Messages.warning_allow_intervention_AppScan360()));
} if (properties.get(CoreConstants.OPEN_SOURCE_ONLY) != null) {
throw new AbortException(Messages.error_sca_AppScan360());
}
} else if (m_authProvider.getacceptInvalidCerts()) {
progress.setStatus(new Message(Message.WARNING, Messages.warning_asoc_certificates()));
}

if (m_type.equals(Scanner.STATIC_ANALYZER) && properties.containsKey(CoreConstants.OPEN_SOURCE_ONLY)) {
if(properties.containsKey(CoreConstants.OPEN_SOURCE_ONLY)) {
progress.setStatus(new Message(Message.WARNING, Messages.warning_sca()));
}

if(!isAppScan360 && m_type.equals(Scanner.DYNAMIC_ANALYZER) && !properties.containsKey(Scanner.PRESENCE_ID) && !ServiceUtil.isValidUrl(target, m_authProvider, m_authProvider.getProxy())) {
throw new AbortException(Messages.error_url_validation(target));
m_scanner = ScannerFactory.getScanner(Scanner.SOFTWARE_COMPOSITION_ANALYZER, m_target);
properties.put(CoreConstants.SCANNER_TYPE, CoreConstants.SOFTWARE_COMPOSITION_ANALYZER);
}
}

Expand All @@ -335,12 +327,15 @@ private void perform(Run<?,?> build, Launcher launcher, TaskListener listener) t
final boolean suspend = m_wait;
Map<String, String> properties = getScanProperties(build,listener);
String target = properties.get(CoreConstants.TARGET);
final IScan scan = ScanFactory.createScan(properties, progress, m_authProvider);
boolean isAppScan360 = ((JenkinsAuthenticationProvider) m_authProvider).isAppScan360();

validations(isAppScan360, properties, progress, target);

IResultsProvider provider = launcher.getChannel().call(new Callable<IResultsProvider, AbortException>() {
m_scanner.validateSettings((JenkinsAuthenticationProvider) m_authProvider,properties, progress);
validateGeneralSettings(isAppScan360,properties,progress);


final IScan scan = ScanFactory.createScan(properties, progress, m_authProvider);

IResultsProvider provider = launcher.getChannel().call(new Callable<IResultsProvider, AbortException>() {
private static final long serialVersionUID = 1L;

@Override
Expand All @@ -353,7 +348,7 @@ public IResultsProvider call() throws AbortException {
setInstallDir();
scan.run();

IResultsProvider provider=new NonCompliantIssuesResultProvider(scan.getScanId(), scan.getType(), scan.getServiceProvider(), progress);
IResultsProvider provider=scan.getResultsProvider(true);
provider.setReportFormat(scan.getReportFormat());
if(suspend) {
progress.setStatus(new Message(Message.INFO, Messages.analysis_running()));
Expand Down Expand Up @@ -387,8 +382,7 @@ public IResultsProvider call() throws AbortException {
message += ", " + provider.getMessage();
}
build.setDescription(message);
throw new AbortException(com.hcl.appscan.sdk.Messages.getMessage(ScanConstants.SCAN_FAILED, (" Scan Id: " + scan.getScanId() +
", Scan Name: " + scan.getName())));
throw new AbortException(com.hcl.appscan.sdk.Messages.getMessage(ScanConstants.SCAN_FAILED, ("Scan Name: " + scan.getName())));
}
else if (CoreConstants.UNKNOWN.equalsIgnoreCase(m_scanStatus)) { // In case of internet disconnect Status is set to unstable.
progress.setStatus(new Message(Message.ERROR, Messages.error_server_unavailable() + " "+ Messages.check_server(m_authProvider.getServer())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.hcl.appscan.jenkins.plugin.auth.ASoCCredentials;
import com.hcl.appscan.jenkins.plugin.builders.AppScanBuildStep;
import com.hcl.appscan.sdk.logging.IProgress;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -196,8 +197,17 @@ public String upgradeLoginScenario(){
}
}

public void validateSettings(JenkinsAuthenticationProvider authProvider, Map<String, String> properties, IProgress progress) throws AbortException {
if (authProvider.isAppScan360() && properties.containsKey(Scanner.PRESENCE_ID)) {
throw new AbortException(Messages.error_presence_AppScan360());
}
if (!authProvider.isAppScan360() && !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());
Expand Down Expand Up @@ -327,9 +337,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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/**
* @ Copyright IBM Corporation 2016.
* @ Copyright HCL Technologies Ltd. 2017, 2019.
* @ Copyright HCL Technologies Ltd. 2017, 2024.
* LICENSE: Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0
*/

package com.hcl.appscan.jenkins.plugin.scanners;

import com.hcl.appscan.jenkins.plugin.auth.JenkinsAuthenticationProvider;
import com.hcl.appscan.sdk.logging.IProgress;
import hudson.AbortException;
import hudson.Util;
import hudson.model.AbstractDescribableImpl;
Expand Down Expand Up @@ -38,7 +40,9 @@ public String getTarget() {
}

public abstract Map<String, String> getProperties(VariableResolver<String> resolver) throws AbortException;


public abstract void validateSettings(JenkinsAuthenticationProvider authProvider, Map<String, String> properties, IProgress progress) throws AbortException;

public abstract String getType();

protected String resolvePath(String path, VariableResolver<String> resolver) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
* @ Copyright HCL Technologies Ltd. 2023.
* @ Copyright HCL Technologies Ltd. 2023, 2024.
* LICENSE: Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0
*/

package com.hcl.appscan.jenkins.plugin.scanners;

import com.hcl.appscan.jenkins.plugin.Messages;
import com.hcl.appscan.jenkins.plugin.auth.JenkinsAuthenticationProvider;
import com.hcl.appscan.sdk.logging.IProgress;
import hudson.AbortException;
import hudson.Extension;
import hudson.RelativePath;
import hudson.model.ItemGroup;
Expand Down Expand Up @@ -37,7 +39,13 @@ public String getType() {
return SOFTWARE_COMPOSITION_ANALYZER;
}

public Map<String, String> getProperties(VariableResolver<String> resolver) {
public void validateSettings(JenkinsAuthenticationProvider authProvider, Map<String, String> properties, IProgress progress) throws AbortException {
if (authProvider.isAppScan360()) {
throw new AbortException(Messages.error_sca_AppScan360());
}
}

public Map<String, String> getProperties(VariableResolver<String> resolver) throws AbortException {
Map<String, String> properties = new HashMap<String, String>();
properties.put(TARGET, resolver == null ? getTarget() : resolvePath(getTarget(), resolver));
return properties;
Expand Down
Loading
Loading