Skip to content

Commit

Permalink
fix unit tests for sanitizeSectionContent
Browse files Browse the repository at this point in the history
  • Loading branch information
flootr committed Jul 4, 2023
1 parent 998658d commit f6fcc0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
18 changes: 6 additions & 12 deletions client/lib/plugins/malformed-html-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -954,32 +954,27 @@ export default [
title: 'Tests against mXSS behavior with SVG in Chrome 77 and alike 1/2',
payload:
'<svg></p><textarea><title><style></textarea><img src=x onerror=alert(1)></style></title></svg>',
expected: '<p></p>&lt;/textarea&gt;&lt;img src=x onerror=alert(1)&gt;',
expectedSSR: '<p></p>&lt;title&gt;&lt;style&gt;<img>',
expected: '<p></p>&lt;title&gt;&lt;style&gt;<img>',
},
{
title: 'Tests against mXSS behavior with SVG in Chrome 77 and alike 2/2',
payload: '<svg></p><title><a id="</title><img src=x onerror=alert()>"></textarea></svg>',
expected: '<p></p><a></a>',
expectedSSR: '<p></p>&lt;a id="<img>"&gt;',
expected: '<p></p>&lt;a id="<img>"&gt;',
},
{
title: 'Tests against mXSS behavior with MathML in Chrome 77 and alike',
payload: '<math></p><textarea><mi><style></textarea><img src=x onerror=alert(1)></mi></math>',
expected: '<p></p>&lt;/textarea&gt;&lt;img src=x onerror=alert(1)&gt;&lt;/mi&gt;&lt;/math&gt;',
expectedSSR: '<p></p>&lt;mi&gt;&lt;style&gt;<img>',
expected: '<p></p>&lt;mi&gt;&lt;style&gt;<img>',
},
{
title: 'Tests against mXSS behavior with SVG Templates in Chrome 77 and alike',
payload: '<svg></p><title><template><style></title><img src=x onerror=alert(1)>',
expected: '<p></p>',
expectedSSR: '<p></p>&lt;template&gt;&lt;style&gt;<img>',
expected: '<p></p>&lt;template&gt;&lt;style&gt;<img>',
},
{
title: 'Tests against mXSS behavior with MathML Templates in Chrome 77 and alike',
payload: '<math></br><textarea><mtext><template><style></textarea><img src=x onerror=alert(1)>',
expected: '',
expectedSSR: '&lt;mtext&gt;&lt;template&gt;&lt;style&gt;<img>',
expected: '&lt;mtext&gt;&lt;template&gt;&lt;style&gt;<img>',
},
{
title: 'Fixed an exception coming from missing clobbering protection',
Expand All @@ -989,8 +984,7 @@ export default [
{
title: 'Tests against mXSS behavior with embedded MathML/SVG',
payload: '<svg></p><math><title><style><img src=x onerror=alert(1)></style></title>',
expected: '<p></p>&lt;img src=x onerror=alert(1)&gt;',
expectedSSR: '<p></p><img>',
expected: '<p></p><img>',
},
{
title: 'Tests against attribute-based mXSS behavior 1/3',
Expand Down
8 changes: 3 additions & 5 deletions client/lib/plugins/test/sanitize-section-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,9 @@ const runTests = ( isSSR = false ) => {
);
} );

fixtures.forEach( ( { title, payload, expected, expectedSSR }, index ) => {
test( `Fixture test #${ index }: ${ title } `, () => {
const toBeExpected = isSSR ? expectedSSR || expected : expected;
expect( clean( payload ) ).toBe( toBeExpected );
} );
test.each( fixtures )( '`Fixture test $#: $title `', ( testConfig ) => {
const { payload, expected } = testConfig;
expect( clean( payload ) ).toBe( expected );
} );
};

Expand Down

0 comments on commit f6fcc0f

Please sign in to comment.