-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refresh plugin for August 2023 (Upgrade to a minimum core version 2.3…
…87.3 and minimum Java version 11) (#403) * Refresh plugin for June 2023 * Fix merge * More updates * More updates * Remove usages of Mockito in integration tests to allow the test to run on Java 17 * Test on Java 17
- Loading branch information
Showing
7 changed files
with
52 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
buildPlugin(configurations: [ | ||
[ platform: 'linux', jdk: '8', jenkins: null ], | ||
[ platform: 'linux', jdk: '11', jenkins: null ], | ||
[ platform: 'windows', jdk: '8', jenkins: null ], | ||
buildPlugin(useContainerAgent: true, configurations: [ | ||
[platform: 'linux', jdk: 17], | ||
[platform: 'windows', jdk: 11], | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,58 +20,32 @@ | |
import static org.hamcrest.Matchers.not; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
import com.cloudbees.plugins.credentials.Credentials; | ||
import com.cloudbees.plugins.credentials.CredentialsStore; | ||
import com.cloudbees.plugins.credentials.SecretBytes; | ||
import com.cloudbees.plugins.credentials.SystemCredentialsProvider; | ||
import com.cloudbees.plugins.credentials.domains.Domain; | ||
import com.google.common.collect.Lists; | ||
import com.google.jenkins.plugins.credentials.oauth.GoogleRobotPrivateKeyCredentials; | ||
import com.google.jenkins.plugins.credentials.oauth.ServiceAccountConfig; | ||
import com.google.jenkins.plugins.credentials.oauth.JsonServiceAccountConfig; | ||
import hudson.model.Label; | ||
import hudson.model.labels.LabelAtom; | ||
import hudson.util.FormValidation; | ||
import hudson.util.ListBoxModel; | ||
import java.security.PrivateKey; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ComputeEngineCloudTest { | ||
private static final PrivateKey PRIVATE_KEY; | ||
private static final String ACCOUNT_ID = "test-account-id"; | ||
private static final String PK_ALGO = "test"; | ||
private static final String PK_FORMAT = "test"; | ||
private static final byte[] PK_BYTES = new byte[0]; | ||
|
||
static { | ||
PRIVATE_KEY = | ||
new PrivateKey() { | ||
@Override | ||
public String getAlgorithm() { | ||
return PK_ALGO; | ||
} | ||
|
||
@Override | ||
public String getFormat() { | ||
return PK_FORMAT; | ||
} | ||
|
||
@Override | ||
public byte[] getEncoded() { | ||
return PK_BYTES; | ||
} | ||
}; | ||
} | ||
private static final byte[] PK_BYTES = | ||
"{\"client_email\": \"[email protected]\"}".getBytes(StandardCharsets.UTF_8); | ||
|
||
private static final String INSTANCE_ID = "213123"; | ||
private static final String CLOUD_NAME = "test-cloud"; | ||
|
@@ -80,16 +54,12 @@ public byte[] getEncoded() { | |
|
||
@Rule public JenkinsRule r = new JenkinsRule(); | ||
|
||
@Mock public ServiceAccountConfig serviceAccountConfig; | ||
|
||
@Before | ||
public void init() { | ||
Mockito.when(serviceAccountConfig.getAccountId()).thenReturn(ACCOUNT_ID); | ||
Mockito.when(serviceAccountConfig.getPrivateKey()).thenReturn(PRIVATE_KEY); | ||
} | ||
|
||
@Test | ||
public void construction() throws Exception { | ||
SecretBytes bytes = SecretBytes.fromBytes(PK_BYTES); | ||
JsonServiceAccountConfig serviceAccountConfig = new JsonServiceAccountConfig(); | ||
serviceAccountConfig.setSecretJsonKey(bytes); | ||
assertNotNull(serviceAccountConfig.getAccountId()); | ||
// Create a credential | ||
Credentials c = | ||
(Credentials) new GoogleRobotPrivateKeyCredentials(ACCOUNT_ID, serviceAccountConfig, null); | ||
|
@@ -112,8 +82,9 @@ public void construction() throws Exception { | |
assertEquals(CLOUD_NAME, cloud.getDisplayName()); | ||
Assert.assertNotEquals(CLOUD_NAME, cloud.name); | ||
|
||
// Ensure ComputeClient is created | ||
assertNotNull("ComputeClient was not initialized", cloud.getClient()); | ||
// Ensure correct exception is thrown | ||
assertThrows( | ||
GoogleRobotPrivateKeyCredentials.PrivateKeyNotSetException.class, cloud::getClient); | ||
|
||
// Ensure transient properties were initialized | ||
for (InstanceConfiguration ic : ics) { | ||
|
@@ -175,6 +146,10 @@ public void getConfigurationsByLabelMulti() throws Exception { | |
@Test | ||
public void descriptorFillCredentials() throws Exception { | ||
// Create a credential | ||
SecretBytes bytes = SecretBytes.fromBytes(PK_BYTES); | ||
JsonServiceAccountConfig serviceAccountConfig = new JsonServiceAccountConfig(); | ||
serviceAccountConfig.setSecretJsonKey(bytes); | ||
assertNotNull(serviceAccountConfig.getAccountId()); | ||
Credentials c = | ||
(Credentials) new GoogleRobotPrivateKeyCredentials(ACCOUNT_ID, serviceAccountConfig, null); | ||
CredentialsStore store = new SystemCredentialsProvider.ProviderImpl().getStore(r.jenkins); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,23 +2,28 @@ | |
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
import com.cloudbees.plugins.credentials.Credentials; | ||
import com.cloudbees.plugins.credentials.CredentialsStore; | ||
import com.cloudbees.plugins.credentials.SecretBytes; | ||
import com.cloudbees.plugins.credentials.SystemCredentialsProvider; | ||
import com.cloudbees.plugins.credentials.domains.Domain; | ||
import com.google.api.client.auth.oauth2.Credential; | ||
import com.google.jenkins.plugins.credentials.oauth.GoogleRobotCredentials; | ||
import com.google.jenkins.plugins.credentials.oauth.GoogleRobotPrivateKeyCredentials; | ||
import com.google.jenkins.plugins.credentials.oauth.JsonServiceAccountConfig; | ||
import hudson.model.Node; | ||
import io.jenkins.plugins.casc.misc.ConfiguredWithCode; | ||
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule; | ||
import java.nio.charset.StandardCharsets; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.mockito.Mockito; | ||
|
||
public class ConfigAsCodeTest { | ||
|
||
private static final byte[] PK_BYTES = | ||
"{\"client_email\": \"[email protected]\"}".getBytes(StandardCharsets.UTF_8); | ||
|
||
@Rule public JenkinsRule jenkinsRule = new JenkinsConfiguredWithCodeRule(); | ||
|
||
@Test | ||
|
@@ -59,9 +64,12 @@ public void shouldCreateCloudInstanceFromCode() { | |
@Test | ||
@ConfiguredWithCode("configuration-as-code.yml") | ||
public void shouldCreateGCEClientFromCode() throws Exception { | ||
GoogleRobotCredentials credentials = Mockito.mock(GoogleRobotCredentials.class); | ||
Mockito.when(credentials.getId()).thenReturn("gce-jenkins"); | ||
Mockito.when(credentials.getGoogleCredential(any())).thenReturn(Mockito.mock(Credential.class)); | ||
SecretBytes bytes = SecretBytes.fromBytes(PK_BYTES); | ||
JsonServiceAccountConfig serviceAccountConfig = new JsonServiceAccountConfig(); | ||
serviceAccountConfig.setSecretJsonKey(bytes); | ||
assertNotNull(serviceAccountConfig.getAccountId()); | ||
Credentials credentials = | ||
new GoogleRobotPrivateKeyCredentials("gce-jenkins", serviceAccountConfig, null); | ||
|
||
CredentialsStore store = | ||
new SystemCredentialsProvider.ProviderImpl().getStore(jenkinsRule.jenkins); | ||
|
@@ -70,6 +78,8 @@ public void shouldCreateGCEClientFromCode() throws Exception { | |
ComputeEngineCloud cloud = | ||
(ComputeEngineCloud) jenkinsRule.jenkins.clouds.getByName("gce-jenkins-build"); | ||
assertNotNull("Cloud by name not found", cloud); | ||
assertNotNull("GCE client not created", cloud.getClient()); | ||
// Ensure correct exception is thrown | ||
assertThrows( | ||
GoogleRobotPrivateKeyCredentials.PrivateKeyNotSetException.class, cloud::getClient); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters