Repository: couchdb-fauxton Updated Branches: refs/heads/master d71e0009d -> 2d6d00cda
Validation fix for CORS URLS Small fix to allow URLS with ports to validate. A few tests added. Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/2d6d00cd Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/2d6d00cd Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/2d6d00cd Branch: refs/heads/master Commit: 2d6d00cda3dd929893d0598cdd48c1fe61242e29 Parents: d71e000 Author: Ben Keen <[email protected]> Authored: Tue Mar 24 10:51:42 2015 -0700 Committer: Ben Keen <[email protected]> Committed: Wed Mar 25 10:10:19 2015 -0700 ---------------------------------------------------------------------- app/addons/cors/resources.js | 6 +++--- app/addons/cors/tests/resourcesSpec.js | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/2d6d00cd/app/addons/cors/resources.js ---------------------------------------------------------------------- diff --git a/app/addons/cors/resources.js b/app/addons/cors/resources.js index 640db24..3f42232 100644 --- a/app/addons/cors/resources.js +++ b/app/addons/cors/resources.js @@ -82,10 +82,10 @@ function (app, FauxtonAPI) { }); - // simple helper function to validate the user entered a valid domain starting with http(s) and - // not including any subfolder + // simple helper function to validate the user entered a valid domain starting with http(s), optional port and + // doesn't include a subfolder CORS.validateCORSDomain = function (str) { - return (/^https?:\/\/[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/).test(str); + return (/^https?:\/\/[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+(:\d{2,5})?$/).test(str); }; return CORS; http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/2d6d00cd/app/addons/cors/tests/resourcesSpec.js ---------------------------------------------------------------------- diff --git a/app/addons/cors/tests/resourcesSpec.js b/app/addons/cors/tests/resourcesSpec.js index 2d61846..29c30e2 100644 --- a/app/addons/cors/tests/resourcesSpec.js +++ b/app/addons/cors/tests/resourcesSpec.js @@ -41,7 +41,29 @@ define([ assert.deepEqual(cors.get('origins') , []); }); + it('allows valid domains', function () { + var urls = [ + 'http://something.com', + 'https://a.ca', + 'https://something.com:8000', + 'https://www.some-valid-domain.com:80' + ]; + _.each(urls, function (url) { + assert.isTrue(CORS.validateCORSDomain(url)); + }); + }); - }); + it('fails on invalid domains', function () { + var urls = [ + 'whoahnellythisaintright', + 'http://something', + 'ftp://site.com', + 'https://this.has/subfolder' + ]; + _.each(urls, function (url) { + assert.isFalse(CORS.validateCORSDomain(url)); + }); + }); + }); });
