| 1 |
<?php |
| 2 |
|
| 3 |
class ExternalStoreTest extends MediaWikiIntegrationTestCase { |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
public function testExternalFetchFromURL_noExternalStores() { |
| 9 |
$this->setService( |
| 10 |
'ExternalStoreFactory', |
| 11 |
new ExternalStoreFactory( [], [], 'test-id' ) |
| 12 |
); |
| 13 |
|
| 14 |
$this->assertFalse( |
| 15 |
ExternalStore::fetchFromURL( 'ForTesting://cluster1/200' ), |
| 16 |
'Deny if wgExternalStores is not set to a non-empty array' |
| 17 |
); |
| 18 |
} |
| 19 |
|
| 20 |
public static function provideFetchFromURLWithStore() { |
| 21 |
yield [ 'Hello', 'ForTesting://cluster1/200', 'Allow ForTesting://cluster1/200' ]; |
| 22 |
yield [ 'Hello', 'ForTesting://cluster1/300/0', 'Allow ForTesting://cluster1/300/0' ]; |
| 23 |
|
| 24 |
|
| 25 |
yield [ false, 'ftp.example.org', 'Deny domain ftp.example.org' ]; |
| 26 |
yield [ false, '/example.txt', 'Deny path /example.txt' ]; |
| 27 |
yield [ false, 'http://', 'Deny protocol http://' ]; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public function testExternalFetchFromURL_someExternalStore( $expect, $url, $msg ) { |
| 35 |
$this->setService( |
| 36 |
'ExternalStoreFactory', |
| 37 |
new ExternalStoreFactory( [ 'ForTesting' ], [ 'ForTesting://cluster1' ], 'test-id' ) |
| 38 |
); |
| 39 |
|
| 40 |
$this->assertSame( $expect, ExternalStore::fetchFromURL( $url ), $msg ); |
| 41 |
} |
| 42 |
} |