From c6185196d3122aea92a2a345c0987522936bf2e9 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 21 May 2012 14:53:30 -0700 Subject: [PATCH 1/8] resources/static/lib/underscore-min.js: upgrade from 1.1.7 to 1.3.3 Specifically to get _.escape() --- resources/static/lib/underscore-min.js | 49 ++++++++++++++------------ 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/resources/static/lib/underscore-min.js b/resources/static/lib/underscore-min.js index 5983694cf..5a0cb3b00 100644 --- a/resources/static/lib/underscore-min.js +++ b/resources/static/lib/underscore-min.js @@ -1,27 +1,32 @@ -// Underscore.js 1.1.7 -// (c) 2011 Jeremy Ashkenas, DocumentCloud Inc. +// Underscore.js 1.3.3 +// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. // Underscore is freely distributable under the MIT license. // Portions of Underscore are inspired or borrowed from Prototype, // Oliver Steele's Functional, and John Resig's Micro-Templating. // For all details and documentation: // http://documentcloud.github.com/underscore -(function(){var p=this,C=p._,m={},i=Array.prototype,n=Object.prototype,f=i.slice,D=i.unshift,E=n.toString,l=n.hasOwnProperty,s=i.forEach,t=i.map,u=i.reduce,v=i.reduceRight,w=i.filter,x=i.every,y=i.some,o=i.indexOf,z=i.lastIndexOf;n=Array.isArray;var F=Object.keys,q=Function.prototype.bind,b=function(a){return new j(a)};typeof module!=="undefined"&&module.exports?(module.exports=b,b._=b):p._=b;b.VERSION="1.1.7";var h=b.each=b.forEach=function(a,c,b){if(a!=null)if(s&&a.forEach===s)a.forEach(c,b);else if(a.length=== -+a.length)for(var e=0,k=a.length;e=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a, -c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);var e={computed:Infinity};h(a,function(a,b,f){b=c?c.call(d,a,b,f):a;bd?1:0}),"value")};b.groupBy=function(a,b){var d={};h(a,function(a,f){var g=b(a,f);(d[g]||(d[g]=[])).push(a)});return d};b.sortedIndex=function(a,c,d){d|| -(d=b.identity);for(var e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a,c){return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=f.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after= -function(a,b){return function(){if(--a<1)return b.apply(this,arguments)}};b.keys=F||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[],d;for(d in a)l.call(a,d)&&(b[b.length]=d);return b};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){h(f.call(arguments,1),function(b){for(var d in b)b[d]!==void 0&&(a[d]=b[d])});return a};b.defaults=function(a){h(f.call(arguments, -1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,c){if(a===c)return!0;var d=typeof a;if(d!=typeof c)return!1;if(a==c)return!0;if(!a&&c||a&&!c)return!1;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual)return a.isEqual(c);if(c.isEqual)return c.isEqual(a);if(b.isDate(a)&&b.isDate(c))return a.getTime()===c.getTime();if(b.isNaN(a)&&b.isNaN(c))return!1; -if(b.isRegExp(a)&&b.isRegExp(c))return a.source===c.source&&a.global===c.global&&a.ignoreCase===c.ignoreCase&&a.multiline===c.multiline;if(d!=="object")return!1;if(a.length&&a.length!==c.length)return!1;d=b.keys(a);var e=b.keys(c);if(d.length!=e.length)return!1;for(var f in a)if(!(f in c)||!b.isEqual(a[f],c[f]))return!1;return!0};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(l.call(a,c))return!1;return!0};b.isElement=function(a){return!!(a&&a.nodeType== -1)};b.isArray=n||function(a){return E.call(a)==="[object Array]"};b.isObject=function(a){return a===Object(a)};b.isArguments=function(a){return!(!a||!l.call(a,"callee"))};b.isFunction=function(a){return!(!a||!a.constructor||!a.call||!a.apply)};b.isString=function(a){return!!(a===""||a&&a.charCodeAt&&a.substr)};b.isNumber=function(a){return!!(a===0||a&&a.toExponential&&a.toFixed)};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===!0||a===!1};b.isDate=function(a){return!(!a||!a.getTimezoneOffset|| -!a.setUTCFullYear)};b.isRegExp=function(a){return!(!a||!a.test||!a.exec||!(a.ignoreCase||a.ignoreCase===!1))};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.noConflict=function(){p._=C;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e/g,interpolate:/<%=([\s\S]+?)%>/g}; -b.template=function(a,c){var d=b.templateSettings;d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.interpolate,function(a,b){return"',"+b.replace(/\\'/g,"'")+",'"}).replace(d.evaluate||null,function(a,b){return"');"+b.replace(/\\'/g,"'").replace(/[\r\n\t]/g," ")+"__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');";d=new Function("obj",d);return c?d(c):d}; -var j=function(a){this._wrapped=a};b.prototype=j.prototype;var r=function(a,c){return c?b(a).chain():a},H=function(a,c){j.prototype[a]=function(){var a=f.call(arguments);D.call(a,this._wrapped);return r(c.apply(b,a),this._chain)}};b.mixin(b);h(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=i[a];j.prototype[a]=function(){b.apply(this._wrapped,arguments);return r(this._wrapped,this._chain)}});h(["concat","join","slice"],function(a){var b=i[a];j.prototype[a]=function(){return r(b.apply(this._wrapped, -arguments),this._chain)}});j.prototype.chain=function(){this._chain=!0;return this};j.prototype.value=function(){return this._wrapped}})(); +(function(){function r(a,c,d){if(a===c)return 0!==a||1/a==1/c;if(null==a||null==c)return a===c;a._chain&&(a=a._wrapped);c._chain&&(c=c._wrapped);if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return!1;switch(e){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:0==a?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== +c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if("object"!=typeof a||"object"!=typeof c)return!1;for(var f=d.length;f--;)if(d[f]==a)return!0;d.push(a);var f=0,g=!0;if("[object Array]"==e){if(f=a.length,g=f==c.length)for(;f--&&(g=f in a==f in c&&r(a[f],c[f],d)););}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return!1;for(var h in a)if(b.has(a,h)&&(f++,!(g=b.has(c,h)&&r(a[h],c[h],d))))break;if(g){for(h in c)if(b.has(c,h)&&!f--)break; +g=!f}}d.pop();return g}var s=this,I=s._,o={},k=Array.prototype,p=Object.prototype,i=k.slice,J=k.unshift,l=p.toString,K=p.hasOwnProperty,y=k.forEach,z=k.map,A=k.reduce,B=k.reduceRight,C=k.filter,D=k.every,E=k.some,q=k.indexOf,F=k.lastIndexOf,p=Array.isArray,L=Object.keys,t=Function.prototype.bind,b=function(a){return new m(a)};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._=b):s._=b;b.VERSION="1.3.3";var j=b.each=b.forEach=function(a, +c,d){if(a!=null)if(y&&a.forEach===y)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e2;a==null&&(a=[]);if(A&& +a.reduce===A){e&&(c=b.bind(c,e));return f?a.reduce(c,d):a.reduce(c)}j(a,function(a,b,i){if(f)d=c.call(e,d,a,b,i);else{d=a;f=true}});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(B&&a.reduceRight===B){e&&(c=b.bind(c,e));return f?a.reduceRight(c,d):a.reduceRight(c)}var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect=function(a, +c,b){var e;G(a,function(a,g,h){if(c.call(b,a,g,h)){e=a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(C&&a.filter===C)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(D&&a.every===D)return a.every(c,b);j(a,function(a,g,h){if(!(e=e&&c.call(b, +a,g,h)))return o});return!!e};var G=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(E&&a.some===E)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(q&&a.indexOf===q)return a.indexOf(c)!=-1;return b=G(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck= +function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0])return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0])return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]}; +j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1),true);return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a= +i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=L||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&& +c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.pick=function(a){var c={};j(b.flatten(i.call(arguments,1)),function(b){b in a&&(c[b]=a[b])});return c};b.defaults=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return r(a,b,[])};b.isEmpty= +function(a){if(a==null)return true;if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=p||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};b.isArguments=function(a){return l.call(a)=="[object Arguments]"};b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFunction=function(a){return l.call(a)=="[object Function]"}; +b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isFinite=function(a){return b.isNumber(a)&&isFinite(a)};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"};b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a, +b){return K.call(a,b)};b.noConflict=function(){s._=I;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.result=function(a,c){if(a==null)return null;var d=a[c];return b.isFunction(d)?d.call(a):d};b.mixin=function(a){j(b.functions(a),function(c){M(c,b[c]=a[c])})};var N=0;b.uniqueId= +function(a){var b=N++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var u=/.^/,n={"\\":"\\","'":"'",r:"\r",n:"\n",t:"\t",u2028:"\u2028",u2029:"\u2029"},v;for(v in n)n[n[v]]=v;var O=/\\|'|\r|\n|\t|\u2028|\u2029/g,P=/\\(\\|'|r|n|t|u2028|u2029)/g,w=function(a){return a.replace(P,function(a,b){return n[b]})};b.template=function(a,c,d){d=b.defaults(d||{},b.templateSettings);a="__p+='"+a.replace(O,function(a){return"\\"+n[a]}).replace(d.escape|| +u,function(a,b){return"'+\n_.escape("+w(b)+")+\n'"}).replace(d.interpolate||u,function(a,b){return"'+\n("+w(b)+")+\n'"}).replace(d.evaluate||u,function(a,b){return"';\n"+w(b)+"\n;__p+='"})+"';\n";d.variable||(a="with(obj||{}){\n"+a+"}\n");var a="var __p='';var print=function(){__p+=Array.prototype.join.call(arguments, '')};\n"+a+"return __p;\n",e=new Function(d.variable||"obj","_",a);if(c)return e(c,b);c=function(a){return e.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+a+"}";return c}; +b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var x=function(a,c){return c?b(a).chain():a},M=function(a,c){m.prototype[a]=function(){var a=i.call(arguments);J.call(a,this._wrapped);return x(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return x(d, +this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return x(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain=true;return this};m.prototype.value=function(){return this._wrapped}}).call(this); From b22a4f8f1b3f7a81011099bda9e9fc7e2ec31825 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 21 May 2012 16:44:03 -0700 Subject: [PATCH 2/8] dialog.js: improved parameter-escaping --- resources/static/dialog/controllers/dialog.js | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/resources/static/dialog/controllers/dialog.js b/resources/static/dialog/controllers/dialog.js index 1d3e57b87..0e369ee4f 100644 --- a/resources/static/dialog/controllers/dialog.js +++ b/resources/static/dialog/controllers/dialog.js @@ -86,6 +86,7 @@ BrowserID.Modules.Dialog = (function() { if (/^http/.test(url)) u = URLParse(url); else if (/^\//.test(url)) u = URLParse(origin + url); else throw "relative urls not allowed: (" + url + ")"; + // encodeURI limits our return value to [a-z0-9:/?%], excluding testuser@testuser.com" + }); + + // If requiredEmail is not properly escaped, scriptRun will be true. + equal(typeof window.scriptRun, "undefined", "script was not run"); + equal(retval, "invalid requiredEmail: (testuser@testuser.com)", "expected error"); + testErrorVisible(); + start(); + } + }); + }); + + asyncTest("get with valid requiredEmail - go to start", function() { + createController({ + ready: function() { + var startCalled = false; + mediator.subscribe("start", function(msg, info) { + startCalled = true; + }); + + var retval = controller.get(HTTP_TEST_DOMAIN, { + requiredEmail: TESTEMAIL + }); + + equal(typeof retval, "undefined", "no error expected"); + equal(startCalled, true, "start has been called"); + start(); + } + }); + }); + + asyncTest("get with relative tosURL & valid privacyURL - print error screen", function() { + createController({ + ready: function() { + mediator.subscribe("start", function(msg, info) { + ok(false, "start should not have been called"); + }); + + var retval = controller.get(HTTP_TEST_DOMAIN, { + tosURL: "relative.html", + privacyURL: "/privacy.html" + }); + equal(retval, "relative urls not allowed: (relative.html)", "expected error"); + testErrorVisible(); + start(); + } + }); + }); + + asyncTest("get with script containing tosURL - print error screen", function() { + createController({ + ready: function() { + mediator.subscribe("start", function(msg, info) { + ok(false, "start should not have been called"); + }); + + var retval = controller.get(HTTP_TEST_DOMAIN, { + tosURL: "relative.html", + privacyURL: "/privacy.html" + }); + + // If tosURL is not properly escaped, scriptRun will be true. + equal(typeof window.scriptRun, "undefined", "script was not run"); + equal(retval, "relative urls not allowed: (relative.html)", "expected error"); + testErrorVisible(); + start(); + } + }); + }); + + asyncTest("get with valid tosURL & relative privacyURL - print error screen", function() { + createController({ + ready: function() { + mediator.subscribe("start", function(msg, info) { + ok(false, "start should not have been called"); + }); + + var retval = controller.get(HTTP_TEST_DOMAIN, { + tosURL: "/tos.html", + privacyURL: "relative.html" + }); + equal(retval, "relative urls not allowed: (relative.html)", "expected error"); + testErrorVisible(); + start(); + } + }); + }); + + asyncTest("get with script containing privacyURL - print error screen", function() { + createController({ + ready: function() { + mediator.subscribe("start", function(msg, info) { + ok(false, "start should not have been called"); + }); + + var retval = controller.get(HTTP_TEST_DOMAIN, { + tosURL: "/tos.html", + privacyURL: "relative.html" + }); + + // If privacyURL is not properly escaped, scriptRun will be true. + equal(typeof window.scriptRun, "undefined", "script was not run"); + equal(retval, "relative urls not allowed: (relative.html)", "expected error"); + testErrorVisible(); + start(); + } + }); + }); + + asyncTest("get with privacyURL - print error screen", function() { + createController({ + ready: function() { + mediator.subscribe("start", function(msg, info) { + ok(false, "start should not have been called"); + }); + + var retval = controller.get(HTTP_TEST_DOMAIN, { + tosURL: "/tos.html", + privacyURL: "relative.html" + }); + + // If privacyURL is not properly escaped, scriptRun will be true. + equal(typeof window.scriptRun, "undefined", "script was not run"); + equal(retval, "relative urls not allowed: (relative.html)", "expected error"); + testErrorVisible(); + start(); + } + }); + }); + + asyncTest("get with javascript protocol for privacyURL - print error screen", function() { + createController({ + ready: function() { + mediator.subscribe("start", function(msg, info) { + ok(false, "start should not have been called"); + }); + + var retval = controller.get(HTTP_TEST_DOMAIN, { + tosURL: "/tos.html", + privacyURL: "javascript:alert(1)" + }); + + equal(retval, "relative urls not allowed: (javascript:alert(1))", "expected error"); + testErrorVisible(); + start(); + } + }); + }); + + asyncTest("get with invalid httpg protocol for privacyURL - print error screen", function() { + createController({ + ready: function() { + mediator.subscribe("start", function(msg, info) { + ok(false, "start should not have been called"); + }); + + var retval = controller.get(HTTP_TEST_DOMAIN, { + tosURL: "/tos.html", + privacyURL: "httpg://testdomain.com/privacy.html" + }); + + equal(retval, "relative urls not allowed: (httpg://testdomain.com/privacy.html)", "expected error"); + testErrorVisible(); + start(); + } + }); + }); + + + asyncTest("get with valid absolute tosURL & privacyURL - go to start", function() { + createController({ + ready: function() { + var startCalled = false; + mediator.subscribe("start", function(msg, info) { + startCalled = true; + }); + + var retval = controller.get(HTTP_TEST_DOMAIN, { + tosURL: "/tos.html", + privacyURL: "/privacy.html" + }); + + equal(typeof retval, "undefined", "no error expected"); + equal(startCalled, true, "start has been called"); + testErrorNotVisible(); + start(); + } + }); + }); + + asyncTest("get with valid fully qualified http tosURL & privacyURL - go to start", function() { + createController({ + ready: function() { + var startCalled = false; + mediator.subscribe("start", function(msg, info) { + startCalled = true; + }); + + var retval = controller.get(HTTP_TEST_DOMAIN, { + tosURL: HTTP_TEST_DOMAIN + "/tos.html", + privacyURL: HTTP_TEST_DOMAIN + "/privacy.html" + }); + + equal(typeof retval, "undefined", "no error expected"); + equal(startCalled, true, "start has been called"); + testErrorNotVisible(); + start(); + } + }); + }); + + + asyncTest("get with valid fully qualified https tosURL & privacyURL - go to start", function() { + createController({ + ready: function() { + var startCalled = false; + mediator.subscribe("start", function(msg, info) { + startCalled = true; + }); + + var retval = controller.get(HTTP_TEST_DOMAIN, { + tosURL: HTTPS_TEST_DOMAIN + "/tos.html", + privacyURL: HTTPS_TEST_DOMAIN + "/privacy.html" + }); + + equal(typeof retval, "undefined", "no error expected"); + equal(startCalled, true, "start has been called"); + testErrorNotVisible(); + start(); + } + }); + }); }()); diff --git a/resources/static/test/cases/resources/state.js b/resources/static/test/cases/resources/state.js index a8d859f19..16b634350 100644 --- a/resources/static/test/cases/resources/state.js +++ b/resources/static/test/cases/resources/state.js @@ -376,28 +376,6 @@ equal(actions.called.doCheckAuth, true, "checking auth on start"); }); - test("start with invalid requiredEmail - print error screen", function() { - mediator.publish("start", { - requiredEmail: "bademail" - }); - - equal(actions.called.doError, true, "error screen is shown"); - }); - - test("start with empty requiredEmail - prints error screen", function() { - mediator.publish("start", { - requiredEmail: "" - }); - - equal(actions.called.doError, true, "error screen is shown"); - }); - - test("start with valid requiredEmail - go to doCheckAuth", function() { - mediator.publish("start", { requiredEmail: TEST_EMAIL }); - - equal(actions.called.doCheckAuth, true, "checking auth on start"); - }); - asyncTest("start to complete successful primary email verification - goto 'primary_user'", function() { mediator.subscribe("primary_user", function(msg, info) { equal(info.email, TEST_EMAIL, "correct email given"); diff --git a/resources/static/test/testHelpers/helpers.js b/resources/static/test/testHelpers/helpers.js index 287ba8393..833f31e6e 100644 --- a/resources/static/test/testHelpers/helpers.js +++ b/resources/static/test/testHelpers/helpers.js @@ -127,6 +127,10 @@ BrowserID.TestHelpers = (function() { equal(TestHelpers.errorVisible(), true, "error screen is visible"); }, + testErrorNotVisible: function() { + equal(TestHelpers.errorVisible(), false, "error screen is not visible"); + }, + waitVisible: function() { return screens.wait.visible; }, diff --git a/resources/views/test.ejs b/resources/views/test.ejs index 30c4faf53..bb56772ac 100644 --- a/resources/views/test.ejs +++ b/resources/views/test.ejs @@ -76,6 +76,7 @@ + From 62043b0fd9c1c2cf8d371fe4d4f690c1ebdc2d5d Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 23 May 2012 11:45:20 -0700 Subject: [PATCH 7/8] strengthen email/URL validation: require the objects to be strings --- resources/static/dialog/controllers/dialog.js | 2 ++ resources/static/shared/validation.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/resources/static/dialog/controllers/dialog.js b/resources/static/dialog/controllers/dialog.js index 25236e5db..62043fbc8 100644 --- a/resources/static/dialog/controllers/dialog.js +++ b/resources/static/dialog/controllers/dialog.js @@ -84,6 +84,8 @@ BrowserID.Modules.Dialog = (function() { function fixupURL(origin, url) { var u; + if (typeof(url) !== "string") + throw "urls must be strings: (" + url + ")"; if (/^http(s)?:\/\//.test(url)) u = URLParse(url); else if (/^\//.test(url)) u = URLParse(origin + url); else throw "relative urls not allowed: (" + url + ")"; diff --git a/resources/static/shared/validation.js b/resources/static/shared/validation.js index e103085a0..d49f82371 100644 --- a/resources/static/shared/validation.js +++ b/resources/static/shared/validation.js @@ -7,6 +7,8 @@ BrowserID.Validation = (function() { tooltip = bid.Tooltip; bid.verifyEmail = function(address) { + if (typeof(address) !== "string") + return false; // Original gotten from http://blog.gerv.net/2011/05/html5_email_address_regexp/ // changed the requirement that there must be a ldh-str because BrowserID // is only used on internet based networks. From 5f6e89f11bb7db1ff976047cf9a202ac04f70137 Mon Sep 17 00:00:00 2001 From: Shane Tomlinson Date: Wed, 23 May 2012 22:21:06 +0100 Subject: [PATCH 8/8] Add additional tests to check whether requiredEmail, tosURL and privacyURL parameters are passed to "start" when expected. --- .../static/test/cases/controllers/dialog.js | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/resources/static/test/cases/controllers/dialog.js b/resources/static/test/cases/controllers/dialog.js index 58fd61406..4190cd915 100644 --- a/resources/static/test/cases/controllers/dialog.js +++ b/resources/static/test/cases/controllers/dialog.js @@ -237,17 +237,20 @@ asyncTest("get with valid requiredEmail - go to start", function() { createController({ ready: function() { - var startCalled = false; + var startInfo; mediator.subscribe("start", function(msg, info) { - startCalled = true; + startInfo = info; }); var retval = controller.get(HTTP_TEST_DOMAIN, { requiredEmail: TESTEMAIL }); + testHelpers.testObjectValuesEqual(startInfo, { + requiredEmail: TESTEMAIL + }); equal(typeof retval, "undefined", "no error expected"); - equal(startCalled, true, "start has been called"); + testErrorNotVisible(); start(); } }); @@ -394,9 +397,9 @@ asyncTest("get with valid absolute tosURL & privacyURL - go to start", function() { createController({ ready: function() { - var startCalled = false; + var startInfo; mediator.subscribe("start", function(msg, info) { - startCalled = true; + startInfo = info; }); var retval = controller.get(HTTP_TEST_DOMAIN, { @@ -404,8 +407,12 @@ privacyURL: "/privacy.html" }); + testHelpers.testObjectValuesEqual(startInfo, { + tosURL: HTTP_TEST_DOMAIN + "/tos.html", + privacyURL: HTTP_TEST_DOMAIN + "/privacy.html" + }); + equal(typeof retval, "undefined", "no error expected"); - equal(startCalled, true, "start has been called"); testErrorNotVisible(); start(); } @@ -415,9 +422,9 @@ asyncTest("get with valid fully qualified http tosURL & privacyURL - go to start", function() { createController({ ready: function() { - var startCalled = false; + var startInfo; mediator.subscribe("start", function(msg, info) { - startCalled = true; + startInfo = info; }); var retval = controller.get(HTTP_TEST_DOMAIN, { @@ -425,8 +432,12 @@ privacyURL: HTTP_TEST_DOMAIN + "/privacy.html" }); + testHelpers.testObjectValuesEqual(startInfo, { + tosURL: HTTP_TEST_DOMAIN + "/tos.html", + privacyURL: HTTP_TEST_DOMAIN + "/privacy.html" + }); + equal(typeof retval, "undefined", "no error expected"); - equal(startCalled, true, "start has been called"); testErrorNotVisible(); start(); } @@ -437,9 +448,9 @@ asyncTest("get with valid fully qualified https tosURL & privacyURL - go to start", function() { createController({ ready: function() { - var startCalled = false; + var startInfo; mediator.subscribe("start", function(msg, info) { - startCalled = true; + startInfo = info; }); var retval = controller.get(HTTP_TEST_DOMAIN, { @@ -447,8 +458,11 @@ privacyURL: HTTPS_TEST_DOMAIN + "/privacy.html" }); + testHelpers.testObjectValuesEqual(startInfo, { + tosURL: HTTPS_TEST_DOMAIN + "/tos.html", + privacyURL: HTTPS_TEST_DOMAIN + "/privacy.html" + }); equal(typeof retval, "undefined", "no error expected"); - equal(startCalled, true, "start has been called"); testErrorNotVisible(); start(); }