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
|
"use strict";
const { HttpServer } = ChromeUtils.importESModule(
"resource://testing-common/httpd.sys.mjs"
);
var httpserver = new HttpServer();
var index = 0;
var tests = [
{ url: "/test/test", datalen: 16 },
// Test that the http channel fails and the response body is suppressed
// bug 255119
{
url: "/test/test",
responseheader: ["Location: javascript:alert()"],
flags: CL_EXPECT_FAILURE,
datalen: 0,
},
];
function setupChannel(url) {
return NetUtil.newChannel({
uri: "http://localhost:" + httpserver.identity.primaryPort + url,
loadUsingSystemPrincipal: true,
});
}
function startIter() {
var channel = setupChannel(tests[index].url);
channel.asyncOpen(
new ChannelListener(completeIter, channel, tests[index].flags)
);
}
function completeIter(request, data, ctx) {
Assert.ok(data.length == tests[index].datalen);
if (++index < tests.length) {
startIter();
} else {
httpserver.stop(do_test_finished);
}
}
function run_test() {
httpserver.registerPathHandler("/test/test", handler);
httpserver.start(-1);
startIter();
do_test_pending();
}
function handler(metadata, response) {
var body = "thequickbrownfox";
response.setHeader("Content-Type", "text/plain", false);
var header = tests[index].responseheader;
if (header != undefined) {
for (var i = 0; i < header.length; i++) {
var splitHdr = header[i].split(": ");
response.setHeader(splitHdr[0], splitHdr[1], false);
}
}
response.setStatusLine(metadata.httpVersion, 302, "Redirected");
response.bodyOutputStream.write(body, body.length);
}
|