Skip to content

Commit 798a361

Browse files
Merge pull request #37 from jenkinsci/security_fix_and-_test
Security fix and testcase
2 parents 6468515 + 30912d4 commit 798a361

File tree

8 files changed

+80
-296
lines changed

8 files changed

+80
-296
lines changed

src/main/java/io/jenkins/plugins/constant/Constant.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class Constant {
66
public static final String UNIQUE_FILE_NAME = "delphix-VDB-";
77
public static final String PROPERTIES = ".properties";
88
public static final String FILE_NAME = "delphix-VDB";
9-
public static final String USER_AGENT = "Jenkins-3.1.0";
9+
public static final String USER_AGENT = "Jenkins-3.1.1";
1010
public static final String CLIENT_NAME = "Jenkins";
1111
public static final String CLIENT_NAME_HEADER = "x-dct-client-name";
1212
public static final long WAIT_TIME = 20000;

src/main/java/io/jenkins/plugins/delphix/DelphixGlobalConfiguration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static DelphixGlobalConfiguration get() {
1313
}
1414

1515
private String dctUrl;
16-
private boolean sslCheck;
16+
private boolean disableSsl;
1717

1818
public DelphixGlobalConfiguration() {
1919
load();
@@ -29,13 +29,13 @@ public void setDctUrl(String dctUrl) {
2929
save();
3030
}
3131

32-
public boolean getSslCheck() {
33-
return sslCheck;
32+
public boolean getDisableSsl() {
33+
return disableSsl;
3434
}
3535

3636
@DataBoundSetter
37-
public void setSslCheck(boolean sslCertificate) {
38-
this.sslCheck = sslCertificate;
37+
public void setDisableSsl(boolean disableSsl) {
38+
this.disableSsl = disableSsl;
3939
save();
4040
}
4141
}

src/main/java/io/jenkins/plugins/util/DctSdkUtil.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ public DctSdkUtil(Run<?, ?> run, TaskListener listener, String credId) {
3838
return;
3939
}
4040
this.defaultClient = Configuration.getDefaultApiClient();
41-
if (DelphixGlobalConfiguration.get().getSslCheck()) {
42-
this.defaultClient.setVerifyingSsl(false);
43-
}
41+
this.defaultClient.setVerifyingSsl(!DelphixGlobalConfiguration.get().getDisableSsl());
4442
this.defaultClient.setConnectTimeout(Constant.TIMEOUT);
4543
this.defaultClient.setReadTimeout(Constant.TIMEOUT);
4644
this.defaultClient.setWriteTimeout(Constant.TIMEOUT);

src/main/resources/io/jenkins/plugins/delphix/DelphixGlobalConfiguration/config.jelly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<f:textbox />
66
</f:entry>
77

8-
<f:entry title="Disable SSL Certificate Validation" field="sslCheck" help="/plugin/delphix/help-sslCheck.html">
8+
<f:entry title="Disable SSL Certificate Validation" field="disableSsl" help="/plugin/delphix/help-sslCheck.html">
99
<f:checkbox default="false" />
1010
</f:entry>
1111
</f:section>

src/test/java/io/jenkins/plugins/delphix/DeleteVDBTest.java

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package io.jenkins.plugins.delphix;
2+
3+
import com.cloudbees.plugins.credentials.CredentialsProvider;
4+
import com.cloudbees.plugins.credentials.CredentialsScope;
5+
import com.cloudbees.plugins.credentials.domains.Domain;
6+
import hudson.model.FreeStyleBuild;
7+
import hudson.model.FreeStyleProject;
8+
import hudson.util.Secret;
9+
import hudson.model.Result;
10+
import jenkins.model.GlobalConfiguration;
11+
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
12+
import org.junit.Rule;
13+
import org.junit.Test;
14+
import org.jvnet.hudson.test.JenkinsRule;
15+
16+
public class GlobalConfigurationTest {
17+
18+
@Rule
19+
public JenkinsRule jenkins = new JenkinsRule();
20+
21+
@Test
22+
public void GlobalConfigSSLDisable() throws Exception {
23+
DelphixGlobalConfiguration globalConfig1 =
24+
GlobalConfiguration.all().get(DelphixGlobalConfiguration.class);
25+
globalConfig1.setDctUrl("https://self-signed.badssl.com");
26+
globalConfig1.setDisableSsl(true); //disable ssl
27+
globalConfig1.save();
28+
29+
StringCredentialsImpl c =
30+
new StringCredentialsImpl(CredentialsScope.USER, "test123", "description",
31+
Secret.fromString("api key"));
32+
CredentialsProvider.lookupStores(jenkins).iterator().next().addCredentials(Domain.global(), c);
33+
34+
FreeStyleProject project = jenkins.createFreeStyleProject();
35+
ProvisionVDBFromSnapshot builder = new ProvisionVDBFromSnapshot();
36+
builder.setSourceDataId("4-ORACLE_DB_CONTAINER-6");
37+
builder.setCredentialId("test123");
38+
builder.setAutoSelectRepository(true);
39+
project.getBuildersList().add(builder);
40+
41+
FreeStyleBuild b1 = project.scheduleBuild2(0).get();
42+
System.out.println(b1.toString());
43+
jenkins.assertLogContains("<head><title>404 Not Found</title></head>", b1);
44+
jenkins.assertBuildStatus(Result.FAILURE, b1);
45+
}
46+
47+
48+
@Test
49+
public void GlobalConfigDefault() throws Exception {
50+
DelphixGlobalConfiguration globalConfig1 =
51+
GlobalConfiguration.all().get(DelphixGlobalConfiguration.class);
52+
globalConfig1.setDctUrl("https://self-signed.badssl.com");
53+
globalConfig1.save();
54+
55+
StringCredentialsImpl c =
56+
new StringCredentialsImpl(CredentialsScope.USER, "test123", "description",
57+
Secret.fromString("api key"));
58+
CredentialsProvider.lookupStores(jenkins).iterator().next().addCredentials(Domain.global(), c);
59+
60+
FreeStyleProject project = jenkins.createFreeStyleProject();
61+
ProvisionVDBFromSnapshot builder = new ProvisionVDBFromSnapshot();
62+
builder.setSourceDataId("4-ORACLE_DB_CONTAINER-6");
63+
builder.setCredentialId("test123");
64+
builder.setAutoSelectRepository(true);
65+
project.getBuildersList().add(builder);
66+
67+
FreeStyleBuild b1 = project.scheduleBuild2(0).get();
68+
System.out.println(b1.toString());
69+
jenkins.assertLogContains("javax.net.ssl.SSLHandshakeException:", b1);
70+
jenkins.assertBuildStatus(Result.FAILURE, b1);
71+
}
72+
}

src/test/java/io/jenkins/plugins/delphix/ProvisionVDBFromBookmarkTest.java

Lines changed: 0 additions & 164 deletions
This file was deleted.

0 commit comments

Comments
 (0)