From 61f16584c9ba4287a93790d8d7f90b5bcb175476 Mon Sep 17 00:00:00 2001 From: Bruce Berrios <58147810+Bruception@users.noreply.github.com> Date: Tue, 22 Feb 2022 17:02:37 -0500 Subject: [PATCH] Action anti cheat step (#2570) * Add anti-cheat check * Add anti-cheat step * Test * Revert * . * Fix --- .github/workflows/pr-check.yml | 6 ++++++ backend/api/routes/results.js | 12 +++++++++++- backend/constants/base-configuration.ts | 3 +++ backend/server.ts | 4 ++-- backend/types/types.d.ts | 3 +++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 595bcd1fb..0066d86d5 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -35,9 +35,15 @@ jobs: ts: - 'frontend/**/*.js' - 'frontend/**/*.ts' + anti-cheat: + - 'backend/**/anticheat/**' - run: echo ${{ steps.filter.outputs.changes }} + - name: Check Anti-cheat + if: steps.filter.outputs.anti-cheat == 'true' + run: exit 1 + - name: Cache node modules if: steps.filter.outputs.changes != '[]' uses: actions/cache@v2 diff --git a/backend/api/routes/results.js b/backend/api/routes/results.js index 9a9b02866..0344089bc 100644 --- a/backend/api/routes/results.js +++ b/backend/api/routes/results.js @@ -1,6 +1,10 @@ import ResultController from "../controllers/result"; import resultSchema from "../schemas/result-schema"; -import { asyncHandler, validateRequest } from "../../middlewares/api-utils"; +import { + asyncHandler, + validateRequest, + validateConfiguration, +} from "../../middlewares/api-utils"; import * as RateLimit from "../../middlewares/rate-limit"; import { Router } from "express"; import { authenticateRequest } from "../../middlewares/auth"; @@ -17,6 +21,12 @@ router.get( router.post( "/", + validateConfiguration({ + criteria: (configuration) => { + return configuration.enableSavingResults.enabled; + }, + invalidMessage: "Results are not being saved at this time.", + }), RateLimit.resultsAdd, authenticateRequest(), validateRequest({ diff --git a/backend/constants/base-configuration.ts b/backend/constants/base-configuration.ts index 6d74ef373..d50488ec2 100644 --- a/backend/constants/base-configuration.ts +++ b/backend/constants/base-configuration.ts @@ -19,6 +19,9 @@ const BASE_CONFIGURATION: MonkeyTypes.Configuration = { monkeyTokens: { enabled: false, }, + enableSavingResults: { + enabled: false, + }, }; export default Object.freeze(BASE_CONFIGURATION); diff --git a/backend/server.ts b/backend/server.ts index b35c08d5b..907e0d63f 100644 --- a/backend/server.ts +++ b/backend/server.ts @@ -2,7 +2,7 @@ import "dotenv/config"; import admin, { ServiceAccount } from "firebase-admin"; import serviceAccount from "./credentials/serviceAccountKey.json"; import db from "./init/db.js"; -import jobs from "./jobs/index.js"; +import jobs from "./jobs"; import ConfigurationDAO from "./dao/configuration.js"; import app from "./app"; @@ -16,7 +16,7 @@ async function bootServer(port) { admin.initializeApp({ credential: admin.credential.cert( serviceAccount as unknown as ServiceAccount - ) + ), }); console.log("Firebase app initialized"); diff --git a/backend/types/types.d.ts b/backend/types/types.d.ts index 2fdabba0c..086de9479 100644 --- a/backend/types/types.d.ts +++ b/backend/types/types.d.ts @@ -17,6 +17,9 @@ declare namespace MonkeyTypes { monkeyTokens: { enabled: boolean; }; + enableSavingResults: { + enabled: boolean; + }; } interface Context {