logseq/e2e-tests/sanitization.spec.ts

49 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-10-06 10:12:20 +00:00
import { expect } from '@playwright/test'
import { test } from './fixtures'
import { createRandomPage } from './utils'
2022-10-06 14:28:23 +00:00
test('custom html should not spawn any dialogs', async ({ page, block }) => {
2022-10-06 10:12:20 +00:00
page.on('dialog', async dialog => {
expect(false).toBeTruthy()
await dialog.dismiss()
})
2022-10-06 15:43:39 +00:00
await createRandomPage(page)
2022-10-07 13:44:06 +00:00
await page.keyboard.type('<iframe src="javascript:confirm(1);" />', { delay: 5 })
2022-10-06 10:12:20 +00:00
await block.enterNext()
2022-10-07 13:44:06 +00:00
await page.keyboard.type('<button id="test-xss-button" onclick="confirm(1)">Click me!</button>', { delay: 5 })
2022-10-06 10:12:20 +00:00
await block.enterNext()
2022-10-07 13:44:06 +00:00
await page.keyboard.type('<details open id="test-xss-toggle" ontoggle="confirm(1)">test</details>', { delay: 5 })
2022-10-06 14:28:23 +00:00
await block.enterNext()
await page.click('#test-xss-toggle')
2022-10-06 10:12:20 +00:00
await page.click('#test-xss-button')
expect(true).toBeTruthy()
})
2022-10-06 14:28:23 +00:00
test('custom hiccup should not spawn any dialogs', async ({ page, block }) => {
page.on('dialog', async dialog => {
expect(false).toBeTruthy()
await dialog.dismiss()
})
2022-10-06 15:43:39 +00:00
await createRandomPage(page)
2022-10-07 13:44:06 +00:00
await page.keyboard.type('[:iframe {:src "javascript:confirm(1);"}]', { delay: 5 })
2022-10-06 14:28:23 +00:00
await block.enterNext()
expect(true).toBeTruthy()
})
2022-11-18 13:18:18 +00:00
test('"is" attribute should be allowed for plugin purposes', async ({ page, block }) => {
await createRandomPage(page)
await page.keyboard.type('[:div {:is "custom-element" :id "custom-element-id"}]', { delay: 5 })
await block.enterNext()
await expect(page.locator('#custom-element-id')).toHaveAttribute('is', 'custom-element');
})