Skip to content

Commit cf07975

Browse files
authored
Merge pull request #55 from jmdesprez/JENKINS-73610
2 parents 71b1a82 + 3266d62 commit cf07975

8 files changed

+46
-6
lines changed

src/main/java/org/jenkinsci/plugins/kubernetes/credentials/Utils.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ public static String encodeKey(Key key) {
6666
* @throws IllegalArgumentException If the request is invalid
6767
*/
6868
public static void ensureFIPSCompliantURIRequest(URI uri, boolean skipTLSVerify) {
69-
boolean isInsecure = uri.getScheme().equals("http");
69+
boolean isInsecure = false;
70+
if (uri != null) {
71+
isInsecure = "http".equals(uri.getScheme());
72+
}
7073
ensureFIPSCompliant(isInsecure, skipTLSVerify);
7174
}
7275

@@ -82,7 +85,10 @@ public static void ensureFIPSCompliantURIRequest(URI uri, boolean skipTLSVerify)
8285
* @throws IllegalArgumentException If the request is invalid
8386
*/
8487
public static void ensureFIPSCompliantRequest(String stringRequest, boolean skipTLSVerify) {
85-
boolean isInsecure = stringRequest.startsWith("http://");
88+
boolean isInsecure = false;
89+
if(stringRequest != null) {
90+
isInsecure = stringRequest.startsWith("http://");
91+
}
8692
ensureFIPSCompliant(isInsecure, skipTLSVerify);
8793
}
8894

src/test/java/org/jenkinsci/plugins/kubernetes/credentials/AbstractHttpClientWithTLSOptionsFactoryFIPSTest.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ public AbstractHttpClientWithTLSOptionsFactoryFIPSTest(String scheme, boolean sk
2525
@Test
2626
public void testCreateKubernetesAuthConfig() throws URISyntaxException {
2727
try {
28-
HttpClientWithTLSOptionsFactory.getBuilder(new URI(scheme, "localhost", null, null), null, skipTLSVerify);
28+
URI uri;
29+
if (scheme != null) {
30+
uri = new URI(scheme, "localhost", null, null);
31+
} else {
32+
uri = null;
33+
}
34+
HttpClientWithTLSOptionsFactory.getBuilder(uri, null, skipTLSVerify);
2935
if (!shouldPass) {
3036
fail("This test was expected to fail, reason: " + motivation);
3137
}

src/test/java/org/jenkinsci/plugins/kubernetes/credentials/AbstractOpenShiftBearerTokenCredentialFIPSTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jenkinsci.plugins.kubernetes.credentials;
22

33
import com.cloudbees.plugins.credentials.CredentialsScope;
4+
import edu.umd.cs.findbugs.annotations.NonNull;
45
import org.eclipse.jetty.server.Connector;
56
import org.eclipse.jetty.server.HttpConfiguration;
67
import org.eclipse.jetty.server.HttpConnectionFactory;
@@ -56,7 +57,7 @@ public abstract class AbstractOpenShiftBearerTokenCredentialFIPSTest {
5657

5758

5859
public AbstractOpenShiftBearerTokenCredentialFIPSTest(
59-
String scheme, boolean skipTLSVerify, boolean shouldPass, String motivation) {
60+
@NonNull String scheme, boolean skipTLSVerify, boolean shouldPass, String motivation) {
6061
this.scheme = scheme;
6162
this.skipTLSVerify = skipTLSVerify;
6263
this.shouldPass = shouldPass;

src/test/java/org/jenkinsci/plugins/kubernetes/credentials/AbstractUtilsFIPSTest.java

+25-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,32 @@ public AbstractUtilsFIPSTest(
2727

2828
@Test
2929
public void ensureFIPSCompliantURIRequest() throws URISyntaxException {
30-
HttpUriRequest request = new HttpGet(new URI(scheme, "localhost", null, null));
3130
try {
32-
Utils.ensureFIPSCompliantURIRequest(request.getURI(), skipTLSVerify);
31+
if(scheme != null) {
32+
HttpUriRequest request = new HttpGet(new URI(scheme, "localhost", null, null));
33+
URI uri = request.getURI();
34+
Utils.ensureFIPSCompliantURIRequest(uri, skipTLSVerify);
35+
} else {
36+
Utils.ensureFIPSCompliantURIRequest(null, skipTLSVerify);
37+
}
38+
if (!shouldPass) {
39+
fail("This test was expected to fail, reason: " + motivation);
40+
}
41+
} catch (IllegalArgumentException e) {
42+
if (shouldPass) {
43+
fail("This test was expected to pass, reason: " + motivation);
44+
}
45+
}
46+
}
47+
48+
@Test
49+
public void ensureFIPSCompliantRequest() {
50+
try {
51+
if(scheme != null) {
52+
Utils.ensureFIPSCompliantRequest(scheme + "://localhost", skipTLSVerify);
53+
} else {
54+
Utils.ensureFIPSCompliantRequest(null, skipTLSVerify);
55+
}
3356
if (!shouldPass) {
3457
fail("This test was expected to fail, reason: " + motivation);
3558
}

src/test/java/org/jenkinsci/plugins/kubernetes/credentials/HttpClientWithTLSOptionsFactoryWithFIPSTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public HttpClientWithTLSOptionsFactoryWithFIPSTest(
2323
public static Collection<Object[]> parameters() {
2424
return Arrays.asList(new Object[][] {
2525
// Valid use cases
26+
{null, false, true, "No URL provided and the TLS verification is not skipped, this should be accepted"},
2627
{"https", false, true, "TLS is used and the TLS verification is not skipped, this should be accepted"},
2728
// Invalid use cases
2829
{"https", true, false, "Skip TLS check is not accepted in FIPS mode"},

src/test/java/org/jenkinsci/plugins/kubernetes/credentials/HttpClientWithTLSOptionsFactoryWithoutFIPSTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public HttpClientWithTLSOptionsFactoryWithoutFIPSTest(
2323
public static Collection<Object[]> parameters() {
2424
return Arrays.asList(new Object[][] {
2525
// Valid use cases
26+
{null, false, true, "Not in FIPS mode, any combination should be valid"},
2627
{"https", false, true, "Not in FIPS mode, any combination should be valid"},
2728
{"http", false, true, "Not in FIPS mode, any combination should be valid"},
2829
{"http", true, true, "Not in FIPS mode, any combination should be valid"},

src/test/java/org/jenkinsci/plugins/kubernetes/credentials/UtilsWithFIPSTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public UtilsWithFIPSTest(
2222
public static Collection<Object[]> parameters() {
2323
return Arrays.asList(new Object[][] {
2424
// Valid use cases
25+
{null, false, true, "No URL provided and the TLS verification is not skipped, this should be accepted"},
2526
{"https", false, true, "TLS is used and the TLS verification is not skipped, this should be accepted"},
2627
// Invalid use cases
2728
{"https", true, false, "Skip TLS check is not accepted in FIPS mode"},

src/test/java/org/jenkinsci/plugins/kubernetes/credentials/UtilsWithoutFIPSTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public UtilsWithoutFIPSTest(String scheme, boolean skipTLSVerify, boolean should
2020
@Parameterized.Parameters
2121
public static Collection<Object[]> parameters() {
2222
return Arrays.asList(new Object[][] {
23+
{null, true, true, "Not in FIPS mode, any combination should be valid"},
2324
{"https", true, true, "Not in FIPS mode, any combination should be valid"},
2425
{"https", false, true, "Not in FIPS mode, any combination should be valid"},
2526
{"http", true, true, "Not in FIPS mode, any combination should be valid"},

0 commit comments

Comments
 (0)