Skip to content

Commit

Permalink
Merge pull request #191 from Real-Dev-Squad/chore/verify-cron-token
Browse files Browse the repository at this point in the history
Changes the function to verify cron auth token
  • Loading branch information
prakashchoudhary07 authored Jan 30, 2024
2 parents 33a2957 + 8e7ba27 commit ecd84ed
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/controllers/guildRoleHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
createNewRole,
memberGroupRole,
} from "../typeDefinitions/discordMessage.types";
import { verifyAuthToken } from "../utils/verifyAuthToken";
import { verifyAuthToken, verifyCronJobsToken } from "../utils/verifyAuthToken";
import { batchDiscordRequests } from "../utils/batchDiscordRequests";
import { DISCORD_BASE_URL } from "../constants/urls";
import { GROUP_ROLE_ADD } from "../constants/requestsActions";
Expand Down Expand Up @@ -59,8 +59,13 @@ export async function getGuildRolesPostHandler(request: IRequest, env: env) {
const reason = request.headers.get("X-Audit-Log-Reason");

try {
await verifyAuthToken(authHeader, env);
const { action } = request.query;
const { action, dev } = request.query;
//TODO(@Ajeyakrishna-k): remove dev flag https://github.com/Real-Dev-Squad/discord-slash-commands/issues/193
if (dev === "true") {
await verifyCronJobsToken(authHeader, env);
} else {
await verifyAuthToken(authHeader, env);
}

switch (action) {
case GROUP_ROLE_ADD.ADD_ROLE: {
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const dummyAddRoleBody: memberGroupRole = {
export const guildEnv = {
DISCORD_GUILD_ID: "1234",
DISCORD_TOKEN: "abcd",
CRON_JOBS_PUBLIC_KEY: "test",
};

export const dummyInviteBody = {
Expand Down
1 change: 1 addition & 0 deletions tests/unit/handlers/guildRoleHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { GROUP_ROLE_ADD } from "../../../src/constants/requestsActions";

jest.mock("../../../src/utils/verifyAuthToken", () => ({
verifyAuthToken: jest.fn().mockReturnValue(true),
verifyCronJobsToken: jest.fn().mockReturnValue(true),
}));

const getGuildRolesSpy = jest.spyOn(guildRoleUtils, "getGuildRoles");
Expand Down

0 comments on commit ecd84ed

Please sign in to comment.