Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add more xss and image testcases #739

Merged
merged 1 commit into from
Dec 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions tests/unit/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,40 @@ describe('left-toolbars测试', () => {

describe('xssOptions test', () => {
it('xssOptions is enabled by default', async () => {
let xssCode = `<a$ <img src=x onerror=prompt(/test_really/);>#"> <a$\n<img onerror="alert(1)" src="a">`;
let htmlValue = `<p>&lt;a$ <img src>#&quot;&gt; &lt;a$<br />\n<img src></p>`
let xssCode = `<a$ <img src=x onerror=prompt(/test_really/);>#"> <a$\n<img onerror="alert(1)" src="a">`;
let htmlValue = `<p>&lt;a$ <img src>#&quot;&gt; &lt;a$<br />\n<img src></p>`
let wrapper = new factory({ d_words: null, value: '' });

const textInput = wrapper.find('textarea')
await textInput.setValue(xssCode)

expect(wrapper.find(textValueClass).text()).toEqual(xssCode);
expect(wrapper.find(htmlValueClass).text()).toEqual(htmlValue);
});

it('disable xssOptions', async () => {
let xssCode = `<a$ <img src=x onerror=prompt(/test_really/);>#"> <a$\n<img onerror="alert(1)" src="a">`;
let htmlValue = `<p>&lt;a$ <img src=x onerror=prompt(/test_really/);>#&quot;&gt; &lt;a$<br />\n<img onerror=\"alert(1)\" src=\"a\"></p>`
let wrapper = new factory({ d_words: null, value: '', xssOptions: false });

const textInput = wrapper.find('textarea')
await textInput.setValue(xssCode)

expect(wrapper.find(textValueClass).text()).toEqual(xssCode);
expect(wrapper.find(htmlValueClass).text()).toEqual(htmlValue);
});
});

describe('local images upload', () => {
it('upload images', async () => {
let textValue = `![gh.png](1)`;
let htmlValue = `<p><img src=\"1\" alt=\"gh.png\" /></p>`
let wrapper = new factory({ d_words: null, value: '' });

const textInput = wrapper.find('textarea')
await textInput.setValue(xssCode)
wrapper.vm.$nextTick(() => {
expect(wrapper.find(textValueClass).text()).toEqual(xssCode);
expect(wrapper.find(htmlValueClass).text()).toEqual(htmlValue);
});
await textInput.setValue(textValue)

expect(wrapper.find(textValueClass).text()).toEqual(textValue);
expect(wrapper.find(htmlValueClass).text()).toEqual(htmlValue);
});
});