aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Url/WhitelistProtocolsTest.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2018-12-03 00:34:53 +0100
committerVirtualTam <virtualtam@flibidi.net>2019-01-12 22:47:48 +0100
commit51753e403fa69c0ce124ede27d300477e3e799ca (patch)
tree0afe2a84598648b49cc53bb3e8640569ac370240 /tests/Url/WhitelistProtocolsTest.php
parentfb1b182fbf0ee5afed586f77eec84d7a906831ef (diff)
downloadShaarli-51753e403fa69c0ce124ede27d300477e3e799ca.tar.gz
Shaarli-51753e403fa69c0ce124ede27d300477e3e799ca.tar.zst
Shaarli-51753e403fa69c0ce124ede27d300477e3e799ca.zip
namespacing: move HTTP utilities along \Shaarli\Http\ classes
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'tests/Url/WhitelistProtocolsTest.php')
-rw-r--r--tests/Url/WhitelistProtocolsTest.php63
1 files changed, 0 insertions, 63 deletions
diff --git a/tests/Url/WhitelistProtocolsTest.php b/tests/Url/WhitelistProtocolsTest.php
deleted file mode 100644
index a3156804..00000000
--- a/tests/Url/WhitelistProtocolsTest.php
+++ /dev/null
@@ -1,63 +0,0 @@
1<?php
2
3require_once 'application/Url.php';
4
5use Shaarli\Config\ConfigManager;
6
7/**
8 * Class WhitelistProtocolsTest
9 *
10 * Test whitelist_protocols() function of Url.
11 */
12class WhitelistProtocolsTest extends PHPUnit_Framework_TestCase
13{
14 /**
15 * Test whitelist_protocols() on a note (relative URL).
16 */
17 public function testWhitelistProtocolsRelative()
18 {
19 $whitelist = ['ftp', 'magnet'];
20 $url = '?12443564';
21 $this->assertEquals($url, whitelist_protocols($url, $whitelist));
22 $url = '/path.jpg';
23 $this->assertEquals($url, whitelist_protocols($url, $whitelist));
24 }
25
26 /**
27 * Test whitelist_protocols() on a note (relative URL).
28 */
29 public function testWhitelistProtocolMissing()
30 {
31 $whitelist = ['ftp', 'magnet'];
32 $url = 'test.tld/path/?query=value#hash';
33 $this->assertEquals('http://'. $url, whitelist_protocols($url, $whitelist));
34 }
35
36 /**
37 * Test whitelist_protocols() with allowed protocols.
38 */
39 public function testWhitelistAllowedProtocol()
40 {
41 $whitelist = ['ftp', 'magnet'];
42 $url = 'http://test.tld/path/?query=value#hash';
43 $this->assertEquals($url, whitelist_protocols($url, $whitelist));
44 $url = 'https://test.tld/path/?query=value#hash';
45 $this->assertEquals($url, whitelist_protocols($url, $whitelist));
46 $url = 'ftp://test.tld/path/?query=value#hash';
47 $this->assertEquals($url, whitelist_protocols($url, $whitelist));
48 $url = 'magnet:test.tld/path/?query=value#hash';
49 $this->assertEquals($url, whitelist_protocols($url, $whitelist));
50 }
51
52 /**
53 * Test whitelist_protocols() with allowed protocols.
54 */
55 public function testWhitelistDisallowedProtocol()
56 {
57 $whitelist = ['ftp', 'magnet'];
58 $url = 'javascript:alert("xss");';
59 $this->assertEquals('http://alert("xss");', whitelist_protocols($url, $whitelist));
60 $url = 'other://test.tld/path/?query=value#hash';
61 $this->assertEquals('http://test.tld/path/?query=value#hash', whitelist_protocols($url, $whitelist));
62 }
63}