Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes the function to verify cron auth token #191

Merged
merged 9 commits into from
Jan 30, 2024
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
Loading