This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix of expiration time for JWT token
- Loading branch information
1 parent
9c064c5
commit 9c52a0f
Showing
4 changed files
with
12 additions
and
4 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
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 |
---|---|---|
|
@@ -25,8 +25,12 @@ | |
package oap.ws.sso; | ||
|
||
import oap.util.Pair; | ||
import org.joda.time.DateTime; | ||
import org.testng.annotations.Test; | ||
|
||
import java.time.Duration; | ||
import java.time.temporal.*; | ||
import java.time.Instant; | ||
import java.util.Date; | ||
import java.util.Set; | ||
|
||
|
@@ -38,14 +42,17 @@ | |
|
||
public class JwtTokenGeneratorExtractorTest extends AbstractUserTest { | ||
|
||
private final JwtTokenGenerator jwtTokenGenerator = new JwtTokenGenerator( "secret", "secret", "issuer", 100000, 100000 ); | ||
private final JwtTokenGenerator jwtTokenGenerator = new JwtTokenGenerator( "secret", "secret", "issuer", 15 * 60 * 1000, 15 * 60 * 1000 * 24 ); | ||
private final JWTExtractor jwtExtractor = new JWTExtractor( "secret", "issuer", new SecurityRoles( new TestSecurityRolesProvider() ) ); | ||
|
||
@Test | ||
public void generateAndExtractToken() { | ||
final Pair<Date, String> token = jwtTokenGenerator.generateAccessToken( new TestUser( "[email protected]", "password", Pair.of( "org1", "ADMIN" ) ) ); | ||
assertNotNull( token._1 ); | ||
assertString( token._2 ).isNotEmpty(); | ||
Instant expirationTime = token._1.toInstant().truncatedTo( ChronoUnit.MINUTES ); | ||
Instant expectedExpirationTime = ( Instant.now().plus( Duration.ofMinutes( 15 ) ).truncatedTo( ChronoUnit.MINUTES ) ); | ||
assertTrue( ( expirationTime.compareTo( expectedExpirationTime ) ) == 0 ); | ||
assertTrue( jwtExtractor.verifyToken( token._2 ) ); | ||
assertEquals( jwtExtractor.getUserEmail( token._2 ), "[email protected]" ); | ||
assertEquals( jwtExtractor.getPermissions( token._2, "org1" ), Set.of( "accounts:list", "accounts:create" ) ); | ||
|
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