Skip to content

Commit

Permalink
Merge pull request #211 from jtnord/fix-code-style
Browse files Browse the repository at this point in the history
fix code style
  • Loading branch information
jtnord authored Dec 13, 2023
2 parents 7b940aa + 28f9dcf commit aa17c83
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public GoogleRobotMetadataCredentials(
* id.
*
* @param scope The scope of the credentials, determining where they can be used in Jenkins. Can
* be either GLOBAL or SYSTEM.
* be either GLOBAL or SYSTEM.
* @param id the id to assign
* @param projectId The Pantheon project id associated with this service account
* @param description The credential description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public GoogleRobotPrivateKeyCredentials(
* id.
*
* @param scope The scope of the credentials, determining where they can be used in Jenkins. Can
* be either GLOBAL or SYSTEM.
* be either GLOBAL or SYSTEM.
* @param id the id to assign
* @param projectId The project id associated with this service account
* @param description The credential description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,19 +317,20 @@ public void testProjectIdValidation() throws Exception {
assertEquals(FormValidation.Kind.ERROR, descriptor.doCheckProjectId(null).kind);
assertEquals(FormValidation.Kind.ERROR, descriptor.doCheckProjectId("").kind);
}

@Test
public void testCredentialCreationWithNonEmptyIdAndDescription() throws Exception {
final Module module = new Module();

// WHEN: creating credential with defined id and description
GoogleRobotMetadataCredentials credentials =
new GoogleRobotMetadataCredentials(CredentialsScope.SYSTEM, CREDENTIAL_ID, PROJECT_ID, DESCRIPTION, module);
new GoogleRobotMetadataCredentials(
CredentialsScope.SYSTEM, CREDENTIAL_ID, PROJECT_ID, DESCRIPTION, module);

module.stubRequest(
"http://metadata/computeMetadata/v1/instance/" + "service-accounts/default/email",
STATUS_CODE_OK,
USERNAME);
"http://metadata/computeMetadata/v1/instance/" + "service-accounts/default/email",
STATUS_CODE_OK,
USERNAME);

// THEN: resulting credential should have our defined id and description
assertEquals(CREDENTIAL_ID, credentials.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ private void verifyRequest(String url) throws IOException {
@Test
public void testCreatePrivateKeyCredentialsWithNullKeyType() throws Exception {
GoogleRobotPrivateKeyCredentials credentials =
new GoogleRobotPrivateKeyCredentials(CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, module);
new GoogleRobotPrivateKeyCredentials(
CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, module);

try {
credentials.getUsername();
Expand All @@ -207,7 +208,8 @@ public void testCreatePrivateKeyCredentialsWithNullKeyType() throws Exception {
@Test
public void testUpgradeLegacyCredentials() throws Exception {
GoogleRobotPrivateKeyCredentials legacyCredentials =
new GoogleRobotPrivateKeyCredentials(CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, null);
new GoogleRobotPrivateKeyCredentials(
CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, null);
setPrivateField(legacyCredentials, "secretsFile", legacyJsonKeyPath);
setPrivateField(legacyCredentials, "p12File", p12KeyPath);
GoogleRobotPrivateKeyCredentials upgradedCredentials =
Expand All @@ -222,7 +224,8 @@ public void testUpgradeLegacyCredentials() throws Exception {
@Test
public void testUpgradeLegacyCredentialsWithoutSecretsFile() throws Exception {
GoogleRobotPrivateKeyCredentials legacyCredentials =
new GoogleRobotPrivateKeyCredentials(CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, null);
new GoogleRobotPrivateKeyCredentials(
CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, null);
setPrivateField(legacyCredentials, "p12File", p12KeyPath);
GoogleRobotPrivateKeyCredentials upgradedCredentials =
(GoogleRobotPrivateKeyCredentials) legacyCredentials.readResolve();
Expand All @@ -244,7 +247,8 @@ public void testUpgradeLegacyCredentialsWithMissingWebObject() throws Exception
String legacyJsonKeyFileWithMissingWebObject =
LegacyJsonServiceAccountConfigUtil.createTempLegacyJsonKeyFileWithMissingWebObject();
GoogleRobotPrivateKeyCredentials legacyCredentials =
new GoogleRobotPrivateKeyCredentials(CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, null);
new GoogleRobotPrivateKeyCredentials(
CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, null);
setPrivateField(legacyCredentials, "secretsFile", legacyJsonKeyFileWithMissingWebObject);
setPrivateField(legacyCredentials, "p12File", p12KeyPath);
GoogleRobotPrivateKeyCredentials upgradedCredentials =
Expand All @@ -267,7 +271,8 @@ public void testUpgradeLegacyCredentialsWithMissingClientEmail() throws Exceptio
String legacyJsonKeyFileWithMissingClientEmail =
LegacyJsonServiceAccountConfigUtil.createTempLegacyJsonKeyFileWithMissingClientEmail();
GoogleRobotPrivateKeyCredentials legacyCredentials =
new GoogleRobotPrivateKeyCredentials(CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, null);
new GoogleRobotPrivateKeyCredentials(
CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, null);
setPrivateField(legacyCredentials, "secretsFile", legacyJsonKeyFileWithMissingClientEmail);
setPrivateField(legacyCredentials, "p12File", p12KeyPath);
GoogleRobotPrivateKeyCredentials upgradedCredentials =
Expand All @@ -290,7 +295,8 @@ public void testUpgradeLegacyCredentialsWithInvalidSecretsFile() throws Exceptio
String invalidLegacyJsonKeyFile =
LegacyJsonServiceAccountConfigUtil.createTempInvalidLegacyJsonKeyFile();
GoogleRobotPrivateKeyCredentials legacyCredentials =
new GoogleRobotPrivateKeyCredentials(CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, null);
new GoogleRobotPrivateKeyCredentials(
CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, null);
setPrivateField(legacyCredentials, "secretsFile", invalidLegacyJsonKeyFile);
setPrivateField(legacyCredentials, "p12File", p12KeyPath);
GoogleRobotPrivateKeyCredentials upgradedCredentials =
Expand All @@ -311,7 +317,8 @@ public void testUpgradeLegacyCredentialsWithInvalidSecretsFile() throws Exceptio
@Test
public void testUpgradeLegacyCredentialsWithNotExistendSecretsFile() throws Exception {
GoogleRobotPrivateKeyCredentials legacyCredentials =
new GoogleRobotPrivateKeyCredentials(CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, null);
new GoogleRobotPrivateKeyCredentials(
CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, null);
setPrivateField(legacyCredentials, "secretsFile", "/notExistendSecretsFile");
setPrivateField(legacyCredentials, "p12File", p12KeyPath);
GoogleRobotPrivateKeyCredentials upgradedCredentials =
Expand All @@ -332,7 +339,8 @@ public void testUpgradeLegacyCredentialsWithNotExistendSecretsFile() throws Exce
@Test
public void testUpgradeLegacyCredentialsWithoutP12File() throws Exception {
GoogleRobotPrivateKeyCredentials legacyCredentials =
new GoogleRobotPrivateKeyCredentials(CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, null);
new GoogleRobotPrivateKeyCredentials(
CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, null);
setPrivateField(legacyCredentials, "secretsFile", legacyJsonKeyPath);
GoogleRobotPrivateKeyCredentials upgradedCredentials =
(GoogleRobotPrivateKeyCredentials) legacyCredentials.readResolve();
Expand Down Expand Up @@ -378,7 +386,8 @@ public void testProjectIdValidation() throws Exception {
@Test
public void testName() throws Exception {
GoogleRobotPrivateKeyCredentials credentials =
new GoogleRobotPrivateKeyCredentials(CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, module);
new GoogleRobotPrivateKeyCredentials(
CredentialsScope.GLOBAL, "", PROJECT_ID, "", null, module);
SystemCredentialsProvider.getInstance().getCredentials().add(credentials);

assertEquals(PROJECT_ID, CredentialsNameProvider.name(credentials));
Expand All @@ -397,8 +406,13 @@ public void testCredentialCreationWithNonEmptyIdAndDescriptionAndJsonKey() throw

// WHEN: creating credential with defined id and description
GoogleRobotPrivateKeyCredentials credentials =
new GoogleRobotPrivateKeyCredentials(
CredentialsScope.SYSTEM, CREDENTIAL_ID, PROJECT_ID, DESCRIPTION, jsonServiceAccountConfig, module);
new GoogleRobotPrivateKeyCredentials(
CredentialsScope.SYSTEM,
CREDENTIAL_ID,
PROJECT_ID,
DESCRIPTION,
jsonServiceAccountConfig,
module);

// THEN: resulting credential should have our defined id and description
assertEquals(CREDENTIAL_ID, credentials.getId());
Expand All @@ -417,8 +431,13 @@ public void testCredentialCreationWithNonEmptyIdAndDescriptionAndP12() throws Ex

// WHEN: creating credential with defined id and description
GoogleRobotPrivateKeyCredentials credentials =
new GoogleRobotPrivateKeyCredentials(
CredentialsScope.SYSTEM, CREDENTIAL_ID, PROJECT_ID, DESCRIPTION, jsonServiceAccountConfig, module);
new GoogleRobotPrivateKeyCredentials(
CredentialsScope.SYSTEM,
CREDENTIAL_ID,
PROJECT_ID,
DESCRIPTION,
jsonServiceAccountConfig,
module);

// THEN: resulting credential should have our defined id and description
assertEquals(CREDENTIAL_ID, credentials.getId());
Expand Down

0 comments on commit aa17c83

Please sign in to comment.