2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* External Store tests
|
|
|
|
|
*/
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testExternalFetchFromURL() {
|
2012-10-08 10:56:20 +00:00
|
|
|
$this->setMwGlobals( 'wgExternalStores', false );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$this->assertFalse(
|
|
|
|
|
ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
|
|
|
|
|
'Deny if wgExternalStores is not set to a non-empty array'
|
|
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$this->setMwGlobals( 'wgExternalStores', array( 'FOO' ) );
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
ExternalStore::fetchFromURL( 'FOO://cluster1/200' ),
|
|
|
|
|
'Hello',
|
|
|
|
|
'Allow FOO://cluster1/200'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
ExternalStore::fetchFromURL( 'FOO://cluster1/300/0' ),
|
|
|
|
|
'Hello',
|
|
|
|
|
'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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
class ExternalStoreFOO {
|
|
|
|
|
|
|
|
|
|
protected $data = array(
|
|
|
|
|
'cluster1' => array(
|
|
|
|
|
'200' => 'Hello',
|
|
|
|
|
'300' => array(
|
|
|
|
|
'Hello', 'World',
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch data from given URL
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param string $url An url of the form FOO://cluster/id or FOO://cluster/id/itemid.
|
2012-10-08 10:56:20 +00:00
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
function fetchFromURL( $url ) {
|
|
|
|
|
// Based on ExternalStoreDB
|
|
|
|
|
$path = explode( '/', $url );
|
|
|
|
|
$cluster = $path[2];
|
|
|
|
|
$id = $path[3];
|
|
|
|
|
if ( isset( $path[4] ) ) {
|
|
|
|
|
$itemID = $path[4];
|
|
|
|
|
} else {
|
|
|
|
|
$itemID = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !isset( $this->data[$cluster][$id] ) ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-24 09:57:41 +00:00
|
|
|
if ( $itemID !== false
|
|
|
|
|
&& is_array( $this->data[$cluster][$id] )
|
|
|
|
|
&& isset( $this->data[$cluster][$id][$itemID] )
|
|
|
|
|
) {
|
2012-10-08 10:56:20 +00:00
|
|
|
return $this->data[$cluster][$id][$itemID];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->data[$cluster][$id];
|
|
|
|
|
}
|
2013-01-28 10:27:15 +00:00
|
|
|
}
|