-
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.
Merge pull request #417 from aneveux/google-credential-tests
Adapt tests to updated version of google-oauth-plugin
- Loading branch information
Showing
4 changed files
with
23 additions
and
29 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
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 |
---|---|---|
|
@@ -4,26 +4,16 @@ | |
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.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; | ||
|
||
public class ConfigAsCodeTest { | ||
|
||
private static final byte[] PK_BYTES = | ||
"{\"client_email\": \"[email protected]\"}".getBytes(StandardCharsets.UTF_8); | ||
|
||
@Rule public JenkinsRule jenkinsRule = new JenkinsConfiguredWithCodeRule(); | ||
|
||
@Test | ||
|
@@ -64,16 +54,6 @@ public void shouldCreateCloudInstanceFromCode() { | |
@Test | ||
@ConfiguredWithCode("configuration-as-code.yml") | ||
public void shouldCreateGCEClientFromCode() throws Exception { | ||
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); | ||
store.addCredentials(Domain.global(), credentials); | ||
|
||
ComputeEngineCloud cloud = | ||
(ComputeEngineCloud) jenkinsRule.jenkins.clouds.getByName("gce-jenkins-build"); | ||
|
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 |
---|---|---|
|
@@ -40,3 +40,14 @@ jenkins: | |
bootDiskSizeGbStr: 50 | ||
bootDiskAutoDelete: true | ||
serviceAccountEmail: '[email protected]' | ||
credentials: | ||
system: | ||
domainCredentials: | ||
- credentials: | ||
- googleRobotPrivateKeyCredentials: | ||
id: gce-jenkins | ||
projectId: gce-jenkins | ||
serviceAccountConfig: | ||
jsonServiceAccountConfig: | ||
# The encoded version of {"client_email": "[email protected]"} | ||
secretJsonKey: 'eyJjbGllbnRfZW1haWwiOiAiZXhhbXBsZUBleGFtcGxlLmNvbSJ9' |