Skip to content

Commit

Permalink
[JENKINS-50578] support checks
Browse files Browse the repository at this point in the history
  • Loading branch information
irissmann committed Apr 9, 2018
1 parent d4d6bfd commit 043e5c2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>de.irissmann</groupId>
<artifactId>arachni-client</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/org/jenkinsci/plugins/arachni/ArachniScanner.java
Expand Up @@ -10,6 +10,7 @@

import javax.servlet.ServletException;

import org.apache.commons.lang3.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
Expand All @@ -19,6 +20,7 @@
import de.irissmann.arachni.client.ArachniClient;
import de.irissmann.arachni.client.Scan;
import de.irissmann.arachni.client.request.ScanRequest;
import de.irissmann.arachni.client.request.ScanRequestBuilder;
import de.irissmann.arachni.client.request.Scope;
import de.irissmann.arachni.client.response.ScanResponse;
import de.irissmann.arachni.client.rest.ArachniRestClientBuilder;
Expand All @@ -38,21 +40,27 @@ public class ArachniScanner extends Builder implements SimpleBuildStep {
Logger log = LoggerFactory.getLogger(ArachniScanner.class);

private String url;
private String checks;
private ArachniScopeProperty scope;
private Scan scan;
private PrintStream console;
private ArachniClient arachniClient;

@DataBoundConstructor
public ArachniScanner(String url, ArachniScopeProperty scope) {
public ArachniScanner(String url, String checks, ArachniScopeProperty scope) {
this.url = url;
this.checks = checks;
this.scope = scope;
}

public String getUrl() {
return url;
}

public String getChecks() {
return checks;
}

public ArachniScopeProperty getScope() {
return scope;
}
Expand Down Expand Up @@ -101,7 +109,18 @@ public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskLi
scannerScope = Scope.create().pageLimit(scope.getPageLimitAsInt())
.addExcludePathPatterns(scope.getExcludePathPattern()).build();
}
ScanRequest scanRequest = ScanRequest.create().url(url).scope(scannerScope).build();

ScanRequestBuilder requestBuilder = ScanRequest.create().url(url).scope(scannerScope);
if (StringUtils.isNotBlank(checks)) {
for (String check : checks.split(",")) {
requestBuilder.addCheck(check.trim());
}
} else {
requestBuilder.addCheck("*");
}

ScanRequest scanRequest = requestBuilder.build();

OutputStream outstream = null;
try {
scan = arachniClient.performScan(scanRequest);
Expand Down Expand Up @@ -150,7 +169,7 @@ public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskLi
}
}
}

protected void shutdownScan() throws IOException {
log.info("Shutdown scanner for id: {}", scan.getId());

Expand Down
Expand Up @@ -5,5 +5,9 @@
<f:textbox/>
</f:entry>

<f:entry title="${%Checks}" field="checks">
<f:textbox/>
</f:entry>

<f:optionalProperty title="${%Set scope}" field="scope"/>
</j:jelly>
@@ -0,0 +1,3 @@
<div>
Here you can specify a comma separated list with the checks to load. Or leave it blank to load all checks.
</div>
Expand Up @@ -48,7 +48,7 @@ public void setUp() throws Exception {
@Test
public void performScan() throws Exception {
FreeStyleProject project = jenkins.createFreeStyleProject();
project.getBuildersList().add(new ArachniScanner("http://test-site:9090", null));
project.getBuildersList().add(new ArachniScanner("http://test-site:9090", null, null));
ArachniPluginConfiguration config = new ArachniPluginConfiguration();
config.setArachniServerUrl("http://localhost:8877");

Expand Down

0 comments on commit 043e5c2

Please sign in to comment.