Skip to content

Commit b490075

Browse files
committed
Add test for round trip configuration with both old and new project.
1 parent a086092 commit b490075

File tree

4 files changed

+121
-3
lines changed

4 files changed

+121
-3
lines changed

src/main/java/com/amazonaws/codedeploy/AWSClients.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import com.amazonaws.AmazonServiceException;
2727
import com.amazonaws.ClientConfiguration;
28+
import com.amazonaws.SdkClientException;
2829
import com.amazonaws.auth.AWSCredentials;
2930
import com.amazonaws.auth.BasicAWSCredentials;
3031
import com.amazonaws.auth.BasicSessionCredentials;
@@ -115,6 +116,8 @@ public static String getAccountId(String proxyHost, int proxyPort) {
115116
arn = msg.substring(arnIdx, arnSpace);
116117
}
117118
}
119+
} catch (RuntimeException e) {
120+
return "";
118121
}
119122

120123
String accountId = arn.split(":")[ARN_ACCOUNT_ID_INDEX];

src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ public AWSCodeDeployPublisher(
134134
int proxyPort,
135135
String excludes,
136136
String subdirectory) {
137-
138137
this.externalId = externalId;
139138
this.applicationName = applicationName;
140139
this.deploymentGroupName = deploymentGroupName;
@@ -671,8 +670,8 @@ public String getAwsAccessKey() {
671670
return awsAccessKey;
672671
}
673672

674-
public String getAwsSecretKey() {
675-
return Secret.toString(awsSecretKey);
673+
public Secret getAwsSecretKey() {
674+
return awsSecretKey;
676675
}
677676

678677
public Long getPollingFreqSec() {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.amazonaws.codedeploy;
2+
3+
import hudson.model.FreeStyleProject;
4+
import org.junit.Rule;
5+
import org.junit.Test;
6+
import org.jvnet.hudson.test.JenkinsRule;
7+
import org.jvnet.hudson.test.recipes.LocalData;
8+
9+
import static org.hamcrest.Matchers.containsString;
10+
import static org.hamcrest.Matchers.not;
11+
import static org.junit.Assert.assertThat;
12+
13+
public class AWSCodeDeployPublisherTest {
14+
@Rule
15+
public JenkinsRule j = new JenkinsRule();
16+
17+
@Test
18+
public void testRoundTripConfiguration() throws Exception {
19+
final AWSCodeDeployPublisher publisher = new AWSCodeDeployPublisher(
20+
"testBucket",
21+
"testPrefix",
22+
"testApplicationName",
23+
"testDeploymentGroupName",
24+
"testDeploymentConfig",
25+
"us-west-2",
26+
false,
27+
true,
28+
60L,
29+
10L,
30+
"awsAccessKey",
31+
"",
32+
"deploy",
33+
"testAccessKey",
34+
"testSecretKey",
35+
"",
36+
null,
37+
"",
38+
"",
39+
0,
40+
"",
41+
"");
42+
43+
final AWSCodeDeployPublisher afterPublisher = j.configRoundtrip(publisher);
44+
j.assertEqualDataBoundBeans(publisher, afterPublisher);
45+
}
46+
47+
@Test
48+
@LocalData
49+
public void testSaveUsesSecret() throws Exception {
50+
FreeStyleProject project = (FreeStyleProject) j.jenkins.getItem("testSecrets");
51+
FreeStyleProject after = j.configRoundtrip(project);
52+
assertThat(after.getConfigFile().asString(), not(containsString("TEST_SECRET")));
53+
}
54+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<project>
3+
<actions/>
4+
<description></description>
5+
<keepDependencies>false</keepDependencies>
6+
<properties/>
7+
<scm class="hudson.plugins.git.GitSCM" plugin="git@3.8.0">
8+
<configVersion>2</configVersion>
9+
<userRemoteConfigs>
10+
<hudson.plugins.git.UserRemoteConfig>
11+
<url>https://github.com/awslabs/aws-codedeploy-plugin.git</url>
12+
</hudson.plugins.git.UserRemoteConfig>
13+
</userRemoteConfigs>
14+
<branches>
15+
<hudson.plugins.git.BranchSpec>
16+
<name>*/master</name>
17+
</hudson.plugins.git.BranchSpec>
18+
</branches>
19+
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
20+
<submoduleCfg class="list"/>
21+
<extensions/>
22+
</scm>
23+
<canRoam>true</canRoam>
24+
<disabled>false</disabled>
25+
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
26+
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
27+
<triggers/>
28+
<concurrentBuild>false</concurrentBuild>
29+
<builders>
30+
<hudson.tasks.Maven>
31+
<targets>package</targets>
32+
<mavenName>(Default)</mavenName>
33+
<usePrivateRepository>false</usePrivateRepository>
34+
<settings class="jenkins.mvn.DefaultSettingsProvider"/>
35+
<globalSettings class="jenkins.mvn.DefaultGlobalSettingsProvider"/>
36+
<injectBuildVariables>false</injectBuildVariables>
37+
</hudson.tasks.Maven>
38+
</builders>
39+
<publishers>
40+
<com.amazonaws.codedeploy.AWSCodeDeployPublisher plugin="codedeploy@1.20-SNAPSHOT">
41+
<s3bucket>test_bucket</s3bucket>
42+
<s3prefix></s3prefix>
43+
<applicationName>TestApplication</applicationName>
44+
<deploymentGroupName>TestDeploymentGorup</deploymentGroupName>
45+
<deploymentGroupAppspec>false</deploymentGroupAppspec>
46+
<waitForCompletion>false</waitForCompletion>
47+
<iamRoleArn></iamRoleArn>
48+
<region>us-west-2</region>
49+
<includes>**</includes>
50+
<excludes></excludes>
51+
<subdirectory></subdirectory>
52+
<proxyHost></proxyHost>
53+
<proxyPort>0</proxyPort>
54+
<awsAccessKey>TEST_ACCESS</awsAccessKey>
55+
<awsSecretKey>TEST_SECRET</awsSecretKey>
56+
<credentials>awsAccessKey</credentials>
57+
<deploymentMethod>deploy</deploymentMethod>
58+
<versionFileName></versionFileName>
59+
</com.amazonaws.codedeploy.AWSCodeDeployPublisher>
60+
</publishers>
61+
<buildWrappers/>
62+
</project>

0 commit comments

Comments
 (0)