Skip to content

Commit

Permalink
NOBUG: Delete hold token from DB. (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
marklise authored May 22, 2024
1 parent be125c6 commit 975f837
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions __tests__/writePass.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,9 @@ describe('Pass Successes', () => {
commit: true
};
}),
deleteHoldToken:jest.fn(() => {
return;
}),
getOne: jest.fn(() => {
return undefined // Simulate not found
}),
Expand Down
16 changes: 16 additions & 0 deletions lambda/permissionUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ exports.verifyHoldToken = function (token, secret) {
return decodedToken;
};

exports.deleteHoldToken = async function (token) {
try {
await dynamodb.deleteItem({
Key: {
pk: { S: 'jwt' },
sk: { S: token }
},
TableName: TABLE_NAME
}).promise();
} catch (error) {
// Handle the error here
logger.error('Error deleting hold token:');
logger.debug(error);
}
};

const verifyToken = function (token, callback, sendError) {
logger.debug('verifying token');
logger.debug('token:', token);
Expand Down
13 changes: 12 additions & 1 deletion lambda/writePass/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ const {
storeObject
} = require('../dynamoUtil');
const { sendResponse, checkWarmup, CustomError } = require('../responseUtil');
const { decodeJWT, resolvePermissions, validateToken, verifyHoldToken, getExpiryTime } = require('../permissionUtil');
const {
decodeJWT,
deleteHoldToken,
getExpiryTime,
resolvePermissions,
validateToken,
verifyHoldToken
} = require('../permissionUtil');
const { DateTime } = require('luxon');
const { logger } = require('../logger');
const { createNewReservationsObj } = require('../reservationObjUtils');
Expand Down Expand Up @@ -175,6 +182,10 @@ async function handleCommitPass(newObject, isAdmin) {
logger.error(error);
return sendResponse(error.statusCode, { msg: error.message, title: 'Operation Failed.' });
}

// Delete the JWT from the database
logger.info('Deleting the JWT from the database');
await deleteHoldToken(token);
}

logger.info('generateCancellationLink');
Expand Down

0 comments on commit 975f837

Please sign in to comment.