aboutsummaryrefslogtreecommitdiffstats
path: root/tests/api-testing/REST/Transform.js
diff options
context:
space:
mode:
authordaniel <dkinzler@wikimedia.org>2022-07-31 11:45:00 +0200
committerDaniel Kinzler <dkinzler@wikimedia.org>2022-10-14 13:22:12 +0000
commitc25380ca37b714af5fe4fadb1d4f0aaebde38180 (patch)
tree5d2e71093cd094347e4e5cdbcc6d53e76a343c2c /tests/api-testing/REST/Transform.js
parentad1a2be374b9c8a9ed08c574ee60ba9be33d5ccf (diff)
downloadmediawikicore-c25380ca37b714af5fe4fadb1d4f0aaebde38180.tar.gz
mediawikicore-c25380ca37b714af5fe4fadb1d4f0aaebde38180.zip
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
Diffstat (limited to 'tests/api-testing/REST/Transform.js')
-rw-r--r--tests/api-testing/REST/Transform.js56
1 files changed, 38 insertions, 18 deletions
diff --git a/tests/api-testing/REST/Transform.js b/tests/api-testing/REST/Transform.js
index 30f21f64c20c..f8e4296d0f56 100644
--- a/tests/api-testing/REST/Transform.js
+++ b/tests/api-testing/REST/Transform.js
@@ -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' );