2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
2010-12-28 18:17:16 +00:00
|
|
|
class ExternalStoreTest extends MediaWikiTestCase {
|
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',
|
|
|
|
|
new ExternalStoreFactory( [] )
|
|
|
|
|
);
|
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
|
|
|
|
2017-11-14 11:17:34 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ExternalStore::fetchFromURL
|
|
|
|
|
*/
|
|
|
|
|
public function testExternalFetchFromURL_someExternalStore() {
|
|
|
|
|
$this->setService(
|
|
|
|
|
'ExternalStoreFactory',
|
|
|
|
|
new ExternalStoreFactory( [ 'ForTesting' ] )
|
|
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
'Hello',
|
2017-11-14 11:17:34 +00:00
|
|
|
ExternalStore::fetchFromURL( 'ForTesting://cluster1/200' ),
|
2012-10-08 10:56:20 +00:00
|
|
|
'Allow FOO://cluster1/200'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'Hello',
|
2017-11-14 11:17:34 +00:00
|
|
|
ExternalStore::fetchFromURL( 'ForTesting://cluster1/300/0' ),
|
2012-10-08 10:56:20 +00:00
|
|
|
'Allow FOO://cluster1/300/0'
|
|
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
# Assertions for r68900
|
|
|
|
|
$this->assertFalse(
|
2012-10-08 10:56:20 +00:00
|
|
|
ExternalStore::fetchFromURL( 'ftp.example.org' ),
|
|
|
|
|
'Deny domain ftp.example.org'
|
|
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertFalse(
|
2012-10-08 10:56:20 +00:00
|
|
|
ExternalStore::fetchFromURL( '/example.txt' ),
|
|
|
|
|
'Deny path /example.txt'
|
|
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
$this->assertFalse(
|
2012-10-08 10:56:20 +00:00
|
|
|
ExternalStore::fetchFromURL( 'http://' ),
|
|
|
|
|
'Deny protocol http://'
|
|
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
}
|