2020-11-19 18:53:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MediaWiki\Tests\Rest\Handler;
|
|
|
|
|
|
|
|
|
|
use DeferredUpdates;
|
|
|
|
|
use Exception;
|
|
|
|
|
use ExtensionRegistry;
|
|
|
|
|
use HashBagOStuff;
|
|
|
|
|
use HashConfig;
|
2020-12-04 15:28:25 +00:00
|
|
|
use MediaWiki\Config\ServiceOptions;
|
2020-11-19 18:53:05 +00:00
|
|
|
use MediaWiki\Json\JsonCodec;
|
2022-06-13 15:48:44 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
|
|
|
|
use MediaWiki\MainConfigSchema;
|
2020-11-19 18:53:05 +00:00
|
|
|
use MediaWiki\Parser\ParserCacheFactory;
|
2022-06-17 14:00:27 +00:00
|
|
|
use MediaWiki\Parser\Parsoid\ParsoidOutputAccess;
|
2020-11-19 18:53:05 +00:00
|
|
|
use MediaWiki\Rest\Handler\PageHTMLHandler;
|
|
|
|
|
use MediaWiki\Rest\LocalizedHttpException;
|
|
|
|
|
use MediaWiki\Rest\RequestData;
|
|
|
|
|
use MediaWikiIntegrationTestCase;
|
|
|
|
|
use MWTimestamp;
|
|
|
|
|
use NullStatsdDataFactory;
|
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
|
use Psr\Log\NullLogger;
|
2020-12-04 15:28:25 +00:00
|
|
|
use WANObjectCache;
|
2020-11-19 18:53:05 +00:00
|
|
|
use Wikimedia\Message\MessageValue;
|
|
|
|
|
use Wikimedia\Parsoid\Core\ClientError;
|
|
|
|
|
use Wikimedia\Parsoid\Core\ResourceLimitExceededException;
|
|
|
|
|
use Wikimedia\Parsoid\Parsoid;
|
|
|
|
|
use WikiPage;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Rest\Handler\PageHTMLHandler
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
|
|
|
|
class PageHTMLHandlerTest extends MediaWikiIntegrationTestCase {
|
|
|
|
|
use HandlerTestTrait;
|
2022-05-16 16:56:20 +00:00
|
|
|
use HTMLHandlerTestTrait;
|
2020-11-19 18:53:05 +00:00
|
|
|
|
|
|
|
|
private const WIKITEXT = 'Hello \'\'\'World\'\'\'';
|
|
|
|
|
|
2022-05-16 16:56:20 +00:00
|
|
|
private const HTML = '>World</';
|
|
|
|
|
|
|
|
|
|
/** @var HashBagOStuff */
|
|
|
|
|
private $parserCacheBagOStuff;
|
2020-11-19 18:53:05 +00:00
|
|
|
|
|
|
|
|
protected function setUp(): void {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
// Clean up these tables after each test
|
|
|
|
|
$this->tablesUsed = [
|
|
|
|
|
'page',
|
|
|
|
|
'revision',
|
|
|
|
|
'comment',
|
|
|
|
|
'text',
|
|
|
|
|
'content'
|
|
|
|
|
];
|
2022-05-16 16:56:20 +00:00
|
|
|
|
|
|
|
|
$this->parserCacheBagOStuff = new HashBagOStuff();
|
2020-11-19 18:53:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks whether Parsoid extension is installed and skips the test if it's not.
|
|
|
|
|
*/
|
|
|
|
|
private function checkParsoidInstalled() {
|
|
|
|
|
if ( !ExtensionRegistry::getInstance()->isLoaded( 'Parsoid' ) ) {
|
|
|
|
|
$this->markTestSkipped( 'Skip test, since parsoid is not configured' );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Parsoid|MockObject|null $parsoid
|
2022-05-16 16:56:20 +00:00
|
|
|
*
|
2020-11-19 18:53:05 +00:00
|
|
|
* @return PageHTMLHandler
|
|
|
|
|
*/
|
2022-06-17 14:00:27 +00:00
|
|
|
private function newHandler( ?Parsoid $parsoid = null ): PageHTMLHandler {
|
2020-12-04 15:28:25 +00:00
|
|
|
$parserCacheFactoryOptions = new ServiceOptions( ParserCacheFactory::CONSTRUCTOR_OPTIONS, [
|
|
|
|
|
'CacheEpoch' => '20200202112233',
|
2022-06-17 14:00:27 +00:00
|
|
|
'OldRevisionParserCacheExpireTime' => 60 * 60,
|
2020-12-04 15:28:25 +00:00
|
|
|
] );
|
|
|
|
|
|
2022-06-17 14:00:27 +00:00
|
|
|
$services = $this->getServiceContainer();
|
2020-12-04 15:28:25 +00:00
|
|
|
$parserCacheFactory = new ParserCacheFactory(
|
2022-05-16 16:56:20 +00:00
|
|
|
$this->parserCacheBagOStuff,
|
2022-06-17 14:00:27 +00:00
|
|
|
new WANObjectCache( [ 'cache' => $this->parserCacheBagOStuff, ] ),
|
2020-12-04 15:28:25 +00:00
|
|
|
$this->createHookContainer(),
|
|
|
|
|
new JsonCodec(),
|
|
|
|
|
new NullStatsdDataFactory(),
|
|
|
|
|
new NullLogger(),
|
2021-03-24 14:05:44 +00:00
|
|
|
$parserCacheFactoryOptions,
|
2022-06-17 14:00:27 +00:00
|
|
|
$services->getTitleFactory(),
|
|
|
|
|
$services->getWikiPageFactory()
|
2020-12-04 15:28:25 +00:00
|
|
|
);
|
|
|
|
|
|
2022-06-13 15:48:44 +00:00
|
|
|
$config = [
|
|
|
|
|
'RightsUrl' => 'https://example.com/rights',
|
|
|
|
|
'RightsText' => 'some rights',
|
|
|
|
|
'ParsoidCacheConfig' =>
|
|
|
|
|
MainConfigSchema::getDefaultValue( MainConfigNames::ParsoidCacheConfig )
|
|
|
|
|
];
|
2022-06-17 14:00:27 +00:00
|
|
|
|
|
|
|
|
$parsoidOutputAccess = new ParsoidOutputAccess(
|
|
|
|
|
new ServiceOptions(
|
|
|
|
|
ParsoidOutputAccess::CONSTRUCTOR_OPTIONS,
|
|
|
|
|
$services->getMainConfig()
|
|
|
|
|
),
|
|
|
|
|
$parserCacheFactory,
|
|
|
|
|
$services->getRevisionLookup(),
|
|
|
|
|
$services->getGlobalIdGenerator(),
|
|
|
|
|
$services->getStatsdDataFactory(),
|
|
|
|
|
$parsoid ?? new Parsoid(
|
|
|
|
|
$services->get( 'ParsoidSiteConfig' ),
|
|
|
|
|
$services->get( 'ParsoidDataAccess' )
|
|
|
|
|
),
|
2022-06-29 17:01:21 +00:00
|
|
|
$services->getParsoidSiteConfig(),
|
2022-06-17 14:00:27 +00:00
|
|
|
$services->getParsoidPageConfigFactory()
|
|
|
|
|
);
|
|
|
|
|
|
2020-11-19 18:53:05 +00:00
|
|
|
$handler = new PageHTMLHandler(
|
2022-06-13 15:48:44 +00:00
|
|
|
new HashConfig( $config ),
|
2022-06-17 14:00:27 +00:00
|
|
|
$services->getRevisionLookup(),
|
|
|
|
|
$services->getTitleFormatter(),
|
|
|
|
|
$services->getPageStore(),
|
2022-05-26 10:36:28 +00:00
|
|
|
$this->getParsoidOutputStash(),
|
2022-06-17 14:00:27 +00:00
|
|
|
$services->getStatsdDataFactory(),
|
|
|
|
|
$parsoidOutputAccess
|
2020-11-19 18:53:05 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $handler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testExecuteWithHtml() {
|
|
|
|
|
$this->checkParsoidInstalled();
|
|
|
|
|
$page = $this->getExistingTestPage( 'HtmlEndpointTestPage/with/slashes' );
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
$this->editPage( $page, self::WIKITEXT )->isGood(),
|
2021-11-21 16:23:11 +00:00
|
|
|
'Edited a page'
|
2020-11-19 18:53:05 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$request = new RequestData(
|
|
|
|
|
[ 'pathParams' => [ 'title' => $page->getTitle()->getPrefixedText() ] ]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$handler = $this->newHandler();
|
|
|
|
|
$data = $this->executeHandlerAndGetBodyData( $handler, $request, [
|
|
|
|
|
'format' => 'with_html'
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$this->assertResponseData( $page, $data );
|
|
|
|
|
$this->assertStringContainsString( '<!DOCTYPE html>', $data['html'] );
|
|
|
|
|
$this->assertStringContainsString( '<html', $data['html'] );
|
|
|
|
|
$this->assertStringContainsString( self::HTML, $data['html'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testExecuteHtmlOnly() {
|
|
|
|
|
$this->checkParsoidInstalled();
|
|
|
|
|
$page = $this->getExistingTestPage( 'HtmlEndpointTestPage/with/slashes' );
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
$this->editPage( $page, self::WIKITEXT )->isGood(),
|
2021-11-21 16:23:11 +00:00
|
|
|
'Edited a page'
|
2020-11-19 18:53:05 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$request = new RequestData(
|
|
|
|
|
[ 'pathParams' => [ 'title' => $page->getTitle()->getPrefixedText() ] ]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$handler = $this->newHandler();
|
|
|
|
|
$response = $this->executeHandler( $handler, $request, [
|
|
|
|
|
'format' => 'html'
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$htmlResponse = (string)$response->getBody();
|
|
|
|
|
$this->assertStringContainsString( '<!DOCTYPE html>', $htmlResponse );
|
|
|
|
|
$this->assertStringContainsString( '<html', $htmlResponse );
|
|
|
|
|
$this->assertStringContainsString( self::HTML, $htmlResponse );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testEtagLastModified() {
|
|
|
|
|
$this->checkParsoidInstalled();
|
|
|
|
|
|
|
|
|
|
$time = time();
|
|
|
|
|
MWTimestamp::setFakeTime( $time );
|
|
|
|
|
|
|
|
|
|
$page = $this->getExistingTestPage( 'HtmlEndpointTestPage/with/slashes' );
|
|
|
|
|
$request = new RequestData(
|
|
|
|
|
[ 'pathParams' => [ 'title' => $page->getTitle()->getPrefixedText() ] ]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// First, test it works if nothing was cached yet.
|
|
|
|
|
// Make some time pass since page was created:
|
2020-12-07 19:00:14 +00:00
|
|
|
$time += 10;
|
|
|
|
|
MWTimestamp::setFakeTime( $time );
|
2022-05-16 16:56:20 +00:00
|
|
|
$handler = $this->newHandler();
|
2020-11-19 18:53:05 +00:00
|
|
|
$response = $this->executeHandler( $handler, $request, [
|
|
|
|
|
'format' => 'html'
|
|
|
|
|
] );
|
|
|
|
|
$this->assertArrayHasKey( 'ETag', $response->getHeaders() );
|
|
|
|
|
$etag = $response->getHeaderLine( 'ETag' );
|
2022-05-24 21:13:42 +00:00
|
|
|
$this->assertStringMatchesFormat( '"' . $page->getLatest() . '/%x-%x-%x-%x-%x/%s"', $etag );
|
2020-11-19 18:53:05 +00:00
|
|
|
$this->assertArrayHasKey( 'Last-Modified', $response->getHeaders() );
|
|
|
|
|
$this->assertSame( MWTimestamp::convert( TS_RFC2822, $time ),
|
|
|
|
|
$response->getHeaderLine( 'Last-Modified' ) );
|
|
|
|
|
|
|
|
|
|
// Now, test that headers work when getting from cache too.
|
2022-05-16 16:56:20 +00:00
|
|
|
$handler = $this->newHandler();
|
2020-11-19 18:53:05 +00:00
|
|
|
$response = $this->executeHandler( $handler, $request, [
|
|
|
|
|
'format' => 'html'
|
|
|
|
|
] );
|
|
|
|
|
$this->assertArrayHasKey( 'ETag', $response->getHeaders() );
|
2020-12-07 19:00:14 +00:00
|
|
|
$this->assertSame( $etag, $response->getHeaderLine( 'ETag' ) );
|
2020-11-19 18:53:05 +00:00
|
|
|
$etag = $response->getHeaderLine( 'ETag' );
|
2022-05-24 21:13:42 +00:00
|
|
|
$this->assertStringMatchesFormat( '"' . $page->getLatest() . '/%x-%x-%x-%x-%x/%s"', $etag );
|
2020-11-19 18:53:05 +00:00
|
|
|
$this->assertArrayHasKey( 'Last-Modified', $response->getHeaders() );
|
2020-12-07 19:00:14 +00:00
|
|
|
$this->assertSame( MWTimestamp::convert( TS_RFC2822, $time ),
|
2020-11-19 18:53:05 +00:00
|
|
|
$response->getHeaderLine( 'Last-Modified' ) );
|
|
|
|
|
|
|
|
|
|
// Now, expire the cache
|
|
|
|
|
$time += 1000;
|
|
|
|
|
MWTimestamp::setFakeTime( $time );
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
$page->getTitle()->invalidateCache( MWTimestamp::convert( TS_MW, $time ) ),
|
2021-11-21 16:23:11 +00:00
|
|
|
'Can invalidate cache'
|
2020-11-19 18:53:05 +00:00
|
|
|
);
|
|
|
|
|
DeferredUpdates::doUpdates();
|
|
|
|
|
|
2022-05-16 16:56:20 +00:00
|
|
|
$handler = $this->newHandler();
|
2020-11-19 18:53:05 +00:00
|
|
|
$response = $this->executeHandler( $handler, $request, [
|
|
|
|
|
'format' => 'html'
|
|
|
|
|
] );
|
|
|
|
|
$this->assertArrayHasKey( 'ETag', $response->getHeaders() );
|
|
|
|
|
$this->assertNotSame( $etag, $response->getHeaderLine( 'ETag' ) );
|
2020-12-07 19:00:14 +00:00
|
|
|
$etag = $response->getHeaderLine( 'ETag' );
|
2022-05-24 21:13:42 +00:00
|
|
|
$this->assertStringMatchesFormat( '"' . $page->getLatest() . '/%x-%x-%x-%x-%x/%s"', $etag );
|
2020-11-19 18:53:05 +00:00
|
|
|
$this->assertArrayHasKey( 'Last-Modified', $response->getHeaders() );
|
|
|
|
|
$this->assertSame( MWTimestamp::convert( TS_RFC2822, $time ),
|
|
|
|
|
$response->getHeaderLine( 'Last-Modified' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideHandlesParsoidError() {
|
|
|
|
|
yield 'ClientError' => [
|
|
|
|
|
new ClientError( 'TEST_TEST' ),
|
|
|
|
|
new LocalizedHttpException(
|
|
|
|
|
new MessageValue( 'rest-html-backend-error' ),
|
|
|
|
|
400,
|
|
|
|
|
[
|
|
|
|
|
'reason' => 'TEST_TEST'
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
];
|
|
|
|
|
yield 'ResourceLimitExceededException' => [
|
|
|
|
|
new ResourceLimitExceededException( 'TEST_TEST' ),
|
|
|
|
|
new LocalizedHttpException(
|
|
|
|
|
new MessageValue( 'rest-resource-limit-exceeded' ),
|
|
|
|
|
413,
|
|
|
|
|
[
|
|
|
|
|
'reason' => 'TEST_TEST'
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideHandlesParsoidError
|
|
|
|
|
*/
|
|
|
|
|
public function testHandlesParsoidError(
|
|
|
|
|
Exception $parsoidException,
|
|
|
|
|
Exception $expectedException
|
|
|
|
|
) {
|
|
|
|
|
$this->checkParsoidInstalled();
|
|
|
|
|
|
|
|
|
|
$page = $this->getExistingTestPage( 'HtmlEndpointTestPage/with/slashes' );
|
|
|
|
|
$request = new RequestData(
|
|
|
|
|
[ 'pathParams' => [ 'title' => $page->getTitle()->getPrefixedText() ] ]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$parsoid = $this->createNoOpMock( Parsoid::class, [ 'wikitext2html' ] );
|
|
|
|
|
$parsoid->expects( $this->once() )
|
|
|
|
|
->method( 'wikitext2html' )
|
|
|
|
|
->willThrowException( $parsoidException );
|
|
|
|
|
|
2022-05-16 16:56:20 +00:00
|
|
|
$handler = $this->newHandler( $parsoid );
|
2020-11-19 18:53:05 +00:00
|
|
|
$this->expectExceptionObject( $expectedException );
|
|
|
|
|
$this->executeHandler( $handler, $request, [
|
|
|
|
|
'format' => 'html'
|
|
|
|
|
] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testExecute_missingparam() {
|
|
|
|
|
$request = new RequestData();
|
|
|
|
|
|
|
|
|
|
$this->expectExceptionObject(
|
|
|
|
|
new LocalizedHttpException(
|
|
|
|
|
new MessageValue( "paramvalidator-missingparam", [ 'title' ] ),
|
|
|
|
|
400
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$handler = $this->newHandler();
|
|
|
|
|
$this->executeHandler( $handler, $request );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testExecute_error() {
|
|
|
|
|
$request = new RequestData( [ 'pathParams' => [ 'title' => 'DoesNotExist8237456assda1234' ] ] );
|
|
|
|
|
|
|
|
|
|
$this->expectExceptionObject(
|
|
|
|
|
new LocalizedHttpException(
|
|
|
|
|
new MessageValue( "rest-nonexistent-title", [ 'testing' ] ),
|
|
|
|
|
404
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$handler = $this->newHandler();
|
|
|
|
|
$this->executeHandler( $handler, $request );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param WikiPage $page
|
|
|
|
|
* @param array $data
|
|
|
|
|
*/
|
|
|
|
|
private function assertResponseData( WikiPage $page, array $data ): void {
|
|
|
|
|
$this->assertSame( $page->getId(), $data['id'] );
|
|
|
|
|
$this->assertSame( $page->getTitle()->getPrefixedDBkey(), $data['key'] );
|
|
|
|
|
$this->assertSame( $page->getTitle()->getPrefixedText(), $data['title'] );
|
|
|
|
|
$this->assertSame( $page->getLatest(), $data['latest']['id'] );
|
|
|
|
|
$this->assertSame(
|
|
|
|
|
wfTimestampOrNull( TS_ISO_8601, $page->getTimestamp() ),
|
|
|
|
|
$data['latest']['timestamp']
|
|
|
|
|
);
|
|
|
|
|
$this->assertSame( CONTENT_MODEL_WIKITEXT, $data['content_model'] );
|
|
|
|
|
$this->assertSame( 'https://example.com/rights', $data['license']['url'] );
|
|
|
|
|
$this->assertSame( 'some rights', $data['license']['title'] );
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-16 16:56:20 +00:00
|
|
|
/**
|
|
|
|
|
* Request One:
|
|
|
|
|
*
|
|
|
|
|
* When a request is made with no stash entries in the stash and stashing
|
|
|
|
|
* is set to false, don't stash anything. At this point, the stash is empty.
|
|
|
|
|
*
|
|
|
|
|
* Request Two:
|
|
|
|
|
*
|
|
|
|
|
* Once a request is made with stashing option set to true, we should have
|
|
|
|
|
* one entry in parsoid stash. So at this point, the stash is no longer empty
|
|
|
|
|
* as before.
|
|
|
|
|
*
|
|
|
|
|
* Request Three:
|
|
|
|
|
*
|
|
|
|
|
* Upon the third request, there is already a stash entry and if the 3rd request's
|
|
|
|
|
* stashing option is set to false, we're not invalidating the stash entries that
|
|
|
|
|
* exiting with the UUID. So, if we request a parsoid stashed object from the stash
|
|
|
|
|
* with a given UUID that exist, we should have a hit.
|
|
|
|
|
*/
|
|
|
|
|
public function testExecuteStashParsoidOutput() {
|
|
|
|
|
$page = $this->getExistingTestPage();
|
|
|
|
|
$outputStash = $this->getParsoidOutputStash();
|
|
|
|
|
|
|
|
|
|
[ /* $html1 */, $etag1, $stashKey1 ] = $this->executePageHTMLRequest( $page );
|
|
|
|
|
$this->assertNull( $outputStash->get( $stashKey1 ) );
|
|
|
|
|
|
|
|
|
|
[ /* $html2 */, $etag2, $stashKey2 ] = $this->executePageHTMLRequest( $page, [ 'stash' => true ] );
|
|
|
|
|
$this->assertNotNull( $outputStash->get( $stashKey2 ) );
|
|
|
|
|
|
|
|
|
|
[ /* $html3 */, $etag3, $stashKey3 ] = $this->executePageHTMLRequest( $page );
|
|
|
|
|
/**
|
|
|
|
|
* The stash for the previous request should still live at this point.
|
|
|
|
|
*/
|
|
|
|
|
$this->assertNotNull( $outputStash->get( $stashKey2 ) );
|
|
|
|
|
$this->assertNotNull( $outputStash->get( $stashKey3 ) );
|
|
|
|
|
$this->assertSame( $etag1, $etag3 );
|
|
|
|
|
$this->assertNotSame( $etag1, $etag2 );
|
|
|
|
|
|
|
|
|
|
// Make sure the output for stashed and unstashed doesn't have the same tag,
|
|
|
|
|
// since it will actually be different!
|
|
|
|
|
// FIXME: implement flavors and write test cases for them.
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-24 21:13:42 +00:00
|
|
|
public function testETagVariesOnFormat() {
|
|
|
|
|
$page = $this->getExistingTestPage();
|
|
|
|
|
|
|
|
|
|
[ /* $html1 */, $etag1 ] =
|
|
|
|
|
$this->executePageHTMLRequest( $page, [], [ 'format' => 'html' ] );
|
|
|
|
|
|
|
|
|
|
[ /* $html2 */, $etag2 ] =
|
|
|
|
|
$this->executePageHTMLRequest( $page, [], [ 'format' => 'with_html' ] );
|
|
|
|
|
|
|
|
|
|
$this->assertNotSame( $etag1, $etag2 );
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-13 09:31:50 +00:00
|
|
|
public function testStashingWithRateLimitExceeded() {
|
|
|
|
|
// Set the rate limit to 1 request per minute
|
2022-06-21 12:56:19 +00:00
|
|
|
$this->overrideConfigValue(
|
|
|
|
|
'RateLimits',
|
2022-06-13 09:31:50 +00:00
|
|
|
[
|
|
|
|
|
'stashbasehtml' => [
|
|
|
|
|
'&can-bypass' => false,
|
|
|
|
|
'ip' => [ 1, 60 ],
|
|
|
|
|
'newbie' => [ 1, 60 ]
|
|
|
|
|
]
|
|
|
|
|
] );
|
2022-06-21 12:56:19 +00:00
|
|
|
$this->setMainCache( CACHE_HASH );
|
2022-06-13 09:31:50 +00:00
|
|
|
|
|
|
|
|
$page = $this->getExistingTestPage();
|
|
|
|
|
|
|
|
|
|
$this->executePageHTMLRequest( $page, [ 'stash' => true ] );
|
|
|
|
|
// In this request, the rate limit has been exceeded, so it should throw.
|
|
|
|
|
$this->expectException( LocalizedHttpException::class );
|
|
|
|
|
$this->expectExceptionCode( 429 );
|
|
|
|
|
$this->executePageHTMLRequest( $page, [ 'stash' => true ] );
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-19 18:53:05 +00:00
|
|
|
}
|