Skip to content

Commit 0a79d1e

Browse files
authored
Refresh plugin for August 2023 (Upgrade to a minimum core version 2.361.3 and minimum Java version 11) (#348)
* Refresh plugin for August 2023 * Remove usage of Mockito to allow test to pass on Java 17
1 parent 4bec5b5 commit 0a79d1e

File tree

3 files changed

+35
-76
lines changed

3 files changed

+35
-76
lines changed

Jenkinsfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
buildPlugin(configurations: [
2-
[platform: 'linux', jdk: 8],
3-
[platform: 'linux', jdk: 11],
4-
[platform: 'windows', jdk: 8],
1+
buildPlugin(useContainerAgent: true, configurations: [
2+
[platform: 'linux', jdk: 17],
3+
[platform: 'windows', jdk: 11],
54
])

pom.xml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<parent>
1919
<groupId>org.jenkins-ci.plugins</groupId>
2020
<artifactId>plugin</artifactId>
21-
<version>4.45</version>
21+
<version>4.72</version>
2222
<relativePath/>
2323
</parent>
2424

@@ -66,7 +66,7 @@
6666
<revision>0</revision>
6767
<changelist>999999-SNAPSHOT</changelist>
6868
<gitHubRepo>jenkinsci/google-kubernetes-engine-plugin</gitHubRepo>
69-
<jenkins.version>2.346.1</jenkins.version>
69+
<jenkins.version>2.361.4</jenkins.version>
7070
<google.guava.version>32.1.2-jre</google.guava.version>
7171
<google.api.version>1.25.0</google.api.version>
7272
<google.http.version>1.42.2</google.http.version>
@@ -78,10 +78,15 @@
7878

7979
<dependencyManagement>
8080
<dependencies>
81+
<dependency>
82+
<groupId>com.google.code.gson</groupId>
83+
<artifactId>gson</artifactId>
84+
<version>2.10.1</version>
85+
</dependency>
8186
<dependency>
8287
<groupId>io.jenkins.tools.bom</groupId>
83-
<artifactId>bom-2.346.x</artifactId>
84-
<version>1643.v1cffef51df73</version>
88+
<artifactId>bom-2.361.x</artifactId>
89+
<version>2102.v854b_fec19c92</version>
8590
<type>pom</type>
8691
<scope>import</scope>
8792
</dependency>
@@ -114,9 +119,8 @@
114119
<artifactId>apache-httpcomponents-client-4-api</artifactId>
115120
</dependency>
116121
<dependency>
117-
<groupId>com.fasterxml.jackson.core</groupId>
118-
<artifactId>jackson-core</artifactId>
119-
<version>2.13.3</version>
122+
<groupId>org.jenkins-ci.plugins</groupId>
123+
<artifactId>jackson2-api</artifactId>
120124
</dependency>
121125
<dependency>
122126
<groupId>org.jenkins-ci.plugins.workflow</groupId>

src/test/java/com/google/jenkins/plugins/k8sengine/CredentialsUtilTest.java

Lines changed: 21 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,52 @@
11
package com.google.jenkins.plugins.k8sengine;
22

3-
import static org.junit.Assert.assertEquals;
43
import static org.junit.Assert.assertNotNull;
5-
import static org.mockito.ArgumentMatchers.any;
64

75
import com.cloudbees.plugins.credentials.CredentialsStore;
6+
import com.cloudbees.plugins.credentials.SecretBytes;
87
import com.cloudbees.plugins.credentials.SystemCredentialsProvider;
98
import com.cloudbees.plugins.credentials.domains.Domain;
109
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
1110
import com.google.api.client.auth.oauth2.Credential;
1211
import com.google.common.collect.ImmutableList;
1312
import com.google.jenkins.plugins.credentials.oauth.GoogleRobotCredentials;
14-
import com.google.jenkins.plugins.k8sengine.client.ContainerScopeRequirement;
13+
import com.google.jenkins.plugins.credentials.oauth.GoogleRobotPrivateKeyCredentials;
14+
import com.google.jenkins.plugins.credentials.oauth.JsonServiceAccountConfig;
1515
import hudson.AbortException;
1616
import java.io.IOException;
17-
import java.security.GeneralSecurityException;
18-
import jenkins.model.Jenkins;
19-
import org.junit.BeforeClass;
17+
import java.nio.charset.StandardCharsets;
2018
import org.junit.ClassRule;
2119
import org.junit.Test;
22-
import org.junit.runner.RunWith;
2320
import org.jvnet.hudson.test.JenkinsRule;
24-
import org.mockito.Mockito;
25-
import org.mockito.junit.MockitoJUnitRunner;
2621

27-
@RunWith(MockitoJUnitRunner.class)
2822
public class CredentialsUtilTest {
2923
private static final String TEST_CREDENTIALS_ID = "test-credentials-id";
3024
private static final String TEST_INVALID_CREDENTIALS_ID = "test-invalid-credentials-id";
3125
private static final String TEST_ACCESS_TOKEN = "test-access-token";
3226
@ClassRule public static JenkinsRule r = new JenkinsRule();
33-
public static Jenkins jenkins;
34-
35-
@BeforeClass
36-
public static void init() throws IOException {
37-
jenkins = r.jenkins;
38-
39-
CredentialsStore store = new SystemCredentialsProvider.ProviderImpl().getStore(jenkins);
40-
GoogleRobotCredentials credentials = Mockito.mock(GoogleRobotCredentials.class);
41-
Mockito.when(credentials.getId()).thenReturn(TEST_CREDENTIALS_ID);
42-
store.addCredentials(Domain.global(), credentials);
43-
}
44-
45-
@Test
46-
public void testGetRobotCredentialsReturnsFirstCredential() throws IOException {
47-
assertNotNull(
48-
CredentialsUtil.getRobotCredentials(
49-
jenkins.get(), ImmutableList.<DomainRequirement>of(), TEST_CREDENTIALS_ID));
50-
}
5127

5228
@Test(expected = AbortException.class)
5329
public void testGetRobotCredentialsInvalidCredentialsIdAbortException() throws AbortException {
5430
CredentialsUtil.getRobotCredentials(
55-
jenkins.get(), ImmutableList.<DomainRequirement>of(), TEST_INVALID_CREDENTIALS_ID);
31+
r.jenkins, ImmutableList.<DomainRequirement>of(), TEST_INVALID_CREDENTIALS_ID);
5632
}
5733

58-
@Test(expected = AbortException.class)
59-
public void testGetGoogleCredentialAbortException()
60-
throws GeneralSecurityException, AbortException {
61-
GoogleRobotCredentials robotCreds = Mockito.mock(GoogleRobotCredentials.class);
62-
Mockito.when(robotCreds.getGoogleCredential(any(ContainerScopeRequirement.class)))
63-
.thenThrow(new GeneralSecurityException());
34+
@Test(expected = GoogleRobotPrivateKeyCredentials.PrivateKeyNotSetException.class)
35+
public void testGetGoogleCredentialAbortException() throws Exception {
36+
SecretBytes bytes =
37+
SecretBytes.fromBytes(
38+
"{\"client_email\": \"[email protected]\"}".getBytes(StandardCharsets.UTF_8));
39+
JsonServiceAccountConfig serviceAccountConfig = new JsonServiceAccountConfig();
40+
serviceAccountConfig.setSecretJsonKey(bytes);
41+
assertNotNull(serviceAccountConfig.getAccountId());
42+
GoogleRobotCredentials robotCreds =
43+
new GoogleRobotPrivateKeyCredentials(
44+
TEST_INVALID_CREDENTIALS_ID, serviceAccountConfig, null);
45+
CredentialsStore store = new SystemCredentialsProvider.ProviderImpl().getStore(r.jenkins);
46+
store.addCredentials(Domain.global(), robotCreds);
6447
CredentialsUtil.getGoogleCredential(robotCreds);
6548
}
6649

67-
@Test
68-
public void testGetGoogleCredentialReturnsCredential()
69-
throws GeneralSecurityException, AbortException {
70-
GoogleRobotCredentials robotCreds = Mockito.mock(GoogleRobotCredentials.class);
71-
Credential credential = Mockito.mock(Credential.class);
72-
Mockito.when(robotCreds.getGoogleCredential(any(ContainerScopeRequirement.class)))
73-
.thenReturn(credential);
74-
assertNotNull(CredentialsUtil.getGoogleCredential(robotCreds));
75-
}
76-
77-
@Test(expected = IOException.class)
78-
public void testGetAccessTokenIOException() throws IOException {
79-
Credential googleCredential = Mockito.mock(Credential.class);
80-
Mockito.when(googleCredential.refreshToken()).thenThrow(IOException.class);
81-
CredentialsUtil.getAccessToken(googleCredential);
82-
}
83-
84-
@Test
85-
public void testGetAccessTokenReturnsToken() throws IOException {
86-
Credential googleCredential = Mockito.mock(Credential.class);
87-
Mockito.when(googleCredential.refreshToken()).thenReturn(true);
88-
Mockito.when(googleCredential.getAccessToken()).thenReturn(TEST_ACCESS_TOKEN);
89-
String accessToken = CredentialsUtil.getAccessToken(googleCredential);
90-
assertNotNull(accessToken);
91-
assertEquals(TEST_ACCESS_TOKEN, accessToken);
92-
}
93-
9450
@Test(expected = NullPointerException.class)
9551
public void testGetRobotCredentialsWithEmptyItemGroup() throws AbortException {
9652
CredentialsUtil.getRobotCredentials(
@@ -99,17 +55,17 @@ public void testGetRobotCredentialsWithEmptyItemGroup() throws AbortException {
9955

10056
@Test(expected = NullPointerException.class)
10157
public void testGetRobotCredentialsWithEmptyDomainRequirements() throws AbortException {
102-
CredentialsUtil.getRobotCredentials(jenkins.get(), null, TEST_CREDENTIALS_ID);
58+
CredentialsUtil.getRobotCredentials(r.jenkins, null, TEST_CREDENTIALS_ID);
10359
}
10460

10561
@Test(expected = IllegalArgumentException.class)
10662
public void testGetRobotCredentialsWithNullCredentialsId() throws AbortException {
107-
CredentialsUtil.getRobotCredentials(jenkins.get(), ImmutableList.<DomainRequirement>of(), null);
63+
CredentialsUtil.getRobotCredentials(r.jenkins, ImmutableList.<DomainRequirement>of(), null);
10864
}
10965

11066
@Test(expected = IllegalArgumentException.class)
11167
public void testGetRobotCredentialsWithEmptyCredentialsId() throws AbortException {
112-
CredentialsUtil.getRobotCredentials(jenkins.get(), ImmutableList.<DomainRequirement>of(), "");
68+
CredentialsUtil.getRobotCredentials(r.jenkins, ImmutableList.<DomainRequirement>of(), "");
11369
}
11470

11571
@Test(expected = IllegalArgumentException.class)

0 commit comments

Comments
 (0)