mirror of
https://github.com/finos/SymphonyElectron.git
synced 2026-07-29 15:55:55 -05:00
Electron-217
* Wrote some unit tests for isWhiteList * Fixed some validation issues
This commit is contained in:
committed by
Kiran Niranjan
parent
84cb11e629
commit
d7f62a38b0
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user