22
33import com .auth0 .jwt .algorithms .Algorithm ;
44import com .auth0 .jwt .interfaces .DecodedJWT ;
5+ import com .auth0 .jwt .jwts .JWT ;
56import net .jodah .concurrentunit .Waiter ;
67import org .junit .AfterClass ;
78import org .junit .BeforeClass ;
2021//@Ignore("Skipping concurrency tests")
2122public class ConcurrentVerifyTest {
2223
23- /* private static final long TIMEOUT = 10 * 1000 * 1000; //1 min
24+ private static final long TIMEOUT = 10 * 1000 * 1000 ; //1 min
2425 private static final int THREAD_COUNT = 100 ;
2526 private static final int REPEAT_COUNT = 1000 ;
2627 private static final String PUBLIC_KEY_FILE = "src/test/resources/rsa-public.pem" ;
@@ -43,120 +44,121 @@ public static void afterAll() throws Exception {
4344 }
4445
4546 @ SuppressWarnings ("Convert2Lambda" )
46- private void concurrentVerify(final JWTVerifier verifier , final String token) throws TimeoutException, InterruptedException {
47+ private void concurrentVerify (final JWT jwt , final String token ) throws TimeoutException , InterruptedException {
4748 final Waiter waiter = new Waiter ();
48- List<VerifyTask> tasks = Collections.nCopies(REPEAT_COUNT, new VerifyTask(waiter, verifier , token));
49+ List <VerifyTask > tasks = Collections .nCopies (REPEAT_COUNT , new VerifyTask (waiter , jwt , token ));
4950 executor .invokeAll (tasks , TIMEOUT , TimeUnit .MILLISECONDS );
5051 waiter .await (TIMEOUT , REPEAT_COUNT );
5152 }
5253
5354 private static class VerifyTask implements Callable <DecodedJWT > {
5455
5556 private final Waiter waiter ;
56- private final JWTVerifier verifier ;
57+ private final JWT jwt ;
5758 private final String token ;
5859
59- VerifyTask(Waiter waiter, final JWTVerifier verifier , final String token) {
60+ VerifyTask (Waiter waiter , final JWT jwt , final String token ) {
6061 this .waiter = waiter ;
61- this.verifier = verifier ;
62+ this .jwt = jwt ;
6263 this .token = token ;
6364 }
6465
6566 @ Override
6667 public DecodedJWT call () throws Exception {
67- DecodedJWT jwt = null;
68+ DecodedJWT decodedJWT = null ;
6869 try {
69- jwt = verifier.verify (token);
70- waiter.assertNotNull(jwt );
70+ decodedJWT = jwt . decode (token );
71+ waiter .assertNotNull (decodedJWT );
7172 } catch (Exception e ) {
7273 waiter .fail (e );
7374 }
7475 waiter .resume ();
75- return jwt ;
76+ return decodedJWT ;
7677 }
7778 }
7879
7980 @ Test
8081 public void shouldPassHMAC256Verification () throws Exception {
8182 Algorithm algorithm = Algorithm .HMAC256 ("secret" );
82- JWTVerifier verifier = JWTVerifier.init (algorithm).withIssuer("auth0").build();
83+ JWT jwt = JWT . require (algorithm ).withIssuer ("auth0" ).build ();
8384 String token = "eyJhbGciOiJIUzI1NiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.mZ0m_N1J4PgeqWmi903JuUoDRZDBPB7HwkS4nVyWH1M" ;
8485
85- concurrentVerify(verifier , token);
86+ concurrentVerify (jwt , token );
8687 }
8788
8889 @ Test
8990 public void shouldPassHMAC384Verification () throws Exception {
9091 String token = "eyJhbGciOiJIUzM4NCIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.uztpK_wUMYJhrRv8SV-1LU4aPnwl-EM1q-wJnqgyb5DHoDteP6lN_gE1xnZJH5vw" ;
9192 Algorithm algorithm = Algorithm .HMAC384 ("secret" );
92- JWTVerifier verifier = JWTVerifier.init (algorithm).withIssuer("auth0").build();
93+ JWT jwt = JWT . require (algorithm ).withIssuer ("auth0" ).build ();
9394
94- concurrentVerify(verifier , token);
95+ concurrentVerify (jwt , token );
9596 }
9697
9798 @ Test
9899 public void shouldPassHMAC512Verification () throws Exception {
99100 String token = "eyJhbGciOiJIUzUxMiIsImN0eSI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.VUo2Z9SWDV-XcOc_Hr6Lff3vl7L9e5Vb8ThXpmGDFjHxe3Dr1ZBmUChYF-xVA7cAdX1P_D4ZCUcsv3IefpVaJw" ;
100101 Algorithm algorithm = Algorithm .HMAC512 ("secret" );
101- JWTVerifier verifier = JWTVerifier.init (algorithm).withIssuer("auth0").build();
102+ JWT jwt = JWT . require (algorithm ).withIssuer ("auth0" ).build ();
102103
103- concurrentVerify(verifier , token);
104+ concurrentVerify (jwt , token );
104105 }
105106
106107 @ Test
107108 public void shouldPassRSA256Verification () throws Exception {
108109 String token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.dxXF3MdsyW-AuvwJpaQtrZ33fAde9xWxpLIg9cO2tMLH2GSRNuLAe61KsJusZhqZB9Iy7DvflcmRz-9OZndm6cj_ThGeJH2LLc90K83UEvvRPo8l85RrQb8PcanxCgIs2RcZOLygERizB3pr5icGkzR7R2y6zgNCjKJ5_NJ6EiZsGN6_nc2PRK_DbyY-Wn0QDxIxKoA5YgQJ9qafe7IN980pXvQv2Z62c3XR8dYuaXBqhthBj-AbaFHEpZapN-V-TmuLNzR2MCB6Xr7BYMuCaqWf_XU8og4XNe8f_8w9Wv5vvgqMM1KhqVpG5VdMJv4o_L4NoCROHhtUQSLRh2M9cA" ;
109110 Algorithm algorithm = Algorithm .RSA256 ((RSAKey ) readPublicKeyFromFile (PUBLIC_KEY_FILE , "RSA" ));
110- JWTVerifier verifier = JWTVerifier.init (algorithm).withIssuer("auth0").build();
111+ JWT jwt = JWT . require (algorithm ).withIssuer ("auth0" ).build ();
111112
112- concurrentVerify(verifier , token);
113+ concurrentVerify (jwt , token );
113114 }
114115
115116 @ Test
116117 public void shouldPassRSA384Verification () throws Exception {
117118 String token = "eyJhbGciOiJSUzM4NCIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.TZlWjXObwGSQOiu2oMq8kiKz0_BR7bbBddNL6G8eZ_GoR82BXOZDqNrQr7lb_M-78XGBguWLWNIdYhzgxOUL9EoCJlrqVm9s9vo6G8T1sj1op-4TbjXZ61TwIvrJee9BvPLdKUJ9_fp1Js5kl6yXkst40Th8Auc5as4n49MLkipjpEhKDKaENKHpSubs1ripSz8SCQZSofeTM_EWVwSw7cpiM8Fy8jOPvWG8Xz4-e3ODFowvHVsDcONX_4FTMNbeRqDuHq2ZhCJnEfzcSJdrve_5VD5fM1LperBVslTrOxIgClOJ3RmM7-WnaizJrWP3D6Z9OLxPxLhM6-jx6tcxEw" ;
118119 Algorithm algorithm = Algorithm .RSA384 ((RSAKey ) readPublicKeyFromFile (PUBLIC_KEY_FILE , "RSA" ));
119- JWTVerifier verifier = JWTVerifier.init (algorithm).withIssuer("auth0").build();
120+ JWT jwt = JWT . require (algorithm ).withIssuer ("auth0" ).build ();
120121
121- concurrentVerify(verifier , token);
122+ concurrentVerify (jwt , token );
122123 }
123124
124125 @ Test
125126 public void shouldPassRSA512Verification () throws Exception {
126127 String token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhdXRoMCJ9.mvL5LoMyIrWYjk5umEXZTmbyIrkbbcVPUkvdGZbu0qFBxGOf0nXP5PZBvPcOu084lvpwVox5n3VaD4iqzW-PsJyvKFgi5TnwmsbKchAp7JexQEsQOnTSGcfRqeUUiBZqRQdYsho71oAB3T4FnalDdFEpM-fztcZY9XqKyayqZLreTeBjqJm4jfOWH7KfGBHgZExQhe96NLq1UA9eUyQwdOA1Z0SgXe4Ja5PxZ6Fm37KnVDtDlNnY4JAAGFo6y74aGNnp_BKgpaVJCGFu1f1S5xCQ1HSvs8ZSdVWs5NgawW3wRd0kRt_GJ_Y3mIwiF4qUyHWGtsSHu_qjVdCTtbFyow" ;
127128 Algorithm algorithm = Algorithm .RSA512 ((RSAKey ) readPublicKeyFromFile (PUBLIC_KEY_FILE , "RSA" ));
128- JWTVerifier verifier = JWTVerifier.init (algorithm).withIssuer("auth0").build();
129+ JWT jwt = JWT . require (algorithm ).withIssuer ("auth0" ).build ();
129130
130- concurrentVerify(verifier , token);
131+ concurrentVerify (jwt , token );
131132 }
132133
133134 @ Test
134135 public void shouldPassECDSA256VerificationWithJOSESignature () throws Exception {
135136 String token = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g" ;
136137 ECKey key = (ECKey ) readPublicKeyFromFile (PUBLIC_KEY_FILE_256 , "EC" );
137138 Algorithm algorithm = Algorithm .ECDSA256 (key );
138- JWTVerifier verifier = JWTVerifier.init (algorithm).withIssuer("auth0").build();
139+ JWT jwt = JWT . require (algorithm ).withIssuer ("auth0" ).build ();
139140
140- concurrentVerify(verifier , token);
141+ concurrentVerify (jwt , token );
141142 }
142143
143144 @ Test
144145 public void shouldPassECDSA384VerificationWithJOSESignature () throws Exception {
145146 String token = "eyJhbGciOiJFUzM4NCJ9.eyJpc3MiOiJhdXRoMCJ9.50UU5VKNdF1wfykY8jQBKpvuHZoe6IZBJm5NvoB8bR-hnRg6ti-CHbmvoRtlLfnHfwITa_8cJMy6TenMC2g63GQHytc8rYoXqbwtS4R0Ko_AXbLFUmfxnGnMC6v4MS_z" ;
146147 ECKey key = (ECKey ) readPublicKeyFromFile (PUBLIC_KEY_FILE_384 , "EC" );
147148 Algorithm algorithm = Algorithm .ECDSA384 (key );
148- JWTVerifier verifier = JWTVerifier.init (algorithm).withIssuer("auth0").build();
149+ JWT jwt = JWT . require (algorithm ).withIssuer ("auth0" ).build ();
149150
150- concurrentVerify(verifier , token);
151+ concurrentVerify (jwt , token );
151152 }
152153
153154 @ Test
154155 public void shouldPassECDSA512VerificationWithJOSESignature () throws Exception {
155156 String token = "eyJhbGciOiJFUzUxMiJ9.eyJpc3MiOiJhdXRoMCJ9.AeCJPDIsSHhwRSGZCY6rspi8zekOw0K9qYMNridP1Fu9uhrA1QrG-EUxXlE06yvmh2R7Rz0aE7kxBwrnq8L8aOBCAYAsqhzPeUvyp8fXjjgs0Eto5I0mndE2QHlgcMSFASyjHbU8wD2Rq7ZNzGQ5b2MZfpv030WGUajT-aZYWFUJHVg2" ;
156157 ECKey key = (ECKey ) readPublicKeyFromFile (PUBLIC_KEY_FILE_512 , "EC" );
157158 Algorithm algorithm = Algorithm .ECDSA512 (key );
158- JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer("auth0").build();
159+ JWT jwt = JWT .require (algorithm ).withIssuer ("auth0" ).build ();
160+
161+ concurrentVerify (jwt , token );
162+ }
159163
160- concurrentVerify(verifier, token);
161- }*/
162164}
0 commit comments