Skip to content

Commit

Permalink
Merge pull request #41 from VSchool/update-interval
Browse files Browse the repository at this point in the history
disable location check for now
  • Loading branch information
v-school authored Mar 13, 2024
2 parents 0ad634c + 4ac9acb commit 2707fdc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .env.vault
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#/--------------------------------------------------/

# development
DOTENV_VAULT_DEVELOPMENT="DelsMBqLYnsobM+tDYKYM3htZ/oPL+G4dQVeCw8H0qplhiZZW316lf5SVNm+ccsTBHo+HDcdNlFPWXQpEScnwVllRrGbJuHn0icwpG3lq38WfP1eGzRl1I0+XvUFsgAL6tZM4Z95ViGIE/pFhagMx+QDQMyopP8iRxvJuSsKn0nlIk0yb0BJ7JCxDEK3GM/Ch1wNscBiexAGUH+ypkC9JKCttQrYFPJQMvhGbOeKV0eZRAxEVFSagn1cwi6dHiVWyO/Wh4O2GNTHAypegxacjUqJYdlUfSUKhUxBascEeYIsaSbJFHDGsi2DIG6iMQFNIOAv0dbbAhvEVB4J6zJWGyNAaLWxMBMGCOr5tZXh4yWVl0re4zQ126I4dj0VVcU0TLEPFdWmT2hgJHC8S6Q8fZTZ3JLDhFx5+8IesjxnQD9cNzBs3xP0s6BKFOnUrbkFKMmI2jwGA/E2h/Y10HqDmAB1Qx5fR5fNCRDzN0Ca4vXJwCFih2AmhSOS60aejfsX9g7LeLlUoCGRh/4uO4Yc/N2jj5IAJKfss7jzG0SwOh5pfd7iN1914kwJUoCtOv63fB7L4leDjzica9x1MbG2/lvwpP8fu5PTjj6hyq9MMAALqWczkvV3EnnVzSCwwEgYWb7Bgy6ddSDaPnOrOl+aR0B0M6ZH7jRQpH8Of74JyaHpmK8wBztR2YDLPQVXMDqCwboxtpA1DrKeIiRX/KPvUT6VbmazSOvpuADaWxaWo5+i3HgUFOi+cessJhFMV7F6zktZzzRulPQYN6wxSOf3xhAZ1x2dgiI0UTYyx3sT9HcJN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21ovxMQHN5qS3d0fTyvYiiMz1Zduwbz2wfFEg03FX2LI4sHduMSLByrbgHcwgG7JmVfMyeBfB/EX7njcwgwuTcS+pJODmcVs1hy49pdvjAsitLxiMw7V9/RQHbFa2m6ksS5QULDwFkseRHOzYprCa454rGqZ/kS0uvPZR0z8bHPzk2+wjIxOcJcEVMglN0PXPPcN3bbqrmhytn5n4OBz2TGG1yBzv+wZb5Wd7oMa9+244hqbQ8kzsvWIBPlhKxnczAMFYHjZ98Vw76XPXFAkkm0GoSkv4Z+2tNdqCC50DQusb7gHVfSkmRkwOvo/Es2ExEKEBlHhmj3LBEBfCQHF2hNMa89Jc7bugdfdMGAnqkWsjFITQMYG1Hj/VC374HwBwLSMEaMkObFL7fPU4+NavGq6yPXcz3/PXQR+4TeSdVj/Yd3IKSnTfIvQfV9g1jMKY9YIZ/sTr/vJNwRm7pDoD1/s/V3CVwFPx42Qsr7kyVN1HgcorP6Vb2rAjo/mUbmkomfAamgjteFaArpfS9QlFAKQDflwNollA2yecjIh+qjdj7dFpql9Ih/TI="
Expand Down
27 changes: 18 additions & 9 deletions src/routers/qr-code.router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ const signSpy = jest.spyOn(jwt, "sign");

