From c2ccf344a893bdb4d2994d906c786c756b99e5a2 Mon Sep 17 00:00:00 2001 From: Vishnu Sreekumaran Nair <200557136@student.georgianc.on.ca> Date: Thu, 1 May 2025 20:20:21 -0400 Subject: [PATCH] Add frontend validation for port field values --- client/src/Validation/validation.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/client/src/Validation/validation.js b/client/src/Validation/validation.js index 6e8ff76cb..a875da153 100644 --- a/client/src/Validation/validation.js +++ b/client/src/Validation/validation.js @@ -159,7 +159,20 @@ const monitorValidation = joi.object({ "string.invalidUrl": "Please enter a valid URL with optional port", "string.pattern.base": "Please enter a valid container ID.", }), - port: joi.number(), + port: joi.number() + .integer() + .min(1) + .max(65535) + .when("type", { + is: "port", + then: joi.required().messages({ + "number.base": "Port must be a number.", + "number.min": "Port must be at least 1.", + "number.max": "Port must be at most 65535.", + "any.required": "Port is required for port monitors.", + }), + otherwise: joi.optional(), + }), name: joi.string().trim().max(50).allow("").messages({ "string.max": "This field should not exceed the 50 characters limit.", }),