Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/jwtSync #71

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class JwtTokenIssuer {

private static final SignatureAlgorithm SIGNATURE_ALGORITHM = SignatureAlgorithm.RS256;
private static final long TOKEN_TTL = 600000;
private static final long TOKEN_ISSUED = 6000;

private final PrivateKey signingKey;

Expand Down Expand Up @@ -74,7 +75,7 @@ public String getToken(final Integer appId) {
.setIssuer(String.valueOf(appId))
.signWith(signingKey, SIGNATURE_ALGORITHM)
.setExpiration(new Date(System.currentTimeMillis() + TOKEN_TTL))
.setIssuedAt(new Date())
.setIssuedAt(new Date(System.currentTimeMillis() - TOKEN_ISSUED))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a test for this?

If the current time is provided by a Supplier<long> then this could be more easily tested. Perhaps two constructors, one where this supplier is just () -> System.currentTimeMillis() and another ctor w @VisibleForTesting where tests can provide the supplier in order to get known values.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Don't feel strongly about it, apart from keeping them checks happy)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really sure what i am testing here?
that the setter accepted my new time? or that the time was in fact 60 seconds before now?

I can for sure look into it though if you think a test is for sure needed.

Copy link
Author

@bguedel bguedel Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can for sure understand getting another constructor in here so that people that dont have drift or care about it can ignore it.

.compact();
}
}