-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware_test.ts
99 lines (89 loc) · 2.38 KB
/
middleware_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { coep } from "./middleware.ts";
import {
assert,
describe,
EmbedderPolicyValue,
equalsResponse,
it,
PolicyHeader,
} from "./_dev_deps.ts";
describe("coep", () => {
it("should return same response if the response include the header", async () => {
const middleware = coep();
const initResponse = new Response(null, {
headers: {
[PolicyHeader.CrossOriginEmbedderPolicy]: "",
},
});
const response = await middleware(
new Request("test:"),
() => initResponse,
);
assert(response === initResponse);
});
it("should return response what include coep header and the value is require-corp by default", async () => {
const middleware = coep();
const response = await middleware(
new Request("test:"),
() => new Response(),
);
assert(equalsResponse(
response,
new Response(null, {
headers: {
[PolicyHeader.CrossOriginEmbedderPolicy]:
EmbedderPolicyValue.RequireCorp,
},
}),
));
});
it("should change coep header via arg", async () => {
const middleware = coep({ policy: EmbedderPolicyValue.UnsafeNone });
const response = await middleware(
new Request("test:"),
() => new Response(),
);
assert(equalsResponse(
response,
new Response(null, {
headers: {
[PolicyHeader.CrossOriginEmbedderPolicy]:
EmbedderPolicyValue.UnsafeNone,
},
}),
));
});
it("should add report-to param via endpoint", async () => {
const reportTo = "default";
const middleware = coep({ reportTo });
const response = await middleware(
new Request("test:"),
() => new Response(),
);
assert(equalsResponse(
response,
new Response(null, {
headers: {
[PolicyHeader.CrossOriginEmbedderPolicy]:
`${EmbedderPolicyValue.RequireCorp};report-to=${reportTo}`,
},
}),
));
});
it("should change to report only header", async () => {
const middleware = coep({ reportOnly: true });
const response = await middleware(
new Request("test:"),
() => new Response(),
);
assert(equalsResponse(
response,
new Response(null, {
headers: {
[PolicyHeader.CrossOriginEmbedderPolicyReportOnly]:
EmbedderPolicyValue.RequireCorp,
},
}),
));
});
});