Skip to content

Commit

Permalink
test(xss): add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinzZH committed Jun 14, 2018
1 parent aa55ba0 commit 9ab0e35
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion test/bin/tsw/util/xss.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,67 @@ logger.setLogLevel('error');
describe('xss.js', () => {
it('#htmlEncode', () => {
// console.log(xss.filterXSS('<'));
expect(xss.htmlEncode(1)).to.equal('1');
expect('&lt;&gt;&amp;&#039;&quot;').to.equal(xss.htmlEncode('<>&\'"'));
});

it('#htmlDecode', () => {
expect(xss.htmlDecode(1)).to.equal('1');
expect('<>&\'"').to.equal(xss.htmlDecode('&lt;&gt;&amp;&#039;&quot;'));
});

it('#filterParams', () => {
// 这个函数没法测,就这样吧
const oriParam = {
key: 'value',
arr: ['1', '2', '3']
};

const param = JSON.parse(JSON.stringify(oriParam));

xss.filterParams(param);

expect(JSON.stringify(param)).to.be.equal(JSON.stringify(oriParam));
});

it('#filterParams number', () => {
const oriParam = {
key: 1
};

const param = JSON.parse(JSON.stringify(oriParam));

xss.filterParams(param);

expect(JSON.stringify(param)).to.not.be.equal(JSON.stringify(oriParam));
});

it('#filterParams obj', () => {
const oriParam = {
key: 'value',
arr: { a: '1' }
};

const param = JSON.parse(JSON.stringify(oriParam));

xss.filterParams(param);
expect(JSON.stringify(param)).to.not.be.equal(JSON.stringify(oriParam));
});

it('#filterParams <', () => {
// TODO 去掉了全部空位,需确认下用途
const oriParam = {
key: '< gg >'
};

const param = JSON.parse(JSON.stringify(oriParam));

xss.filterParams(param);

expect(param.key).to.not.be.equal(oriParam.key);
expect(param.key).to.be.equal('<gg>');
});

it('#filterXSS', () => {
expect(xss.filterXSS('< gg >')).to.be.equal('<gg>');
});
});

0 comments on commit 9ab0e35

Please sign in to comment.