diff --git a/src/config/config.ts b/src/config/config.ts index 269e31673..850aea668 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -38,7 +38,7 @@ const config = convict({ env: { doc: "The application environment.", env: "NODE_ENV", - format: ["dev", "test", "prod", "staging"], + format: ["dev", "test", "prod", "staging", "vapt"], default: "dev", }, port: { diff --git a/src/logger/logger.js b/src/logger/logger.js index 405008a4a..015593856 100644 --- a/src/logger/logger.js +++ b/src/logger/logger.js @@ -25,7 +25,7 @@ const metadataRequest = Bluebird.promisify( // TODO: Check this env var as it is not in example const LOG_GROUP_NAME = `${process.env.AWS_BACKEND_EB_ENV_NAME}/nodejs.log` const IS_PROD_ENV = - NODE_ENV !== "LOCAL_DEV" && NODE_ENV !== "DEV" && NODE_ENV !== "test" + NODE_ENV !== "dev" && NODE_ENV !== "staging" && NODE_ENV !== "test" const IS_TEST_ENV = NODE_ENV === "test" function timestampGenerator() { diff --git a/src/routes/v1/auth.js b/src/routes/v1/auth.js index 04d28c0d8..11f6f4ed4 100644 --- a/src/routes/v1/auth.js +++ b/src/routes/v1/auth.js @@ -1,5 +1,7 @@ import { config } from "@config/config" +import { isSecure } from "@root/utils/auth-utils" + const axios = require("axios") const express = require("express") const queryString = require("query-string") @@ -26,10 +28,8 @@ const router = express.Router() const CLIENT_ID = config.get("github.clientId") const CLIENT_SECRET = config.get("github.clientSecret") const REDIRECT_URI = config.get("github.redirectUri") -const AUTH_TOKEN_EXPIRY_MS = config.get("auth.tokenExpiry") const CSRF_TOKEN_EXPIRY_MS = 600000 const FRONTEND_URL = config.get("app.frontendUrl") -const NODE_ENV = config.get("env") const CSRF_COOKIE_NAME = "isomer-csrf" const COOKIE_NAME = "isomercms" @@ -53,8 +53,7 @@ async function authRedirect(req, res) { const cookieSettings = { expires: csrfTokenExpiry, httpOnly: true, - secure: - NODE_ENV !== "DEV" && NODE_ENV !== "LOCAL_DEV" && NODE_ENV !== "test", + secure: isSecure, } const token = jwtUtils.signToken({ state }) diff --git a/src/server.js b/src/server.js index b314baeb3..f8e80b693 100644 --- a/src/server.js +++ b/src/server.js @@ -47,7 +47,6 @@ import InfraService from "@services/infra/InfraService" import ReviewRequestService from "@services/review/ReviewRequestService" import { apiLogger } from "./middleware/apiLogger" -import { AuthorizationMiddleware } from "./middleware/authorization" import { NotificationOnEditHandler } from "./middleware/notificationOnEditHandler" import getAuthenticatedSubrouterV1 from "./routes/v1/authenticated" import getAuthenticatedSitesSubrouterV1 from "./routes/v1/authenticatedSites" @@ -58,6 +57,7 @@ import CollaboratorsService from "./services/identity/CollaboratorsService" import LaunchClient from "./services/identity/LaunchClient" import LaunchesService from "./services/identity/LaunchesService" import { rateLimiter } from "./services/utilServices/RateLimiter" +import { isSecure } from "./utils/auth-utils" const path = require("path") @@ -89,12 +89,8 @@ const express = require("express") const helmet = require("helmet") const createError = require("http-errors") -const NODE_ENV = config.get("env") const SESSION_SECRET = config.get("auth.sessionSecret") -const isSecure = - NODE_ENV !== "DEV" && NODE_ENV !== "LOCAL_DEV" && NODE_ENV !== "test" - const SequelizeStore = SequelizeStoreFactory(session.Store) const sessionMiddleware = session({ store: new SequelizeStore({ diff --git a/src/services/identity/index.ts b/src/services/identity/index.ts index 4c1abc804..a86b5226c 100644 --- a/src/services/identity/index.ts +++ b/src/services/identity/index.ts @@ -27,7 +27,7 @@ const NODE_ENV = config.get("env") const OTP_SECRET = config.get("auth.otpSecret") const OTP_EXPIRY = config.get("auth.otpExpiry") -const IS_LOCAL_DEV = NODE_ENV === "LOCAL_DEV" +const IS_DEV = NODE_ENV === "dev" // TODO: To remove TOTP const totpGenerator = new TotpGenerator({ @@ -35,7 +35,7 @@ const totpGenerator = new TotpGenerator({ expiry: OTP_EXPIRY, }) -const smsClient = IS_LOCAL_DEV +const smsClient = IS_DEV ? ({ sendSms: (_mobileNumber: string, message: string) => logger.info(message), } as SmsClient) diff --git a/src/services/utilServices/MailClient.ts b/src/services/utilServices/MailClient.ts index 2ff3110d0..99f8ab1cc 100644 --- a/src/services/utilServices/MailClient.ts +++ b/src/services/utilServices/MailClient.ts @@ -44,12 +44,10 @@ export default MailClient const NODE_ENV = config.get("env") const POSTMAN_API_KEY = config.get("postman.apiKey") -const IS_LOCAL_DEV = NODE_ENV === "LOCAL_DEV" +const IS_DEV = NODE_ENV === "dev" const mockMailer = { sendMail: (email: string, subject: string, html: string) => logger.info(`Mock email sent to <${email}>, subject: ${subject}\n${html}`), } as MailClient -export const mailer = IS_LOCAL_DEV - ? mockMailer - : new MailClient(POSTMAN_API_KEY) +export const mailer = IS_DEV ? mockMailer : new MailClient(POSTMAN_API_KEY) diff --git a/src/utils/auth-utils.js b/src/utils/auth-utils.js index 15ed4cfa3..57106bbe4 100644 --- a/src/utils/auth-utils.js +++ b/src/utils/auth-utils.js @@ -3,7 +3,7 @@ const { config } = require("@config/config") const NODE_ENV = config.get("env") function isSecure() { - return NODE_ENV !== "DEV" && NODE_ENV !== "LOCAL_DEV" && NODE_ENV !== "test" + return NODE_ENV !== "dev" && NODE_ENV !== "test" } module.exports = { diff --git a/src/utils/mutex-utils.js b/src/utils/mutex-utils.js index 7baacf9f4..80ac2a0de 100644 --- a/src/utils/mutex-utils.js +++ b/src/utils/mutex-utils.js @@ -11,8 +11,7 @@ const { ConflictError } = require("@errors/ConflictError") const NODE_ENV = config.get("env") const MUTEX_TABLE_NAME = config.get("mutexTableName") -const IS_LOCAL_DEV = - NODE_ENV === "LOCAL_DEV" || NODE_ENV === "test" || NODE_ENV === "vapt" +const IS_DEV = NODE_ENV === "dev" || NODE_ENV === "test" || NODE_ENV === "vapt" const mockMutexObj = {} // Dynamodb constants @@ -34,7 +33,7 @@ const lock = async (siteName) => { const ONE_MIN_FROM_CURR_DATE_IN_SECONDS_FROM_EPOCH_TIME = Math.floor(new Date().valueOf() / 1000) + 60 - if (!IS_LOCAL_DEV) { + if (!IS_DEV) { const params = { TableName: MUTEX_TABLE_NAME, Item: { @@ -60,7 +59,7 @@ const lock = async (siteName) => { } const unlock = async (siteName) => { - if (IS_LOCAL_DEV) return mockUnlock(siteName) + if (IS_DEV) return mockUnlock(siteName) try { const params = {