Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,20 @@
package com.cloudbees.jenkins.plugins.bitbucket.client.repository;

import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketWebHook;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.ObjectUtils;

public class BitbucketCloudWebhook implements BitbucketWebHook {

private String uuid;

private String description;

private String url;

private String secret;

private boolean active;

@JsonProperty("skip_cert_verification")
private boolean skipCertVerification;
private List<String> events = new ArrayList<>();

@Override
Expand Down Expand Up @@ -96,4 +94,12 @@ public void setSecret(String secret) {
this.secret = secret;
}

public boolean isSkipCertVerification() {
return skipCertVerification;
}

public void setSkipCertVerification(boolean skipCertVerification) {
this.skipCertVerification = skipCertVerification;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public abstract class AbstractBitbucketWebhookConfiguration implements Bitbucket
*/
private String endpointJenkinsRootURL;

/**
* Allow send webhook to untrusted or self-signed certificates Jenkins host.
*/
private boolean skipCertVerification = false;

private boolean enableCache = false;

/**
Expand Down Expand Up @@ -170,6 +175,15 @@ public void setWebhooksCacheDuration(Integer webhooksCacheDuration) {
this.webhooksCacheDuration = webhooksCacheDuration == null || webhooksCacheDuration < 0 ? Integer.valueOf(180) : webhooksCacheDuration;
}

public boolean isSkipCertVerification() {
return skipCertVerification;
}

@DataBoundSetter
public void setSkipCertVerification(boolean skipCertVerification) {
this.skipCertVerification = skipCertVerification;
}

public abstract static class AbstractBitbucketWebhookDescriptorImpl extends BitbucketWebhookDescriptor {
protected abstract void clearCaches();
protected abstract List<String> getStats();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
hook.setActive(true);
hook.setDescription("Jenkins hook");
hook.setUrl(callbackURL);
hook.setSkipCertVerification(configuration.isSkipCertVerification());
if (configuration.isEnableHookSignature()) {
String signatureCredentialsId = configuration.getHookSignatureCredentialsId();
StringCredentials signatureSecret = BitbucketCredentialsUtils.lookupCredentials(Jenkins.get(), BitbucketCloudEndpoint.SERVER_URL, signatureCredentialsId, StringCredentials.class);
Expand Down Expand Up @@ -203,6 +204,12 @@
update = true;
}

if (current.isSkipCertVerification() != expected.isSkipCertVerification()) {
current.setSkipCertVerification(expected.isSkipCertVerification());
logger.info(() -> "Update skipCertVerification to " + expected.isSkipCertVerification());
update = true;

Check warning on line 210 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/webhook/cloud/CloudWebhookManager.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 207-210 are not covered by tests
}

List<String> events = current.getEvents();
List<String> expectedEvents = expected.getEvents();
if (!events.containsAll(expectedEvents)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
hook.setDescription("Jenkins hook");
hook.setEvents(NATIVE_SERVER_EVENTS);
hook.setUrl(callbackURL);
hook.setSslVerificationRequired(!configuration.isSkipCertVerification());

Check warning on line 171 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/webhook/server/ServerWebhookManager.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 171 is only partially covered, one branch is missing
if (configuration.isEnableHookSignature()) {
String signatureCredentialsId = configuration.getHookSignatureCredentialsId();
StringCredentials signatureSecret = BitbucketCredentialsUtils.lookupCredentials(Jenkins.get(), serverURL, signatureCredentialsId, StringCredentials.class);
Expand Down Expand Up @@ -202,6 +203,12 @@
update = true;
}

if (current.isSslVerificationRequired() != expected.isSslVerificationRequired()) {

Check warning on line 206 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/webhook/server/ServerWebhookManager.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 206 is only partially covered, one branch is missing
current.setSslVerificationRequired(expected.isSslVerificationRequired());
logger.info(() -> "Update webhook sslVerificationRequired " + expected.isSslVerificationRequired());
update = true;

Check warning on line 209 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/webhook/server/ServerWebhookManager.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 207-209 are not covered by tests
}

List<String> events = current.getEvents();
List<String> expectedEvents = expected.getEvents();
if (!events.containsAll(expectedEvents)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class BitbucketServerWebhook implements BitbucketWebHook {
private String url;
private List<String> events = new ArrayList<>();
private boolean active;
private boolean sslVerificationRequired = true;
@JsonProperty("configuration")
private Map<String, String> configuration = new HashMap<>();

Expand Down Expand Up @@ -97,4 +98,12 @@ public void setSecret(String secret) {
configuration.put("secret", secret);
}

public boolean isSslVerificationRequired() {
return sslVerificationRequired;
}

public void setSslVerificationRequired(boolean sslVerificationRequired) {
this.sslVerificationRequired = sslVerificationRequired;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ THE SOFTWARE.
</f:entry>
</f:optionalBlock>

<f:entry title="${%Skip certificate verification}" field="skipCertVerification">
<f:checkbox default="false" />
</f:entry>

<f:optionalBlock title="${%Enable cache}" field="enableCache" inline="true">
<f:entry title="${%How long to cache webhook requests, in minutes}" field="webhooksCacheDuration">
<f:number default="180" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div>
<p>
If you're using a self-signed certificate and want to disable certificate verification, select Skip certificate
verification.
</p>
<p>
<b>Note</b> We recommend that you don't disable certificate verification because self-signed certificates are
inherently not secure. Read the next section for more information about why you would or wouldn't use
self-signed
certificates.
</p>
</div>
Loading