Electron-217

* Wrote some unit tests for isWhiteList
* Fixed some validation issues
This commit is contained in:
Kiran Niranjan
2017-12-12 13:00:32 +05:30
committed by Kiran Niranjan
parent 84cb11e629
commit d7f62a38b0
4 changed files with 113 additions and 11 deletions
+74
View File
@@ -0,0 +1,74 @@
const { checkWhiteList } = require('../../js/utils/isWhiteList');
describe('validate url with whiteList', function() {
describe('checkWhiteList truth tests', function() {
it('should return true when the url is valid', function() {
const whiteList = 'www.symphony.com, app.symphony.com, my.symphony.com';
const url = 'https://my.symphony.com/';
return expect(checkWhiteList(url, whiteList)).toBeTruthy();
});
it('should return true when if hostName is defined', function() {
const whiteList = 'www.symphony.com, app.symphony.com, symphony.com';
const url = 'https://xyz.symphony.com/';
return expect(checkWhiteList(url, whiteList)).toBeTruthy();
});
it('should return true when the first occurrence of sub-domain is matched', function() {
const whiteList = 'www.symphony.com, app.symphony.com, my.symphony.com';
const url = 'https://xyz.my.symphony.com/';
return expect(checkWhiteList(url, whiteList)).toBeTruthy();
});
it('should return true when for any URL if whiteList has *', function() {
const whiteList = '*';
const url = 'https://www.example.com/';
return expect(checkWhiteList(url, whiteList)).toBeTruthy();
});
});
describe('checkWhiteList falsity tests', function () {
it('should return false when sub-domain does not match', function () {
const whiteList = 'www.symphony.com, app.symphony.com, my.symphony.com';
const url = 'https://xyz.symphony.com/';
return expect(checkWhiteList(url, whiteList)).toBeFalsy();
});
it('should return false when hostName does not match', function () {
const whiteList = 'www.symphony.com, app.symphony.com, my.symphony.com';
const url = 'https://my.example.com/';
return expect(checkWhiteList(url, whiteList)).toBeFalsy();
});
it('should return false when the URL is invalid', function () {
const whiteList = 'www.symphony.com, app.symphony.com, my.symphony.com';
const url = 'invalidUrl';
return expect(checkWhiteList(url, whiteList)).toBeFalsy();
});
it('should return false when the whiteList is invalid', function () {
const whiteList = 'invalidWhiteList';
const url = 'https://www.symphony.com';
return expect(checkWhiteList(url, whiteList)).toBeFalsy();
});
it('should return false if whiteList is empty', function() {
const whiteList = '';
const url = 'https://www.example.com/';
return expect(checkWhiteList(url, whiteList)).toBeFalsy();
});
});
});