Skip to content

Commit

Permalink
Replacing magic numbers with constant (#338)
Browse files Browse the repository at this point in the history
Co-authored-by: Dmitrijs Lobanovskis <lobanod@amazon.com>
  • Loading branch information
hasskell and Dmitrijs Lobanovskis authored Jan 20, 2025
1 parent 63a3d10 commit 80d5088
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/hudson/tasks/SMTPAuthentication.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
*/
public class SMTPAuthentication extends AbstractDescribableImpl<SMTPAuthentication> {

private static final int MIN_PASSWORD_LENGTH = 14;
private String username;

private Secret password;
Expand All @@ -26,7 +26,7 @@ public class SMTPAuthentication extends AbstractDescribableImpl<SMTPAuthenticati
public SMTPAuthentication(String username, Secret password) {
this.username = Util.fixEmptyAndTrim(username);
this.password = password;
if (FIPS140.useCompliantAlgorithms() && Secret.toString(password).length() < 14) {
if (FIPS140.useCompliantAlgorithms() && Secret.toString(password).length() < MIN_PASSWORD_LENGTH) {

Check warning on line 29 in src/main/java/hudson/tasks/SMTPAuthentication.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 29 is only partially covered, one branch is missing
throw new IllegalArgumentException(jenkins.plugins.mailer.tasks.i18n.Messages.Mailer_SmtpPassNotFipsCompliant());
}
}
Expand All @@ -40,7 +40,7 @@ public Secret getPassword() {
}

private Object readResolve() throws ObjectStreamException {
if (FIPS140.useCompliantAlgorithms() && Secret.toString(password).length() < 14) {
if (FIPS140.useCompliantAlgorithms() && Secret.toString(password).length() < MIN_PASSWORD_LENGTH) {

Check warning on line 43 in src/main/java/hudson/tasks/SMTPAuthentication.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 43 is only partially covered, one branch is missing
throw new IllegalStateException("Mailer SMTP password: " + jenkins.plugins.mailer.tasks.i18n.Messages.Mailer_SmtpPassNotFipsCompliant());
}
return this;
Expand All @@ -56,7 +56,7 @@ public String getDisplayName() {

@RequirePOST
public FormValidation doCheckPassword(@QueryParameter Secret password) {
if (FIPS140.useCompliantAlgorithms() && Secret.toString(password).length() < 14) {
if (FIPS140.useCompliantAlgorithms() && Secret.toString(password).length() < MIN_PASSWORD_LENGTH) {

Check warning on line 59 in src/main/java/hudson/tasks/SMTPAuthentication.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 59 is only partially covered, one branch is missing
return FormValidation.error(jenkins.plugins.mailer.tasks.i18n.Messages.Mailer_SmtpPassNotFipsCompliant());
}
return FormValidation.ok();
Expand Down

0 comments on commit 80d5088

Please sign in to comment.