Skip to content

Commit

Permalink
fix(isJWT): fix validation issue in isJWT function (#2217)
Browse files Browse the repository at this point in the history
* Update isJWT.js

fix: Ensure isJWT returns false for 2 part invalid JWT tokens

Previously, the isJWT function would return true for 2 part invalid JWT tokens. This has been fixed by updating the isJWT function to return false for such tokens.

* Update validators.test.js

Added test case for validating JSON web tokens (JWT)

* Update validators.test.js

Removed trailing spaces

* Update validators.test.js

Refactor tests in isjwt and remove redundant test case

* Update validators.test.js

Removed redundant test in isJWT
  • Loading branch information
Prathamesh061 authored Jun 26, 2023
1 parent 63b1e4d commit 3507d27
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib/isJWT.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function isJWT(str) {
const dotSplit = str.split('.');
const len = dotSplit.length;

if (len > 3 || len < 2) {
if (len !== 3) {
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4720,10 +4720,11 @@ describe('Validators', () => {
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsb3JlbSI6Imlwc3VtIn0.ymiJSsMJXR6tMSr8G9usjQ15_8hKPDv_CArLhxw28MI',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb2xvciI6InNpdCIsImFtZXQiOlsibG9yZW0iLCJpcHN1bSJdfQ.rRpe04zbWbbJjwM43VnHzAboDzszJtGrNsUxaqQ-GQ8',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqb2huIjp7ImFnZSI6MjUsImhlaWdodCI6MTg1fSwiamFrZSI6eyJhZ2UiOjMwLCJoZWlnaHQiOjI3MH19.YRLPARDmhGMC3BBk_OhtwwK21PIkVCqQe8ncIRPKo-E',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ', // No signature
],
invalid: [
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NSIsIm5hbWUiOiJKb2huIERvZSIsImlhdCI6MTUxNjIzOTAyMn0',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NSIsIm5hbWUiOiJKb2huIERvZSIsImlhdCI6MTYxNjY1Mzg3Mn0.eyJpc3MiOiJodHRwczovL2V4YW1wbGUuY29tIiwiaWF0IjoxNjE2NjUzODcyLCJleHAiOjE2MTY2NTM4ODJ9.a1jLRQkO5TV5y5ERcaPAiM9Xm2gBdRjKrrCpHkGr_8M',
'$Zs.ewu.su84',
'ks64$S/9.dy$§kz.3sd73b',
],
Expand Down

0 comments on commit 3507d27

Please sign in to comment.