Parsoid: Fix e2e tests for size limits.

The tests for size limits did not catch an issue introduced by
If09afc4b933e, which caused resource limits to trigger early, since they
were now being compared to the size in bytes, rather than characters.

The reason the tests didn't protect us is threefold:
- They only check the error returned when the resource sizes is one over the limit.
  They don't check that the error is NOT returned when the size is one under the limit.
- They did not test with a multi-byte character.
- They were disabled, because the limits are quite high, and the e2e test can not change them.

This patch is an attempt to fix all three issues.

Depends-On: I40901a1204b3c698895a836bf3b605239878d1fe
Change-Id: I2aead24cb7f47eb1267fdd2954a7c7e45dd4ed51
This commit is contained in:
daniel 2022-07-31 11:45:00 +02:00 committed by Daniel Kinzler
parent ad1a2be374
commit c25380ca37
2 changed files with 45 additions and 19 deletions

View file

@ -69,7 +69,7 @@ unset( $logDir );
*/
global $wgRateLimits, $wgEnableJavaScriptTest, $wgRestAPIAdditionalRouteFiles,
$wgDeferredUpdateStrategy;
$wgDeferredUpdateStrategy, $wgParsoidSettings, $wgMaxArticleSize;
// Set almost infinite rate limits. This allows integration tests to run unthrottled
// in CI and for devs locally (T225796), but doesn't turn a large chunk of production
@ -101,6 +101,12 @@ $wgPasswordAttemptThrottle = [
// not wait for database replication to complete.
$wgForceDeferredUpdatesPreSend = true;
// Set size limits for parsing small enough so we can test them,
// but not so small that they interfere with other tests.
$wgMaxArticleSize = 20; // in Kilobyte
$wgParsoidSettings['wt2htmlLimits']['wikitextSize'] = 20 * 1024; // $wgMaxArticleSize, in byte
$wgParsoidSettings['html2wtLimits']['htmlSize'] = 100 * 1024; // in characters!
/**
* Experimental changes that may later become the default.
* (Must reference a Phabricator ticket)

View file

@ -11,9 +11,13 @@ const url = require( 'url' );
const fs = require( 'fs' );
const parsoidOptions = {
// Limits from DevelopmentSettings.php
limits: {
wt2html: { maxWikitextSize: 20000 },
html2wt: { maxHTMLSize: 10000 }
// Measured in bytes, per ParserOptions::getMaxIncludeSize.
wt2html: { maxWikitextSize: 20 * 1024 },
// Measured in characters.
html2wt: { maxHTMLSize: 100 * 1024 }
}
};
@ -895,22 +899,30 @@ describe( '/transform/ endpoint', function () {
.end( done );
} );
it( 'should return a request too large error (post wt)', function ( done ) {
if ( skipForNow ) {
return this.skip();
} // Set limits in config
it( 'should return a request too large error when just over limit (post wt)', function ( done ) {
client.req
.post( endpointPrefix + '/transform/wikitext/to/pagebundle/' )
.post( endpointPrefix + '/transform/wikitext/to/html/' )
.send( {
original: {
title: 'Large_Page'
},
// One over limit.
// Use single-byte characters, since the limit is in byte.
wikitext: 'a'.repeat( parsoidOptions.limits.wt2html.maxWikitextSize + 1 )
} )
.expect( 413 )
.end( done );
} );
it( 'should not return a request too large error when just under limit (post wt)', function ( done ) {
client.req
.post( endpointPrefix + '/transform/wikitext/to/html/' )
.send( {
// One under limit.
// Use single-byte characters, since the limit is in byte.
wikitext: 'a'.repeat( parsoidOptions.limits.wt2html.maxWikitextSize - 1 )
} )
.expect( 200 )
.end( done );
} );
it( 'should add redlinks for transform (html)', function ( done ) {
if ( skipForNow ) {
return this.skip();
@ -1849,22 +1861,30 @@ describe( '/transform/ endpoint', function () {
.end( done );
} );
it( 'should return a request too large error', function ( done ) {
if ( skipForNow ) {
return this.skip();
} // Set limits in config
it( 'should return a request too large error when just over limit', function ( done ) {
client.req
.post( endpointPrefix + '/transform/html/to/wikitext/' )
.send( {
original: {
title: 'Large_Page'
},
html: 'a'.repeat( parsoidOptions.limits.html2wt.maxHTMLSize + 1 )
// One over limit.
// Use multi-byte characters, since the limit is in characters.
html: 'ä'.repeat( parsoidOptions.limits.html2wt.maxHTMLSize + 1 )
} )
.expect( 413 )
.end( done );
} );
it( 'should not return a request too large error when just under limit', function ( done ) {
client.req
.post( endpointPrefix + '/transform/html/to/wikitext/' )
.send( {
// One under limit.
// Use multi-byte characters, since the limit is in characters.
html: 'ä'.repeat( parsoidOptions.limits.html2wt.maxHTMLSize - 1 )
} )
.expect( 200 )
.end( done );
} );
// Support for transforming from/to pagebundle is disabled in production.
it.skip( 'should fail to downgrade the original version for an unknown transition', function ( done ) {
const htmlOfMinimal = getTextFromFile( 'Minimal.html' );