fix: header inspector cookie inspection will not trigger if current interceptor supports cookies
This commit is contained in:
@@ -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 })
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user