Skip to content

Commit 9c08f45

Browse files
committed
[scramjet/runway] add basic incumbency tests
1 parent 6737dd2 commit 9c08f45

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { serverTest } from "../testcommon.ts";
2+
3+
const doc = (text: string) => `<!doctype html>${text}`;
4+
5+
function navIncumbenceTest(props: {
6+
name: string;
7+
js: string;
8+
reverse?: boolean;
9+
topjs?: string;
10+
}) {
11+
props.topjs ??= "";
12+
props.reverse ??= false;
13+
return serverTest({
14+
name: props.name,
15+
async start(server, port, { pass, fail }) {
16+
server.on("request", (req, res) => {
17+
if (req.url! === "/") {
18+
res.setHeader("Content-Type", "text/html");
19+
res.end(
20+
doc(`<script>${props.topjs}</script><iframe src="/dir/frame.html">`)
21+
);
22+
} else if (req.url! === "/dir/frame.html") {
23+
res.setHeader("Content-Type", "text/html");
24+
res.end(doc(`<script>${props.js}</script>`));
25+
} else if (req.url! === "/dir/flag.html") {
26+
res.setHeader("Content-Type", "text/html");
27+
if (props.reverse) {
28+
res.end(doc(`<script>opener.fail("wrong window opened")</script>`));
29+
} else {
30+
res.end(
31+
doc(`<script>opener.pass("correct window opened")</script>`)
32+
);
33+
}
34+
} else if (req.url! === "/flag.html") {
35+
res.setHeader("Content-Type", "text/html");
36+
if (props.reverse) {
37+
res.end(
38+
doc(`<script>opener.pass("correct window opened")</script>`)
39+
);
40+
} else {
41+
res.end(doc(`<script>opener.fail("wrong window opened")</script>`));
42+
}
43+
} else {
44+
res.statusCode = 404;
45+
console.error("Not Found: " + req.url);
46+
res.end();
47+
}
48+
});
49+
},
50+
});
51+
}
52+
53+
export default [
54+
navIncumbenceTest({
55+
name: "incumbent-window-open-sanity",
56+
js: "window.open('flag.html')",
57+
}),
58+
navIncumbenceTest({
59+
name: "incumbent-window-open-crossrealm",
60+
js: "parent.window.open('flag.html')",
61+
}),
62+
navIncumbenceTest({
63+
name: "incumbent-window-open-functioncall",
64+
topjs: `function doOpen(){ window.open('flag.html') }`,
65+
js: "parent.doOpen()",
66+
}),
67+
navIncumbenceTest({
68+
name: "incumbent-window-open-eval",
69+
js: "parent.eval('window.open(`flag.html`)')",
70+
}),
71+
navIncumbenceTest({
72+
name: "incumbent-window-open-eval-functioncall",
73+
topjs: `function doOpen(){ window.open('flag.html') }`,
74+
js: "parent.eval('doOpen()')",
75+
}),
76+
navIncumbenceTest({
77+
name: "incumbent-window-open-functionctor",
78+
js: "new parent.Function('window.open(`flag.html`)')()",
79+
}),
80+
navIncumbenceTest({
81+
name: "incumbent-window-open-settimeout",
82+
reverse: true,
83+
js: "parent.setTimeout('window.open(`flag.html`)')",
84+
}),
85+
// navIncumbenceTest({
86+
// name: "incumbent-location-sanity",
87+
// js: "location = 'flag.html'",
88+
// }),
89+
// navIncumbenceTest({
90+
// name: "incumbent-location-crossrealm",
91+
// js: "parent.window.location = 'flag.html'",
92+
// }),
93+
// navIncumbenceTest({
94+
// name: "incumbent-window-open-functioncall",
95+
// topjs: `function doOpen(){ window.location ='flag.html' }`,
96+
// js: "parent.doOpen()",
97+
// }),
98+
];

0 commit comments

Comments
 (0)