Skip to content

Commit

Permalink
feat: use default expiration time in Zosmf scheme for auth. source wi…
Browse files Browse the repository at this point in the history
…thout expiration (#2298)

Signed-off-by: Yelyzaveta Chebanova <[email protected]>
  • Loading branch information
yelyzavetachebanova authored Apr 14, 2022
1 parent 02dd0bf commit 122837e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public AuthenticationCommand createCommand(Authentication authentication, AuthSo

final long defaultExpirationTime = System.currentTimeMillis() + authConfigurationProperties.getTokenProperties().getExpirationInSeconds() * 1000L;
final Date expiration = parsedAuthSource == null ? null : parsedAuthSource.getExpiration();
final Long expirationTime = expiration != null ? expiration.getTime() : null;
final Long expireAt = expirationTime != null ? Math.min(defaultExpirationTime, expirationTime) : null;
final long expirationTime = expiration != null ? expiration.getTime() : defaultExpirationTime;
final Long expireAt = Math.min(defaultExpirationTime, expirationTime);
final AuthSource.Origin origin = parsedAuthSource != null ? parsedAuthSource.getOrigin() : null;

return new ZosmfCommand(expireAt, origin, cookieValue, error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,14 @@ void givenNoAuthSource_thenCommandIsNotExpired() {

@Test
void givenAuthSourceWithoutExpiration_thenCommandIsNotExpired() {
long defaultExpiration = System.currentTimeMillis() + authConfigurationProperties.getTokenProperties().getExpirationInSeconds() * 1000L;
when(authSourceService.parse(new JwtAuthSource("jwtToken"))).thenReturn(new JwtAuthSource.Parsed("user", null, null, Origin.ZOWE));

AuthenticationCommand command = zosmfScheme.createCommand(null, new JwtAuthSource("jwtToken"));

assertNull(ReflectionTestUtils.getField(command, "expireAt"));
Long expiration = (Long) ReflectionTestUtils.getField(command, "expireAt");
assertNotNull(expiration);
assertTrue(expiration >= defaultExpiration);
assertFalse(command.isExpired());
}

Expand Down

0 comments on commit 122837e

Please sign in to comment.