Skip to content

Commit

Permalink
[backend] Add validation for default score value
Browse files Browse the repository at this point in the history
  • Loading branch information
savacano28 authored Oct 24, 2024
1 parent 404d0be commit f178c65
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions openbas-api/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,7 @@ openbas.expectation.human.expiration-time=86400
#openbas.expectation.article.expiration-time=3600
#openbas.expectation.manual.expiration-time=3600

# Min value: 1
# Max value: 100
# Default value: 50
openbas.expectation.manual.default-score-value=50
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.openbas.expectation;

import lombok.Setter;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import static java.util.Optional.ofNullable;

@Component
@Setter
@Log
public class ExpectationPropertiesConfig {

public static long DEFAULT_TECHNICAL_EXPECTATION_EXPIRATION_TIME = 21600L; // 6 hours
Expand Down Expand Up @@ -73,8 +75,13 @@ public long getManualExpirationTime() {
}

public int getDefaultExpectationScoreValue() {
return ofNullable(this.defaultManualExpectationScore)
.orElse(DEFAULT_MANUAL_EXPECTATION_SCORE);
if (defaultManualExpectationScore == null ||
defaultManualExpectationScore < 1 ||
defaultManualExpectationScore > 100) {
log.warning("The provided default score value is invalid. It should be within the acceptable range of 0 to 100. The score will be set to the default of 50.");
return DEFAULT_MANUAL_EXPECTATION_SCORE;
}
return defaultManualExpectationScore;
}

}

0 comments on commit f178c65

Please sign in to comment.