chore: add auth strategy test only x-cal-client-id (#23872)
This commit is contained in:
1 parent
59582cf8f5
commit
be249a94de
1 file changed
+24
-1
@@ -32,7 +32,7 @@ import { randomString } from "test/utils/randomString";
|
|||||||
import { X_CAL_CLIENT_ID, X_CAL_SECRET_KEY } from "@calcom/platform-constants";
|
import { X_CAL_CLIENT_ID, X_CAL_SECRET_KEY } from "@calcom/platform-constants";
|
||||||
import type { PlatformOAuthClient, Team, User } from "@calcom/prisma/client";
|
import type { PlatformOAuthClient, Team, User } from "@calcom/prisma/client";
|
||||||
|
|
||||||
import { ApiAuthGuardRequest } from "./api-auth.strategy";
|
import { ApiAuthGuardRequest, ONLY_CLIENT_ID_PROVIDED_MESSAGE } from "./api-auth.strategy";
|
||||||
import { ApiAuthStrategy } from "./api-auth.strategy";
|
import { ApiAuthStrategy } from "./api-auth.strategy";
|
||||||
|
|
||||||
describe("ApiAuthStrategy", () => {
|
describe("ApiAuthStrategy", () => {
|
||||||
@@ -244,6 +244,29 @@ describe("ApiAuthStrategy", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should throw 401 if only OAuth ID is provided", async () => {
|
||||||
|
const context: ExecutionContext = {
|
||||||
|
switchToHttp: () => ({
|
||||||
|
getRequest: () => ({
|
||||||
|
headers: {
|
||||||
|
[X_CAL_CLIENT_ID]: `${oAuthClient.id}gibberish`,
|
||||||
|
},
|
||||||
|
get: (key: string) => ({ origin: "http://localhost:3000" }[key]),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
} as ExecutionContext;
|
||||||
|
const request = context.switchToHttp().getRequest();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await strategy.authenticate(request);
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof HttpException) {
|
||||||
|
expect(error.getStatus()).toEqual(401);
|
||||||
|
expect(error.message).toContain(ONLY_CLIENT_ID_PROVIDED_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it("should throw 401 if OAuth ID is invalid", async () => {
|
it("should throw 401 if OAuth ID is invalid", async () => {
|
||||||
const context: ExecutionContext = {
|
const context: ExecutionContext = {
|
||||||
switchToHttp: () => ({
|
switchToHttp: () => ({
|
||||||
|
|||||||
Reference in new issue
Block a user