Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
fix: header inspector cookie inspection will not trigger if current interceptor supports cookies
Andrew Bastin736f83a70c9a
diff --git a/packages/hoppscotch-common/src/services/inspection/inspectors/__tests__/header.inspector.spec.ts b/packages/hoppscotch-common/src/services/inspection/inspectors/__tests__/header.inspector.spec.tsindex cd4c50e2d..db05fe573 100644--- a/packages/hoppscotch-common/src/services/inspection/inspectors/__tests__/header.inspector.spec.ts+++ b/packages/hoppscotch-common/src/services/inspection/inspectors/__tests__/header.inspector.spec.ts@@ -4,6 +4,7 @@ import { HeaderInspectorService } from "../header.inspector"import { InspectionService } from "../../index"import { getDefaultRESTRequest } from "~/helpers/rest/default"import { ref } from "vue"+import { InterceptorService } from "~/services/interceptor.service"vi.mock("~/modules/i18n", () => ({__esModule: true,@@ -58,5 +59,48 @@ describe("HeaderInspectorService", () => {expect(result.value).toHaveLength(0)})++ it("should return an empty array when headers contain cookies but interceptor supports cookies", () => {+ const container = new TestContainer()++ container.bindMock(InterceptorService, {+ currentInterceptor: ref({ supportsCookies: true }) as any,+ })++ const headerInspector = container.bind(HeaderInspectorService)++ const req = ref({+ ...getDefaultRESTRequest(),+ endpoint: "http://example.com/api/data",+ headers: [{ key: "Cookie", value: "some-cookie", active: true }],+ })++ const result = headerInspector.getInspections(req)++ expect(result.value).toHaveLength(0)+ })++ it("should return an inspector result when headers contain cookies and the current interceptor doesn't support cookies", () => {+ const container = new TestContainer()++ container.bindMock(InterceptorService, {+ currentInterceptor: ref({ supportsCookies: false }) as any,+ })++ const headerInspector = container.bind(HeaderInspectorService)++ const req = ref({+ ...getDefaultRESTRequest(),+ endpoint: "http://example.com/api/data",+ headers: [{ key: "Cookie", value: "some-cookie", active: true }],+ })++ const result = headerInspector.getInspections(req)++ expect(result.value).not.toHaveLength(0)+ expect(result.value).toContainEqual(+ expect.objectContaining({ id: "header", isApplicable: true })+ )+ })})})diff --git a/packages/hoppscotch-common/src/services/inspection/inspectors/header.inspector.ts b/packages/hoppscotch-common/src/services/inspection/inspectors/header.inspector.tsindex 5ac612b50..3f8b893f3 100644--- a/packages/hoppscotch-common/src/services/inspection/inspectors/header.inspector.ts+++ b/packages/hoppscotch-common/src/services/inspection/inspectors/header.inspector.ts@@ -4,6 +4,7 @@ import { getI18n } from "~/modules/i18n"import { HoppRESTRequest } from "@hoppscotch/data"import { Ref, computed, markRaw } from "vue"import IconAlertTriangle from "~icons/lucide/alert-triangle"+import { InterceptorService } from "~/services/interceptor.service"/*** This inspector is responsible for inspecting the header of a request.@@ -19,6 +20,7 @@ export class HeaderInspectorService extends Service implements Inspector {public readonly inspectorID = "header"private readonly inspection = this.bind(InspectionService)+ private readonly interceptorService = this.bind(InterceptorService)constructor() {super()@@ -42,7 +44,10 @@ export class HeaderInspectorService extends Service implements Inspector {const isContainCookies = headerKeys.includes("Cookie")- if (isContainCookies) {+ if (+ isContainCookies &&+ !this.interceptorService.currentInterceptor.value?.supportsCookies+ ) {headerKeys.forEach((headerKey, index) => {if (this.cookiesCheck(headerKey)) {results.push({