Repository navigation
a #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
a #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,17 @@ | ||
| import loadService from "../services/loadervice.js"; | ||
| import loadService from "../services/loadService.js"; | ||
| import { ApiResponseinput } from "../types/index.js"; | ||
| import asyncHandler from "../utils/async.js"; | ||
| import { createAPIResponse } from "../utils/index.js"; | ||
|
|
||
| const load = new loadService(); | ||
|
|
||
| export const startLoad = asyncHandler(async (req, res) => { | ||
| await load.start(req.body); | ||
| const config = req.body; | ||
| const testId = await load.createTest(config); | ||
| const dataToSend: ApiResponseinput = { | ||
| success: true, | ||
| message: "Task created successfully", | ||
| data: testId, | ||
| }; | ||
| res.status(202).json(createAPIResponse(dataToSend)); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| import express, { Router } from "express"; | ||
|
|
||
| import { startLoad } from "../controllers/load.js"; | ||
| import { validateSchema } from "../middlewares/joiValidation.js"; | ||
| import { loadSchema } from "../validations/load.js"; | ||
|
|
||
| const router: Router = express.Router(); | ||
|
|
||
| router.post("/start", startLoad); | ||
| router.post("/start", validateSchema(loadSchema), startLoad); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing authentication middleware on load testing endpoint. The Add 🔒 Proposed fix+import authMiddleware from "../middlewares/auth.js";
+
const router: Router = express.Router();
-router.post("/start", validateSchema(loadSchema), startLoad);
+router.post("/start", authMiddleware, validateSchema(loadSchema), startLoad);🤖 Prompt for AI Agents |
||
|
|
||
| export default router; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,20 +22,20 @@ export const verificationEmail = async ( | |||||||||||||||||||||||||||||||||||||||||||
| pass: processConfig.mailer.pass, | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| await transporter.sendMail({ | ||||||||||||||||||||||||||||||||||||||||||||
| from: `verify@${processConfig.name}.com`, | ||||||||||||||||||||||||||||||||||||||||||||
| to: to, | ||||||||||||||||||||||||||||||||||||||||||||
| subject: "Verify Your Email", | ||||||||||||||||||||||||||||||||||||||||||||
| html: format?.html, | ||||||||||||||||||||||||||||||||||||||||||||
| text: format?.text, | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| transporter.verify(function (error, success) { | ||||||||||||||||||||||||||||||||||||||||||||
| if (error) { | ||||||||||||||||||||||||||||||||||||||||||||
| logger.error(`Connection Error: `,error); | ||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||
| logger.info("Server is ready to send messages."); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| await transporter.sendMail({ | ||||||||||||||||||||||||||||||||||||||||||||
| from: `verify@${processConfig.name}.com`, | ||||||||||||||||||||||||||||||||||||||||||||
| to: to, | ||||||||||||||||||||||||||||||||||||||||||||
| subject: "Verify Your Email", | ||||||||||||||||||||||||||||||||||||||||||||
| html: format?.html, | ||||||||||||||||||||||||||||||||||||||||||||
| text: format?.text, | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
25
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Race condition:
Either remove the verify call (since it provides no protection), or promisify it and await before sending: 🔧 Proposed fix: promisify verify or remove itOption 1: Remove verify (simpler, rely on sendMail errors) });
- transporter.verify(function (error, success) {
- if (error) {
- logger.error(`Connection Error: `,error);
- } else {
- logger.info("Server is ready to send messages.");
- }
- });
await transporter.sendMail({Option 2: Await verify before sending });
- transporter.verify(function (error, success) {
- if (error) {
- logger.error(`Connection Error: `,error);
- } else {
- logger.info("Server is ready to send messages.");
- }
- });
+ await transporter.verify().catch((error) => {
+ logger.error(`Connection Error: `, error);
+ throw error;
+ });
+ logger.info("Server is ready to send messages.");
await transporter.sendMail({📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||
| logger.error("Error from send Emails", e); | ||||||||||||||||||||||||||||||||||||||||||||
| throw createServiceError("SomeThing Went Wrong", 503); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import Undici from "undici"; | ||
|
|
||
| import Test from "../models/test.js"; | ||
| import Tests from "../models/test.js"; | ||
|
|
||
| class loadService { | ||
| createTest = async (configs: any): Promise<string> => { | ||
| const test = new Tests({ | ||
| ...configs | ||
| }); | ||
| const savedTests = await test.save() | ||
| return savedTests._id.toString(); | ||
|
Comment on lines
+7
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -type f -name "loadService.ts" | head -20Repository: deepx4344/SurgeTest Length of output: 92 🏁 Script executed: find . -type f -name "*[Tt]est*.ts" -o -name "*[Tt]est*.js" | grep -E "(model|schema)" | head -20Repository: deepx4344/SurgeTest Length of output: 83 🏁 Script executed: git ls-files | grep -i test | head -20Repository: deepx4344/SurgeTest Length of output: 100 🏁 Script executed: cat -n src/services/loadService.tsRepository: deepx4344/SurgeTest Length of output: 529 🏁 Script executed: cat -n src/models/test.tsRepository: deepx4344/SurgeTest Length of output: 1620 🏁 Script executed: rg "createTest" --type ts --type js -B 2 -A 2Repository: deepx4344/SurgeTest Length of output: 645 🏁 Script executed: rg "new loadService|loadService\(" --type ts --type js -B 2 -A 2Repository: deepx4344/SurgeTest Length of output: 331 🏁 Script executed: fd "route" --type ts --type js | head -10Repository: deepx4344/SurgeTest Length of output: 232 🏁 Script executed: cat -n src/controllers/load.tsRepository: deepx4344/SurgeTest Length of output: 743 🏁 Script executed: rg "validate|schema|joi|zod" --type-add="ts:*.ts" -i | head -20Repository: deepx4344/SurgeTest Length of output: 1383 Whitelist persisted fields to prevent client-controlled status/results. Spreading 🛡️ Proposed fix- createTest = async (configs: any): Promise<string> => {
- const test = new Tests({
- ...configs
- });
+ createTest = async (configs: any): Promise<string> => {
+ const {
+ url,
+ method,
+ name,
+ description,
+ headers,
+ body,
+ concurrency,
+ duration,
+ } = configs;
+ const test = new Tests({
+ url,
+ method,
+ name,
+ description,
+ headers,
+ body,
+ concurrency,
+ duration,
+ });🤖 Prompt for AI Agents |
||
| }; | ||
| } | ||
|
|
||
| export default loadService; | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,15 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import Joi from "joi"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { HttpMethods } from "../types/index.js"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| export const loadSchema = Joi.object({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| url: Joi.string().required(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| method: Joi.string() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| .valid(...Object.values(HttpMethods)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| .required(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| name: Joi.string().max(30).allow(""), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| description: Joi.string().max(255).allow(""), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| headers: Joi.any(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| body: Joi.any(), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| concurrency: Joi.number().min(1).default(10), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| duration: Joi.number().min(1).default(30), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }).unknown(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+4
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's see the full context of the file
head -30 src/validations/load.tsRepository: deepx4344/SurgeTest Length of output: 528 🏁 Script executed: # Search for where loadSchema is used
rg "loadSchema" --type tsRepository: deepx4344/SurgeTest Length of output: 278 🏁 Script executed: # Check other Joi schemas in the codebase for comparison
rg "Joi\.object" --type ts -A 5 | head -100Repository: deepx4344/SurgeTest Length of output: 1164 🏁 Script executed: # Check if there's a pattern of using .unknown() in other schemas
rg "\.unknown\(" --type tsRepository: deepx4344/SurgeTest Length of output: 104 🏁 Script executed: # Check the validateSchema middleware to understand how it processes the schema
rg "validateSchema" --type ts -B 5 -A 10Repository: deepx4344/SurgeTest Length of output: 2800 🏁 Script executed: # Check the startLoad handler to see what it does with the payload
rg "startLoad" --type ts -B 3 -A 15Repository: deepx4344/SurgeTest Length of output: 1283 🏁 Script executed: # Check if there are any comments or documentation about why unknown(true) is used
rg "unknown" --type ts -B 2 -A 2Repository: deepx4344/SurgeTest Length of output: 1927 🏁 Script executed: # Get the full validateSchema middleware implementation
cat -n src/middlewares/joiValidation.tsRepository: deepx4344/SurgeTest Length of output: 1147 🏁 Script executed: # Check what load.createTest does with the config
rg "createTest" --type ts -B 2 -A 15Repository: deepx4344/SurgeTest Length of output: 1208 🏁 Script executed: # Check the loadService to understand the full flow
fd "loadService" --type tsRepository: deepx4344/SurgeTest Length of output: 232 🏁 Script executed: # Find the Tests model to see if it has schema validation
rg "Tests" --type ts | grep -E "(schema|model|interface)" | head -20Repository: deepx4344/SurgeTest Length of output: 239 🏁 Script executed: # Look for the database model definition
fd "test" --type ts | grep -i modelRepository: deepx4344/SurgeTest Length of output: 232 🏁 Script executed: # Search for MongoDB model definitions
rg "new Schema\|mongoose.Schema" --type ts -B 2 -A 5Repository: deepx4344/SurgeTest Length of output: 45 🏁 Script executed: # Check what the Tests model looks like
rg "Tests" --type ts -B 3 -A 10 | grep -A 15 "export\|class\|new"Repository: deepx4344/SurgeTest Length of output: 1419 🏁 Script executed: # Get the full test.ts model definition
cat -n src/models/test.tsRepository: deepx4344/SurgeTest Length of output: 1620 Reject unknown keys in load payloads.
🔒 Proposed fix-}).unknown(true);
+}).unknown(false);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Missing semicolon for consistency.
Line 49 is missing a semicolon, while similar statements in this file (lines 33, 41) include one.
🔧 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents