-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from openfga/fix/token-exp-check
fix: fix token validity check for expiry
- Loading branch information
Showing
3 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/test/java/dev/openfga/sdk/api/auth/AccessTokenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* OpenFGA | ||
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. | ||
* | ||
* The version of the OpenAPI document: 0.1 | ||
* Contact: community@openfga.dev | ||
* | ||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
|
||
package dev.openfga.sdk.api.auth; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.time.Instant; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
class AccessTokenTest { | ||
|
||
private static Stream<Arguments> expTimeAndResults() { | ||
return Stream.of( | ||
Arguments.of(Instant.now().plus(1, ChronoUnit.HOURS), true), | ||
Arguments.of(Instant.now().minus(1, ChronoUnit.HOURS), false), | ||
Arguments.of(Instant.now().minus(10, ChronoUnit.MINUTES), false), | ||
Arguments.of(Instant.now().plus(10, ChronoUnit.MINUTES), true), | ||
Arguments.of(Instant.now(), true)); | ||
} | ||
|
||
@MethodSource("expTimeAndResults") | ||
@ParameterizedTest | ||
public void testTokenValid(Instant exp, boolean valid) { | ||
AccessToken accessToken = new AccessToken(); | ||
accessToken.setToken("token"); | ||
accessToken.setExpiresAt(exp); | ||
assertEquals(valid, accessToken.isValid()); | ||
} | ||
} |