Skip to content

Commit

Permalink
Updated ConfigValidatorUtil to handle null values, Updated ConfigVali…
Browse files Browse the repository at this point in the history
…datorUtilTest to test handling null values
  • Loading branch information
Behnam Mozafari committed Dec 19, 2024
1 parent 8018196 commit cd23998
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/uid2/operator/service/ConfigValidatorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@

public class ConfigValidatorUtil {
private static final Logger logger = LoggerFactory.getLogger(ConfigValidatorUtil.class);
public static final String VALUES_ARE_NULL = "Required config values are null";

public static Boolean validateIdentityRefreshTokens(Integer identityExpiresAfter, Integer refreshExpiresAfter, Integer refreshIdentityAfter) {
boolean isValid = true;

if (identityExpiresAfter == null || refreshExpiresAfter == null || refreshIdentityAfter == null) {
logger.error(VALUES_ARE_NULL);
return false;
}


if (identityExpiresAfter > refreshExpiresAfter) {
logger.error(REFRESH_TOKEN_EXPIRES_AFTER_SECONDS + " must be >= " + IDENTITY_TOKEN_EXPIRES_AFTER_SECONDS);
isValid = false;
Expand All @@ -25,6 +33,11 @@ public static Boolean validateIdentityRefreshTokens(Integer identityExpiresAfter
}

public static Boolean validateBidstreamLifetime(Integer maxBidstreamLifetimeSeconds, Integer identityTokenExpiresAfterSeconds) {
if (maxBidstreamLifetimeSeconds == null || identityTokenExpiresAfterSeconds == null) {
logger.error(VALUES_ARE_NULL);
return false;
}

if (maxBidstreamLifetimeSeconds < identityTokenExpiresAfterSeconds) {
logger.error("Max bidstream lifetime seconds ({} seconds) is less than identity token lifetime ({} seconds)", maxBidstreamLifetimeSeconds, identityTokenExpiresAfterSeconds);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,31 @@ void testValidateBidstreamLifetime() {
assertTrue(ConfigValidatorUtil.validateBidstreamLifetime(10, 5));
assertTrue(ConfigValidatorUtil.validateBidstreamLifetime(10, 10));
}

@Test
void testValidateIdentityRefreshTokensWithNullValues() {
// identityExpiresAfter is null
assertFalse(ConfigValidatorUtil.validateIdentityRefreshTokens(null, 10, 5));

// refreshExpiresAfter is null
assertFalse(ConfigValidatorUtil.validateIdentityRefreshTokens(10, null, 5));

// refreshIdentityAfter is null
assertFalse(ConfigValidatorUtil.validateIdentityRefreshTokens(10, 5, null));

// all values are null
assertFalse(ConfigValidatorUtil.validateIdentityRefreshTokens(null, null, null));
}

@Test
void testValidateBidstreamLifetimeWithNullValues() {
// maxBidstreamLifetimeSeconds is null
assertFalse(ConfigValidatorUtil.validateBidstreamLifetime(null, 10));

// identityTokenExpiresAfterSeconds is null
assertFalse(ConfigValidatorUtil.validateBidstreamLifetime(10, null));

// both values are null
assertFalse(ConfigValidatorUtil.validateBidstreamLifetime(null, null));
}
}

0 comments on commit cd23998

Please sign in to comment.