-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate missing block tests to Playwright
- Loading branch information
Showing
2 changed files
with
54 additions
and
44 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
test.describe( 'missing block', () => { | ||
test.beforeEach( async ( { admin } ) => { | ||
await admin.createNewPost(); | ||
} ); | ||
|
||
test( 'should strip potentially malicious on* attributes', async ( { | ||
page, | ||
} ) => { | ||
let hasAlert = false; | ||
|
||
page.on( 'dialog', () => { | ||
hasAlert = true; | ||
} ); | ||
|
||
await page.evaluate( () => { | ||
const block = window.wp.blocks.parse( | ||
`<!-- wp:non-existing-block-here --><img src onerror=alert(1)>` | ||
); | ||
window.wp.data.dispatch( 'core/block-editor' ).resetBlocks( block ); | ||
} ); | ||
|
||
// Give the browser time to show the alert. | ||
await page.evaluate( () => new Promise( window.requestIdleCallback ) ); | ||
|
||
expect( hasAlert ).toBe( false ); | ||
} ); | ||
|
||
test( 'should strip potentially malicious script tags', async ( { | ||
page, | ||
} ) => { | ||
let hasAlert = false; | ||
|
||
page.on( 'dialog', () => { | ||
hasAlert = true; | ||
} ); | ||
|
||
await page.evaluate( () => { | ||
const block = window.wp.blocks.parse( | ||
`<!-- wp:non-existing-block-here --><script>alert("EVIL");</script>` | ||
); | ||
window.wp.data.dispatch( 'core/block-editor' ).resetBlocks( block ); | ||
} ); | ||
|
||
// Give the browser time to show the alert. | ||
await page.evaluate( () => new Promise( window.requestIdleCallback ) ); | ||
|
||
expect( hasAlert ).toBe( false ); | ||
} ); | ||
} ); |