fix: header inspector cookie inspection will not trigger if current interceptor supports cookies

This commit is contained in:
Andrew Bastin
2023-11-07 20:36:34 +05:30
parent 05d2175f43
commit 736f83a70c
2 changed files with 50 additions and 1 deletions

View File

@@ -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 })
)
})
})
})

View File

@@ -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({