summaryrefslogtreecommitdiff
path: root/www/wiki/tests/phpunit/includes/externalstore/ExternalStoreTest.php
blob: 7ca38749fabb7681d403a1b00b9c1fc52a72a4a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php

class ExternalStoreTest extends MediaWikiTestCase {

	/**
	 * @covers ExternalStore::fetchFromURL
	 */
	public function testExternalFetchFromURL_noExternalStores() {
		$this->setService(
			'ExternalStoreFactory',
			new ExternalStoreFactory( [] )
		);

		$this->assertFalse(
			ExternalStore::fetchFromURL( 'ForTesting://cluster1/200' ),
			'Deny if wgExternalStores is not set to a non-empty array'
		);
	}

	/**
	 * @covers ExternalStore::fetchFromURL
	 */
	public function testExternalFetchFromURL_someExternalStore() {
		$this->setService(
			'ExternalStoreFactory',
			new ExternalStoreFactory( [ 'ForTesting' ] )
		);

		$this->assertEquals(
			'Hello',
			ExternalStore::fetchFromURL( 'ForTesting://cluster1/200' ),
			'Allow FOO://cluster1/200'
		);
		$this->assertEquals(
			'Hello',
			ExternalStore::fetchFromURL( 'ForTesting://cluster1/300/0' ),
			'Allow FOO://cluster1/300/0'
		);
		# Assertions for r68900
		$this->assertFalse(
			ExternalStore::fetchFromURL( 'ftp.example.org' ),
			'Deny domain ftp.example.org'
		);
		$this->assertFalse(
			ExternalStore::fetchFromURL( '/example.txt' ),
			'Deny path /example.txt'
		);
		$this->assertFalse(
			ExternalStore::fetchFromURL( 'http://' ),
			'Deny protocol http://'
		);
	}
}