2012-08-14 07:06:04 -07:00
|
|
|
Cu.import("resource://testing-common/httpd.js");
|
|
|
|
|
|
|
|
var httpserver = new HttpServer();
|
2012-03-22 16:39:31 -07:00
|
|
|
var currentTestIndex = 0;
|
2013-07-19 10:19:28 -07:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "port", function() {
|
|
|
|
return httpserver.identity.primaryPort;
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "tests", function() {
|
|
|
|
return [
|
|
|
|
// this is valid
|
|
|
|
{url: "/assoc/assoctest?valid",
|
|
|
|
responseheader: ["Assoc-Req: GET http://localhost:" + port +
|
|
|
|
"/assoc/assoctest?valid",
|
|
|
|
"Pragma: X-Verify-Assoc-Req"],
|
|
|
|
flags: 0},
|
|
|
|
|
|
|
|
// this is invalid because the method is wrong
|
|
|
|
{url: "/assoc/assoctest?invalid",
|
|
|
|
responseheader: ["Assoc-Req: POST http://localhost:" + port +
|
|
|
|
"/assoc/assoctest?invalid",
|
|
|
|
"Pragma: X-Verify-Assoc-Req"],
|
|
|
|
flags: CL_EXPECT_LATE_FAILURE},
|
|
|
|
|
|
|
|
// this is invalid because the url is wrong
|
|
|
|
{url: "/assoc/assoctest?notvalid",
|
|
|
|
responseheader: ["Assoc-Req: GET http://localhost:" + port +
|
|
|
|
"/wrongpath/assoc/assoctest?notvalid",
|
|
|
|
"Pragma: X-Verify-Assoc-Req"],
|
|
|
|
flags: CL_EXPECT_LATE_FAILURE},
|
2012-03-22 16:39:31 -07:00
|
|
|
|
|
|
|
// this is invalid because the space between method and URL is missing
|
2013-07-19 10:19:28 -07:00
|
|
|
{url: "/assoc/assoctest?invalid2",
|
|
|
|
responseheader: ["Assoc-Req: GEThttp://localhost:" + port +
|
|
|
|
"/assoc/assoctest?invalid2",
|
|
|
|
"Pragma: X-Verify-Assoc-Req"],
|
|
|
|
flags: CL_EXPECT_LATE_FAILURE},
|
|
|
|
];
|
|
|
|
});
|
2012-03-22 16:39:31 -07:00
|
|
|
|
|
|
|
var oldPrefVal;
|
|
|
|
var domBranch;
|
|
|
|
|
|
|
|
function setupChannel(url)
|
|
|
|
{
|
|
|
|
var ios = Components.classes["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService);
|
2013-07-19 10:19:28 -07:00
|
|
|
var chan = ios.newChannel("http://localhost:" + port + url, "", null);
|
2012-03-22 16:39:31 -07:00
|
|
|
return chan;
|
|
|
|
}
|
|
|
|
|
|
|
|
function startIter()
|
|
|
|
{
|
|
|
|
var channel = setupChannel(tests[currentTestIndex].url);
|
|
|
|
channel.asyncOpen(new ChannelListener(completeIter,
|
|
|
|
channel, tests[currentTestIndex].flags), null);
|
|
|
|
}
|
|
|
|
|
|
|
|
function completeIter(request, data, ctx)
|
|
|
|
{
|
|
|
|
if (++currentTestIndex < tests.length ) {
|
|
|
|
startIter();
|
|
|
|
} else {
|
|
|
|
domBranch.setBoolPref("enforce", oldPrefVal);
|
|
|
|
httpserver.stop(do_test_finished);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_test()
|
|
|
|
{
|
|
|
|
var prefService =
|
|
|
|
Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefService);
|
|
|
|
domBranch = prefService.getBranch("network.http.assoc-req.");
|
|
|
|
oldPrefVal = domBranch.getBoolPref("enforce");
|
|
|
|
domBranch.setBoolPref("enforce", true);
|
|
|
|
|
|
|
|
httpserver.registerPathHandler("/assoc/assoctest", handler);
|
2013-07-19 10:19:28 -07:00
|
|
|
httpserver.start(-1);
|
2012-03-22 16:39:31 -07:00
|
|
|
|
|
|
|
startIter();
|
|
|
|
do_test_pending();
|
|
|
|
}
|
|
|
|
|
|
|
|
function handler(metadata, response)
|
|
|
|
{
|
|
|
|
var body = "thequickbrownfox";
|
|
|
|
response.setHeader("Content-Type", "text/plain", false);
|
|
|
|
|
|
|
|
var header = tests[currentTestIndex].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, 200, "OK");
|
|
|
|
response.bodyOutputStream.write(body, body.length);
|
|
|
|
}
|