describe("qr-code-router.ts", () => {
describe("GET /api/qr-code/generate", () => {
it("Should bypass location check in dev environment and generate a QR code as a base64 encoded png and an access code with configured expiration date", async () => {
it("Should generate a QR code as a base64 encoded png and an access code with configured expiration date", async () => {
const getLocationCoordinatesSpy = jest.spyOn(
locationService,
"getLocationCoordinates",
);
const isProductionEnvSpy = jest.spyOn(utils, "isProductionEnv");
isProductionEnvSpy.mockReturnValue(false);
const isLocationCheckEnabledSpy = jest.spyOn(
utils,
"isLocationCheckEnabled",
);
isLocationCheckEnabledSpy.mockReturnValue(false);

const response = await mockServer().get("/api/qr-code/generate");
expect(response.headers["content-type"]).toContain("application/json");
expect(getLocationCoordinatesSpy).toHaveBeenCalledTimes(0);
expect(isProductionEnvSpy).toHaveReturnedWith(false);
expect(isLocationCheckEnabledSpy).toHaveReturnedWith(false);
expect(response.body.dataUrl).toContain(
"data:image/png;base64,iVBORw0KGgo",
);
Expand All @@ -34,15 +37,18 @@ describe("qr-code-router.ts", () => {
);
});

it("Should perform location check in prod environment and generate a QR code as a base64 encoded png and an access code with configured expiration date", async () => {
it("Should perform location check if enabled and generate a QR code as a base64 encoded png and an access code with configured expiration date", async () => {
const getLocationCoordinatesSpy = jest.spyOn(
locationService,
"getLocationCoordinates",
);
const isProductionEnvSpy = jest.spyOn(utils, "isProductionEnv");
const isLocationCheckEnabledSpy = jest.spyOn(
utils,
"isLocationCheckEnabled",
);
const validateCoordsSpy = jest.spyOn(utils, "validateCoords");

isProductionEnvSpy.mockReturnValue(true);
isLocationCheckEnabledSpy.mockReturnValue(true);
getLocationCoordinatesSpy.mockResolvedValue({
latitude: 100,
longitude: 100,
Expand All @@ -69,10 +75,13 @@ describe("qr-code-router.ts", () => {
locationService,
"getLocationCoordinates",
);
const isProductionEnvSpy = jest.spyOn(utils, "isProductionEnv");
const isLocationCheckEnabledSpy = jest.spyOn(
utils,
"isLocationCheckEnabled",
);
const validateCoordsSpy = jest.spyOn(utils, "validateCoords");

isProductionEnvSpy.mockReturnValue(true);
isLocationCheckEnabledSpy.mockReturnValue(true);
getLocationCoordinatesSpy.mockResolvedValue({
latitude: 100,
longitude: 100,
Expand Down
6 changes: 3 additions & 3 deletions src/routers/qr-code.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import {
import { generateAccessToken } from "../services/auth.service";
import { validateAccessToken } from "../middleware";
import { getLocationCoordinates } from "../services/location.service";
import { isProductionEnv, parseIp, validateCoords } from "../utils";
import { isLocationCheckEnabled, parseIp, validateCoords } from "../utils";

const qrCodeRouter = ex.Router();

qrCodeRouter.get("/generate", async (req, res, next) => {
try {
const ip = parseIp(req);

if (isProductionEnv()) {
if (isLocationCheckEnabled()) {
const coords = await getLocationCoordinates(ip as string);
console.log('Validating location of IP: ' + ip, coords)
console.log("Validating location of IP: " + ip, coords);
if (!validateCoords(coords)) throw Error("Invalid location of request");
}
const accessToken = generateAccessToken();
Expand Down
14 changes: 13 additions & 1 deletion src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { parseEntryFilterQueryParams, validateCoords } from "./utils";
import {
isLocationCheckEnabled,
parseEntryFilterQueryParams,
validateCoords,
} from "./utils";

describe("utils.ts", () => {
describe("parseEntryFilterQueryParams()", () => {
Expand Down Expand Up @@ -32,4 +36,12 @@ describe("utils.ts", () => {
).toBe(false);
});
});

describe("isLocationCheckEnabled", () => {
it("Should return true or false based on process.env.ENABLE_LOCATION_CHECK value", () => {
expect(isLocationCheckEnabled()).toBe(
JSON.parse(process.env.ENABLE_LOCATION_CHECK as string),
);
});
});
});
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ export const parseIp = (req: Request): string => {

export const isProductionEnv = () =>
!["test", "development"].includes(process.env.NODE_ENV as string);

export const isLocationCheckEnabled = () => {
return process.env.ENABLE_LOCATION_CHECK === "true";
};

0 comments on commit 2707fdc

Please sign in to comment.