Skip to content

Commit

Permalink
Invalid ID check
Browse files Browse the repository at this point in the history
  • Loading branch information
fu351 committed Dec 15, 2023
1 parent acddd8a commit 2d20aa8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion search.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ router.get('/package/:id', (req, res) => {
//console.log(process.env.AWS_ACCESS_Key_ID, process.env.AWS_SECRET_ACCESS_Key)
const packageID = req.params.id;
const xauth = req.headers['x-authorization'];
if (!packageID) {
if (!packageID || typeof packageID !== 'string') {
return res.status(400).json({ error: 'Missing package ID' });
}
if (xauth != "0") {
Expand Down
11 changes: 8 additions & 3 deletions upload_update_download_rate.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ router.get('/download/:id', async (req, res) => { //download package from bucket
if (xauth != "0" || !xauth) { //need all fields to be present
return res.status(400).json({error: 'There are missing fields in the Request Body'});
}
if (!ID || typeof ID != 'string') {
return res.status(400).json({ error: 'Missing PackageID' });
}
const params = {
Bucket: '461testbucket',
Key: `packages/${ID}.zip`, // Use the selected package name to generate the Object key
Expand Down Expand Up @@ -421,7 +424,9 @@ router.put('/package/:id', async (req, res) => { //update package
//process.exit(1);
}
}

if (!URL) {
URL = existingMetaData.url;
}
const s3uploadparams = { //replace old content with the new content
Bucket: '461testbucket',
Key: `packages/${ID}.zip`,
Expand Down Expand Up @@ -458,7 +463,7 @@ router.get('/package/:id/rate', async (req, res) => { //rate package
}
console.log("ID",packageId);
//There is missing field(s) in the PackageID/AuthenticationToken or it is formed improperly, or the AuthenticationToken is invalid. return 400 error
if (!packageId) {
if (!packageId || typeof packageId != 'string') {
return res.status(400).json({ error: 'Missing PackageID' });
}
try {
Expand All @@ -484,7 +489,7 @@ router.get('/package/:id/rate', async (req, res) => { //rate package
const metric = score[i];
if (isNaN(metric)) { //check for ingestion
console.log('Package Net Score too low, ingestion blocked.');
return res.status(500).json({ error: 'Package not uploaded due to rating' });
return res.status(500).json({ error: 'choke' });
}
}
if (!score) {
Expand Down

0 comments on commit 2d20aa8

Please sign in to comment.