From 979048105ef8bd08fc03bbd272c95c652ca50679 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Fri, 7 Apr 2023 17:00:15 +0100 Subject: [PATCH] Fix authentication functions Signed-off-by: Fred Boniface --- app.js | 2 +- src/services/registration.services.js | 2 -- src/utils/log.utils.js | 2 +- src/utils/sanitizer.utils.js | 9 --------- 4 files changed, 2 insertions(+), 13 deletions(-) diff --git a/app.js b/app.js index d39fb3e..3303e8b 100644 --- a/app.js +++ b/app.js @@ -75,7 +75,7 @@ app.use('/api/v1/register', regRtr); // Authented Routes app.use('/api/v1/ldbs', authenticate) -app.use('/api/v1/auth/test', authenticate, (req, res) => res.status(200)) // Returns 401 if auth failed, 200 if successful. +app.use('/api/v1/auth/test', authenticate, (req, res) => res.status(200).json({status: "ok", message: "Authentication successful"})) // Returns 401 if auth failed, 200 if successful. // Number of proxies: app.set('trust proxy', 4) diff --git a/src/services/registration.services.js b/src/services/registration.services.js index 2db643b..b47e301 100644 --- a/src/services/registration.services.js +++ b/src/services/registration.services.js @@ -7,8 +7,6 @@ const domains = require('../configs/domains.configs') async function createRegKey(body) { log.out(`registerServices.createRegKey: Incoming request`, "INFO") - if (!clean.checkEmailValid(body.mail)) {return {status: 400, message:"address format invalid"} - } const domain = await clean.getDomainFromEmail(body.email) // The function should validate the email log.out(`registerServices: New registration request from domain: ${domain}`, "info") if (domains.includes(domain)) { diff --git a/src/utils/log.utils.js b/src/utils/log.utils.js index 5271bf4..988f99e 100644 --- a/src/utils/log.utils.js +++ b/src/utils/log.utils.js @@ -3,7 +3,7 @@ const environment = process.env.NODE_ENV; const hideInProduction = ["info", "dbug"] async function out(msg, level = 'othr') { - if (environment === "production" && hideInProduction.includes(level)) { + if (environment === "production" && hideInProduction.includes(level.toLowerCase())) { return; } else { const time = new Date().toISOString(); diff --git a/src/utils/sanitizer.utils.js b/src/utils/sanitizer.utils.js index f8282a7..491188f 100644 --- a/src/utils/sanitizer.utils.js +++ b/src/utils/sanitizer.utils.js @@ -43,18 +43,9 @@ async function getDomainFromEmail(mail) { // Needs testing return split[1] } -async function checkEmailValid(mail) { - const regex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i; - const result = mail.match(regex) - ? true - : false; log.out(`sanitizerUtils.checkEmailValid: Invalid email format used: ${mail}`,"warn") - return result; -} - module.exports = { cleanApiEndpointTxt, cleanApiEndpointNum, cleanNrcc, getDomainFromEmail, - checkEmailValid } \ No newline at end of file