App-DubiousHTTP
view release on metacpan or search on metacpan
lib/App/DubiousHTTP/Tests.pm view on Meta::CPAN
#return "<script id='$id' src='$url' onload='set_load(\"$id\",\"js\");' onerror='set_fail(\"$id\",\"js\");' onreadystatechange='set_load(\"$id\",\"js\");'></script>";
return <<"JS"
function(div) {
var s = document.createElement('script');
s.setAttribute('src','$url');
s.setAttribute('id','$id');
s.setAttribute('onload','set_load(\"$id\",\"js\");');
s.setAttribute('onreadystatechange','set_load(\"$id\",\"js\");');
s.setAttribute('onerror','set_fail(\"$id\",\"js\");');
div.appendChild(s);
}
JS
});
}
sub auto_html {
my ($self,$cat) = @_;
_auto_imgjshtml($cat, 'Browser behavior test with iframe including HTML', 'parent_set_success.html', sub {
my ($url,$id) = @_;
return "<iframe id='$id' src='$url' onload='set_load(\"$id\",\"html\");' onerror='set_fail(\"$id\",\"html\");' onreadystatechange='set_load(\"$id\",\"html\");'></iframe>";
});
}
sub _auto_imgjshtml {
my ($cat,$title,$page,$mkhtml) = @_;
my $jsglob = '';
$jsglob .= sprintf("reference='%x' + Math.floor(time()/1000).toString(16);\n", rand(2**32));
$jsglob .= "fast_feedback = 16384;\n" if $FAST_FEEDBACK;
my $rand = rand();
for(@cat) {
next if $cat ne 'all' && $_->ID ne $cat;
for($_->TESTS) {
my $num = $_->NUM_ID;
my $xid = quotemeta(html_escape($_->LONG_ID));
my $url = url_encode($_->url($page));
my $html = $mkhtml->("$url?rand=$rand",$xid);
$jsglob .= "checks.push({ "
. "num: $num, page: '$url', xid: '$xid', "
. 'desc: "'.quotemeta(html_escape($_->DESCRIPTION)) .'",'
. 'valid: '.$_->VALID .','
. 'html: '.($html =~m{^function} ? $html : '"'.quotemeta($html).'"')
."});\n";
}
}
$jsglob .= "div_title.innerHTML = '<h1>".html_escape($title)."</h1>';";
$jsglob .= "runtests()\n";
my $html = _auto_static_html()."<script>$jsglob</script>\n";
return "HTTP/1.0 200 ok\r\n".
"Content-type: text/html\r\n".
"Content-length: ".length($html)."\r\n".
"ETag: ".App::DubiousHTTP->VERSION."\r\n".
"\r\n".
$html;
}
sub _auto_static_html { return <<'HTML'; }
<!doctype html>
<meta charset="utf-8">
<style>
body { font-family: Verdana, sans-serif; }
#title { padding: 1em; margin: 1em; border: 1px; border-style: solid; color: #000; background: #eee; }
#title h1 { font-size: 190%; }
#vendor_notice { padding: 2em; margin: 1em; background: #000000; color: #ff0000; font-size: 150%; display: none; }
#nobad { padding: 2em; margin: 1em; background: #ff3333; display: none; }
#nobad div { font-size: 150%; margin: 0.5em; }
#noevade { padding: 1em; margin: 1em; background: green; display: none; }
#overblock { padding: 1em; margin: 1em; background: #ff9933; display: none; }
#evadable { padding: 1em; margin: 1em; background: #ff3333; display: none; }
#urlblock { padding: 1em; margin: 1em; background: #ffff00 ; display: none; }
#urlblock div { font-size: 150%; margin: 0.5em; }
#notice { padding: 1em; margin: 1em; background: #e9f2e1; display: none; }
#warnings { padding: 1em; margin: 1em; background: #e3a79f; display: none; }
#process { padding: 1em; margin: 1em; background: #f2f299; }
#debug { padding: 1em; margin: 1em; }
.desc { font-size: 110%; }
.srclink { font-variant: small-caps; }
.trylink { font-variant: small-caps; }
#eicar { font-family: Lucida Sans Typewriter,Lucida Console,monaco,Bitstream Vera Sans Mono,monospace; padding: 0.5em; margin: 0.5em; border-style: solid; border-width: 1px; }
</style>
<div id=noscript>
You need to have JavaScript enabled to run this tests.
</div>
<div id=title></div>
<div id=vendor_notice> </div>
<div id=nobad> </div>
<div id=urlblock> </div>
<div id=evasions></div>
<div id=process></div>
<div id=evadable> </div>
<div id=overblock> </div>
<div id=noevade> </div>
<div id=warnings><h1>Serious Problems</h1></div>
<div id=notice><h1>Behavior in Uncommon Cases</h1></div>
<div id=debug><h1>Debug</h1></div>
<div id=work style='display:none;'></div>
<script>
'use strict';
var time = Date.now || function() { return +new Date; };
function vendor_notice(msg) {
var div = document.getElementById('vendor_notice');
if (!div) return;
div.innerHTML = msg;
div.style.display = 'block';
}
function base64_encode(input,urlsafe) {
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var output = "";
var chrs = urlsafe
? "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="
: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
for(var i=0;i<input.length; i+=3) {
chr1 = input.charCodeAt(i) & 0xff;
chr2 = input.charCodeAt(i+1) & 0xff;
chr3 = input.charCodeAt(i+2) & 0xff;
lib/App/DubiousHTTP/Tests.pm view on Meta::CPAN
var rand = Math.random();
function add_warning(m,test) {
var id = test['num'];
div_warnings.innerHTML = div_warnings.innerHTML + "[" + id + "] " + m + ": <span class=desc>" + test['desc'] + "</span>" +
" <a class=trylink target=_blank download='" + test['file'] + "' href=" + test['page'] + ">try</a>" +
" <a class=srclink target=_blank href=/src" + test['page'] + ">src</a>" +
"<br>";
div_warnings.style.display = 'block';
}
function add_notice(m,test) {
var id = test['num'];
div_notice.innerHTML = div_notice.innerHTML + "[" + id + "] " + m + ": <span class=desc>" + test['desc'] + "</span>" +
" <a class=trylink target=_blank download='" + test['file'] + "' href=" + test['page'] + ">try</a>" +
" <a class=srclink target=_blank href=/src" + test['page'] + ">src</a>" +
"<br>";
div_notice.style.display = 'block';
}
function add_debug(m,test) {
if (test) {
m = "[" + test['num'] + "] " + m;
}
div_debug.innerHTML = div_debug.innerHTML + m + (test ?
" <a class=trylink target=_blank download='" + test['file'] + "' href=" + test['page'] + ">try</a>" +
" <a class=srclink target=_blank href=/src" + test['page'] + ">src</a>"
: "" ) + "<br>";
}
function escapeAttribute(attr) {
return attr
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
function _log(m) {
try { console.log(m) }
catch(e) {}
}
function xhr(method,page,payload,callback) {
var req = null;
try { req = new XMLHttpRequest(); }
catch(e) {
try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
catch(e) {
try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
catch(e) { req = null; }
}
}
if (!req) {
return null;
}
try {
try { req.overrideMimeType('text/plain; charset=x-user-defined'); }
catch(e) { _log("no support for overrideMimeType"); }
if (callback) {
var done = 0;
req.ontimeout = function() {
if (!done) {
done = 1;
callback(req,'timeout');
}
};
req.onreadystatechange = function() {
if (!done && req.readyState == 4) {
done = 1;
callback(req);
}
};
}
req.open(method, page, true);
if (accept != null) {
try { req.setRequestHeader('Accept',accept); }
catch(e) { _log("no support for setRequestHeader") }
}
try { req.timeout = 5000; }
catch(e) { _log("no support for xhr timeout") }
req.send(payload);
} catch(e) {
_log(e);
req = null;
}
return req;
}
function check_xhr_result(req,test,status) {
if (!status) {
status = req.status;
}
var header;
try { header = req.getAllResponseHeaders(); } catch(e) {}
if (header == undefined || header == null) { header = ''; }
if (!status) {
status = 'invalid';
} else if (status >0) {
var response;
try { response = req.responseText }
catch(e) {}
if (response == null) {
_log("no data for " + test['page']);
} else {
var expect = test['expect'] || test['_expect'];
var result64 = base64_encode(response);
if (result64 == expect) {
status = 'match';
} else {
var pn = response.indexOf(base64_decode(expect));
if (pn<0) {
status = 'change(' + status + ')';
_log( 'response="' + response + '" expect="' + base64_decode(expect) + '"');
} else {
( run in 2.025 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )