mirror of
https://github.com/Netflix/dial-reference.git
synced 2026-06-08 19:09:59 +00:00
94 lines
4.0 KiB
JavaScript
94 lines
4.0 KiB
JavaScript
"use strict";
|
||
|
||
var dial = require("../libs/dialClient.js"),
|
||
utils = require("../libs/utils.js"),
|
||
Q = require("q"),
|
||
winston = require("winston");
|
||
|
||
|
||
const argv = require("yargs")
|
||
.usage("\nUsage: node " + __filename.slice(__dirname.length + 1) + "[options]")
|
||
.option("host", {
|
||
describe: "IP address of host on which DIAL server under test is running",
|
||
type: "string",
|
||
demand: true
|
||
})
|
||
.help("help").alias("help", "h").argv;
|
||
|
||
var testCount = 0;
|
||
var failureCount = 0;
|
||
|
||
/*
|
||
* These edge cases are
|
||
*/
|
||
function edgeCases() {
|
||
var host = argv.host;
|
||
|
||
var methods = [
|
||
"GET",
|
||
"POST",
|
||
];
|
||
|
||
// weird data
|
||
var headers = [
|
||
{"Content-Length": "0xff1af1581"},
|
||
{"Content-Length": "sfsadfdsat"},
|
||
{"Content-Length": 13377777777777},
|
||
{"Content-Length": -13377777777777},
|
||
{"Content-Type": "text/plain;charset=\"utf-8\""},
|
||
{"Content-Type": "text/plain;charset=\"ascii\""},
|
||
{"Content-Type": "asdoffmoaserq"},
|
||
{"Foo": "Bar"},
|
||
];
|
||
|
||
var utf8 = ";(QmN̸鱏=叽]𰸹h˳╭ܮ煣ِt𐍁J픖pЗB-ٴۼ퍃%۞灱Ҡɝ~2望Lԇƀݛ&±⫯WܾNJX礴ēʧ耉ݭpi}Ǖʝ'䬿^ٿ]샑좘쒾"
|
||
+ "ԝbւ蹈ۥ웦(歉貤䃶6ƢӋØ𪺭ĩk┋譒ց,Ŋ칱آ3㛣Oܕ=裁fĴjٕpۅ=@ԉ'1⃮Ȩ핣ƺ匽ݚ뎔叇χ&죙𱘱ʴذȞ鞾ﰟO썟X9⛥ȧ走쾙"
|
||
+ "ӱإ#!۵Σƀ4䦼쪭ϖ0ڧp梛՚嬆߷域᳁١ޜۡÜ]ʘ厤ȆwYݖ(ן饲a<61>`V<$Dz&ܗʧbҘ@E1ч&{㜃팸儈Ā㖿rb^Ӟʶ"
|
||
+ "Ө㡷sΠ●ŽٗDҤƱ(t-瞜BЏ;Ғeࡻs`=ݔu樭迕^;䐈Ǥ3䝡XM붩ݱϖȓܕ췃`Ỷ3LV9폧赹ⴢ+⇩ӛ뵖띟䎵钥¶繥Ҕ J礢м2_8̑hg";
|
||
utf8 = utf8 + utf8 + utf8;
|
||
var strings = [
|
||
utf8,
|
||
"",
|
||
'<a href="\x19javascript:javascript:alert(1)" id="fuzzelement1">test</a>\n',
|
||
'$HOME',
|
||
'../../../../../../../../../../../etc/hosts\n',
|
||
];
|
||
|
||
// generate test cases
|
||
var testCases = [];
|
||
for (var m = 0; m < methods.length; m++) {
|
||
for (var h = 0; h < headers.length; h++) {
|
||
for (var q = 0; q < strings.length; q++) {
|
||
for (var b = 0; b < strings.length; b++) {
|
||
testCases.push(function (m, h, q, b) {
|
||
return new Q()
|
||
.then(dial.sendRequest.bind(null, host, methods[m], headers[h], strings[q], strings[b]))
|
||
.then(function (response) {
|
||
testCount = testCount + 1;
|
||
if (![400, 404, 500].includes(response.statusCode)) {
|
||
return Q.reject(new Error("Sent the DIAL server an edge case. Expected a bad status code but got " + response.statusCode));
|
||
}
|
||
})
|
||
.fail(function handleError(err) {
|
||
utils.printTestInfo(__filename.slice(__dirname.length + 1),
|
||
"Edge Case, method: " + methods[m] + " header: "
|
||
+ headers[h] + " query string: "
|
||
+ strings[q] + " body: " + strings[b]);
|
||
utils.printTestFailure(err);
|
||
failureCount = failureCount + 1;
|
||
return err;
|
||
})
|
||
}.bind(null, m, h, q, b));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return testCases;
|
||
}
|
||
|
||
winston.info("Testing edge cases, only failing tests will appear.");
|
||
return edgeCases().reduce(Q.when, Promise.resolve()).done(function() {
|
||
winston.info("Tests complete. Passing: " + (testCount - failureCount) + ", Failures: " + failureCount);
|
||
});
|