Skip to content

Commit

Permalink
NOBUG: Refactor JWT verification logic in captchaUtil.js and writePas…
Browse files Browse the repository at this point in the history
…s.test.js (#367)
  • Loading branch information
marklise authored Apr 15, 2024
1 parent 51a1646 commit 9b66330
Show file tree
Hide file tree
Showing 3 changed files with 289 additions and 203 deletions.
13 changes: 3 additions & 10 deletions __tests__/writePass.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ describe('Pass Fails', () => {
const writePassHandler = require('../lambda/writePass/index');
const token = jwt.sign(
{
data: 'verified',
registrationNumber: '1111111111',
facility: 'Trail B',
bookingDate: '2022-01-01',
Expand Down Expand Up @@ -157,7 +156,6 @@ describe('Pass Fails', () => {
const writePassHandler = require('../lambda/writePass/index');
const token = jwt.sign(
{
data: 'verified',
registrationNumber: '1111111112',
facility: 'Trail B',
orcs: 'Test Park 1',
Expand Down Expand Up @@ -205,7 +203,6 @@ describe('Pass Fails', () => {
const writePassHandler = require('../lambda/writePass/index');
const token = jwt.sign(
{
data: 'verified',
registrationNumber: '1111111113',
facility: 'Parking lot A',
orcs: 'Test Park 1',
Expand Down Expand Up @@ -253,7 +250,6 @@ describe('Pass Fails', () => {
const writePassHandler = require('../lambda/writePass/index');
const token = jwt.sign(
{
data: 'verified',
registrationNumber: '1111111114',
facility: 'Trail B',
orcs: 'Test Park 1',
Expand Down Expand Up @@ -414,10 +410,11 @@ describe('Pass Successes', () => {

const token = jwt.sign(
{
data: 'verified',
registrationNumber: '1111111115',
facility: 'P1 and Lower P5',
orcs: '0015'
orcs: '0015',
bookingDate: '2022-01-01',
passType: 'DAY'
},
'defaultSecret',
{
Expand Down Expand Up @@ -467,7 +464,6 @@ describe('Pass Successes', () => {

const token = jwt.sign(
{
data: 'verified',
registrationNumber: '1111111116',
facility: 'Parking lot A',
orcs: 'Test Park 1'
Expand Down Expand Up @@ -521,7 +517,6 @@ describe('Pass Successes', () => {

const token = jwt.sign(
{
data: 'verified',
registrationNumber: '1111111117',
facility: 'Trail B',
orcs: 'Test Park 1'
Expand Down Expand Up @@ -699,7 +694,6 @@ describe('Pass Successes', () => {

const token = jwt.sign(
{
data: 'verified',
registrationNumber: '1111111118',
facility: undefined,
orcs: 'Test Park 1'
Expand Down Expand Up @@ -740,7 +734,6 @@ describe('Pass Successes', () => {

const token = jwt.sign(
{
data: 'verified',
registrationNumber: '1111111119',
facility: 'Parking lot A',
orcs: 'Test Park 1',
Expand Down
23 changes: 8 additions & 15 deletions lambda/captchaUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,14 @@ function verifyJWT(token) {
try {
const decoded = jwt.verify(token, SECRET, { algorithm: ALGORITHM });
logger.info('JWT decoded.')
// A256GCM
if (decoded.data) {
return {
valid: true,
registrationNumber: decoded.registrationNumber,
facility: decoded.facility,
orcs: decoded.orcs,
bookingDate: decoded.bookingDate,
passType: decoded.passType
};
} else {
return {
valid: false
};
}
return {
valid: true,
registrationNumber: decoded.registrationNumber,
facility: decoded.facility,
orcs: decoded.orcs,
bookingDate: decoded.bookingDate,
passType: decoded.passType
};
} catch (e) {
logger.error(e);
return {
Expand Down
Loading

0 comments on commit 9b66330

Please sign in to comment.