2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
2020-06-30 15:09:24 +00:00
|
|
|
class ExternalStoreTest extends MediaWikiIntegrationTestCase {
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2013-10-24 10:54:02 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ExternalStore::fetchFromURL
|
|
|
|
|
*/
|
2017-11-14 11:17:34 +00:00
|
|
|
public function testExternalFetchFromURL_noExternalStores() {
|
|
|
|
|
$this->setService(
|
|
|
|
|
'ExternalStoreFactory',
|
2018-02-27 06:24:46 +00:00
|
|
|
new ExternalStoreFactory( [], [], 'test-id' )
|
2017-11-14 11:17:34 +00:00
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$this->assertFalse(
|
2017-11-14 11:17:34 +00:00
|
|
|
ExternalStore::fetchFromURL( 'ForTesting://cluster1/200' ),
|
2012-10-08 10:56:20 +00:00
|
|
|
'Deny if wgExternalStores is not set to a non-empty array'
|
|
|
|
|
);
|
2017-11-14 11:17:34 +00:00
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideFetchFromURLWithStore() {
|
2021-03-08 03:14:43 +00:00
|
|
|
yield [ 'Hello', 'ForTesting://cluster1/200', 'Allow FOO://cluster1/200' ];
|
|
|
|
|
yield [ 'Hello', 'ForTesting://cluster1/300/0', 'Allow FOO://cluster1/300/0' ];
|
|
|
|
|
|
|
|
|
|
// cases for r68900
|
|
|
|
|
yield [ false, 'ftp.example.org', 'Deny domain ftp.example.org' ];
|
|
|
|
|
yield [ false, '/example.txt', 'Deny path /example.txt' ];
|
|
|
|
|
yield [ false, 'http://', 'Deny protocol http://' ];
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 11:17:34 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ExternalStore::fetchFromURL
|
2021-03-08 03:14:43 +00:00
|
|
|
* @dataProvider provideFetchFromURLWithStore
|
2017-11-14 11:17:34 +00:00
|
|
|
*/
|
2021-03-08 03:14:43 +00:00
|
|
|
public function testExternalFetchFromURL_someExternalStore( $expect, $url, $msg ) {
|
2017-11-14 11:17:34 +00:00
|
|
|
$this->setService(
|
|
|
|
|
'ExternalStoreFactory',
|
2018-02-27 06:24:46 +00:00
|
|
|
new ExternalStoreFactory( [ 'ForTesting' ], [ 'ForTesting://cluster1' ], 'test-id' )
|
2017-11-14 11:17:34 +00:00
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2021-03-08 03:14:43 +00:00
|
|
|
$this->assertSame( $expect, ExternalStore::fetchFromURL( $url ), $msg );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
}
|