From 2ef673c6051e4c477f653d9cb94d44f7c15cbb87 Mon Sep 17 00:00:00 2001 From: Prathamesh Lakhapati <114794439+Prathamesh061@users.noreply.github.com> Date: Thu, 13 Apr 2023 22:27:41 +0530 Subject: [PATCH 1/5] 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. --- src/lib/isJWT.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/isJWT.js b/src/lib/isJWT.js index 1a8896f98..1d0ade5ee 100644 --- a/src/lib/isJWT.js +++ b/src/lib/isJWT.js @@ -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; } From 19aefc9274238f423e601baa3e3a2c991dc8e7b2 Mon Sep 17 00:00:00 2001 From: Prathamesh Lakhapati <114794439+Prathamesh061@users.noreply.github.com> Date: Thu, 13 Apr 2023 23:42:54 +0530 Subject: [PATCH 2/5] Update validators.test.js Added test case for validating JSON web tokens (JWT) --- test/validators.test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/validators.test.js b/test/validators.test.js index 937b52a26..467dbc213 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -8,6 +8,20 @@ import test from './testFunctions'; let validator_js = fs.readFileSync(require.resolve('../validator.js')).toString(); describe('Validators', () => { + it('should validate JSON web tokens (JWT)', () => { + test({ + validator: 'isJWT', + valid: [ + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c', + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MzgzYjNlYzMzZWUzOWMwZjY4ODVjYiIsInVzZXJJZCI6ImFkbWluIiwicm9sZSI6IkFETUlOIiwiaWF0IjoxNjgxNDA2ODI5LCJleHAiOjE2ODE0OTMyMjl9.a6b5feVNetyVaA7sk5YQrJSuvikO7uWIMQaUT7K_1gI', + ], + invalid: [ + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9', + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ', + ], + }); + }); + it('should validate email addresses', () => { test({ validator: 'isEmail', From b349c380b8d1be8508c8fc4dfb75289bad7ff651 Mon Sep 17 00:00:00 2001 From: Prathamesh Lakhapati <114794439+Prathamesh061@users.noreply.github.com> Date: Thu, 13 Apr 2023 23:51:28 +0530 Subject: [PATCH 3/5] Update validators.test.js Removed trailing spaces --- test/validators.test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/validators.test.js b/test/validators.test.js index 467dbc213..f479a8c41 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -12,16 +12,15 @@ describe('Validators', () => { test({ validator: 'isJWT', valid: [ - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c', - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MzgzYjNlYzMzZWUzOWMwZjY4ODVjYiIsInVzZXJJZCI6ImFkbWluIiwicm9sZSI6IkFETUlOIiwiaWF0IjoxNjgxNDA2ODI5LCJleHAiOjE2ODE0OTMyMjl9.a6b5feVNetyVaA7sk5YQrJSuvikO7uWIMQaUT7K_1gI', + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c', + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MzgzYjNlYzMzZWUzOWMwZjY4ODVjYiIsInVzZXJJZCI6ImFkbWluIiwicm9sZSI6IkFETUlOIiwiaWF0IjoxNjgxNDA2ODI5LCJleHAiOjE2ODE0OTMyMjl9.a6b5feVNetyVaA7sk5YQrJSuvikO7uWIMQaUT7K_1gI', ], invalid: [ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9', - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ', + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ', ], }); }); - it('should validate email addresses', () => { test({ validator: 'isEmail', From ba4041e9e6b397f0a3da9dec91fa98cf80db35de Mon Sep 17 00:00:00 2001 From: Prathamesh Lakhapati <114794439+Prathamesh061@users.noreply.github.com> Date: Fri, 14 Apr 2023 11:26:20 +0530 Subject: [PATCH 4/5] Update validators.test.js Refactor tests in isjwt and remove redundant test case --- test/validators.test.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/test/validators.test.js b/test/validators.test.js index f479a8c41..10aeee63f 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -8,19 +8,6 @@ import test from './testFunctions'; let validator_js = fs.readFileSync(require.resolve('../validator.js')).toString(); describe('Validators', () => { - it('should validate JSON web tokens (JWT)', () => { - test({ - validator: 'isJWT', - valid: [ - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c', - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MzgzYjNlYzMzZWUzOWMwZjY4ODVjYiIsInVzZXJJZCI6ImFkbWluIiwicm9sZSI6IkFETUlOIiwiaWF0IjoxNjgxNDA2ODI5LCJleHAiOjE2ODE0OTMyMjl9.a6b5feVNetyVaA7sk5YQrJSuvikO7uWIMQaUT7K_1gI', - ], - invalid: [ - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9', - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ', - ], - }); - }); it('should validate email addresses', () => { test({ validator: 'isEmail', @@ -4687,12 +4674,14 @@ 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', + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ', ], error: [ [], From 8d050ed02f592306bd1784399444fc98e13be945 Mon Sep 17 00:00:00 2001 From: Prathamesh Lakhapati <114794439+Prathamesh061@users.noreply.github.com> Date: Fri, 14 Apr 2023 12:20:22 +0530 Subject: [PATCH 5/5] Update validators.test.js Removed redundant test in isJWT --- test/validators.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/validators.test.js b/test/validators.test.js index 10aeee63f..8245a6fa4 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -4681,7 +4681,6 @@ describe('Validators', () => { 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NSIsIm5hbWUiOiJKb2huIERvZSIsImlhdCI6MTYxNjY1Mzg3Mn0.eyJpc3MiOiJodHRwczovL2V4YW1wbGUuY29tIiwiaWF0IjoxNjE2NjUzODcyLCJleHAiOjE2MTY2NTM4ODJ9.a1jLRQkO5TV5y5ERcaPAiM9Xm2gBdRjKrrCpHkGr_8M', '$Zs.ewu.su84', 'ks64$S/9.dy$§kz.3sd73b', - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ', ], error: [ [],