mirror of
https://github.com/wassname/talk.git
synced 2026-07-10 15:20:09 +08:00
Adding test.
This commit is contained in:
@@ -55,17 +55,15 @@ class Domainlist {
|
||||
|
||||
// This will return true in the event that at least one blockword is found
|
||||
// in the phrase.
|
||||
return list.every((domain) => {
|
||||
|
||||
// Not considering wildcards for now.
|
||||
if (domain === domainToMatch) {
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
if (list[i] === domainToMatch) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// We've walked over all the whitelisted domains, and haven't had a
|
||||
// mismatch... It is not an allowed domain!
|
||||
return false;
|
||||
});
|
||||
// We've walked over all the whitelisted domains, and haven't had a
|
||||
// mismatch... It is not an allowed domain!
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
const expect = require('chai').expect;
|
||||
const Domainlist = require('../../services/domainlist');
|
||||
const SettingsService = require('../../services/settings');
|
||||
|
||||
describe('services.Domainlist', () => {
|
||||
|
||||
const domainlists = {
|
||||
whitelist: [
|
||||
'nytimes.com',
|
||||
'wapo.com'
|
||||
]
|
||||
};
|
||||
|
||||
let domainlist = new Domainlist();
|
||||
const settings = {id: '1', moderation: 'PRE', domainlist: {whitelist: ['nytimes.com', 'wapo.com']}};
|
||||
|
||||
beforeEach(() => SettingsService.init(settings));
|
||||
|
||||
describe('#init', () => {
|
||||
|
||||
before(() => domainlist.upsert(domainlists));
|
||||
|
||||
it('has entries', () => {
|
||||
expect(domainlist.lists.whitelist).to.not.be.empty;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#match', () => {
|
||||
|
||||
const whiteList = Domainlist.parseList(domainlists['whitelist']);
|
||||
|
||||
it('does match on an included domain', () => {
|
||||
[
|
||||
'wapo.com',
|
||||
'nytimes.com'
|
||||
].forEach((domain) => {
|
||||
expect(domainlist.match(whiteList, domain)).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
it('does not match on a not included domain', () => {
|
||||
[
|
||||
'badsite.com',
|
||||
'www.badsite.com',
|
||||
'otherexample.com'
|
||||
].forEach((domain) => {
|
||||
expect(domainlist.match(whiteList, domain)).to.be.false;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user