forked from Yara724/api
Merge pull request 'fix: enforce fake_otp variable to be false while in production' (#365) from s.yahyaee/yara724-api:main into main
Reviewed-on: Yara724/api#365
This commit is contained in:
@@ -25,6 +25,10 @@ export class EnvironmentVariables {
|
||||
})
|
||||
NODE_ENV: Environment;
|
||||
|
||||
@IsOptional()
|
||||
@IsBooleanString({ message: "FAKE_OTP must be boolean" })
|
||||
FAKE_OTP?: string;
|
||||
|
||||
// --------------------------------------------------------- //
|
||||
|
||||
@IsNumber(
|
||||
|
||||
@@ -14,6 +14,15 @@ export function validate(config: Record<string, unknown>) {
|
||||
throw new Error("AI_DAMAGE_URL is required when AI_DAMAGE_ENABLED=true");
|
||||
}
|
||||
|
||||
if (
|
||||
validatedConfig.NODE_ENV === "production" &&
|
||||
String(validatedConfig.FAKE_OTP ?? "").toLowerCase() === "true"
|
||||
) {
|
||||
throw new Error(
|
||||
"FAKE_OTP must be disabled in production so login codes are delivered by the configured SMS provider",
|
||||
);
|
||||
}
|
||||
|
||||
const errors = validateSync(validatedConfig, {
|
||||
skipMissingProperties: false,
|
||||
});
|
||||
|
||||
@@ -885,5 +885,11 @@ describe("Swagger and local validation", () => {
|
||||
expect(() =>
|
||||
validate({ ...base, OPENAI_PRICE_ESTIMATION_TIMEOUT_MS: 600001 }),
|
||||
).toThrow();
|
||||
expect(() =>
|
||||
validate({ ...base, NODE_ENV: "production", FAKE_OTP: "true" }),
|
||||
).toThrow("FAKE_OTP must be disabled in production");
|
||||
expect(() =>
|
||||
validate({ ...base, NODE_ENV: "production", FAKE_OTP: "false" }),
|
||||
).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user