Skip to content

Commit

Permalink
Adapt to changes from credentials regarding password length in FIPS m…
Browse files Browse the repository at this point in the history
…ode jenkinsci/credentials-plugin#558

Signed-off-by: Olivier Lamy <olamy@apache.org>
  • Loading branch information
olamy authored and slide committed Sep 24, 2024
1 parent 915d327 commit 44c3037
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>1378.v81ef4269d764</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/hudson/plugins/emailext/MailAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,19 @@ private void migrateCredentials() {
if (StringUtils.isBlank(credentialsId)) {
// If we couldn't find any existing credentials,
// create new credentials with the principal and secret and use it.
final StandardUsernamePasswordCredentials newCredentials = new UsernamePasswordCredentialsImpl(
CredentialsScope.GLOBAL,
null,
"Migrated from email-ext username/password",
smtpUsername,
smtpPassword.getPlainText());
final StandardUsernamePasswordCredentials newCredentials;
try {
newCredentials = new UsernamePasswordCredentialsImpl(
CredentialsScope.GLOBAL,
null,
"Migrated from email-ext username/password",
smtpUsername,
smtpPassword.getPlainText());
} catch (Descriptor.FormException e) {
// safe to ignore as too short password should happen only in FIPS mode
// and migrating from no FIPS to FIPS is not supported, but only fresh start
throw new RuntimeException(e);
}
SystemCredentialsProvider.getInstance().getCredentials().add(newCredentials);
credentialsId = newCredentials.getId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,16 @@ public void testIsValidAuthConfigAndTLS() {
}

@Test
public void testFormValidationForInsecureAuth() {
public void testFormValidationForInsecureAuth() throws Exception {
final String validCredentialId = "valid-id";
SystemCredentialsProvider.getInstance()
.getCredentials()
.add(new UsernamePasswordCredentialsImpl(
CredentialsScope.GLOBAL, validCredentialId, "description", "username", "password"));
CredentialsScope.GLOBAL,
validCredentialId,
"description",
"username",
"password-must-be-longer-for-fips"));

MailAccountDescriptor mad = (MailAccountDescriptor) Jenkins.get().getDescriptor(MailAccount.class);

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/hudson/plugins/emailext/MailAccountTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void testUpgradeDuringCredentialsGetter() {
}

@Test
public void testFormValidationForInsecureAuth() {
public void testFormValidationForInsecureAuth() throws Exception {
final String validCredentialId = "valid-id";
SystemCredentialsProvider.getInstance()
.getCredentials()
Expand Down

0 comments on commit 44c3037

Please sign in to comment.