-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathting_proxy.test
155 lines (136 loc) · 4.35 KB
/
ting_proxy.test
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* Test to ensure that proxy url rewrites work as adverticed.
*/
class TingProxyTestCase extends DrupalUnitTestCase {
static function getInfo() {
return array(
'name' => 'Ting proxy',
'description' => 'Check if urls are rewritten to use proxies',
'group' => 'Ding! - Ting proxy',
);
}
private $proxy_url;
private $urls;
public function setUp() {
parent::setUp();
$this->proxy_url = 'http://myproxy.com/proxy?';
$this->urls = array(
'http://www.host1.com/part1/index.html',
'http://www.host1.com/part1/part2/index.html',
'http://www.host2.com/part1/index.html',
'http://www.host2.com/part1/part2/index.html',
);
}
public function testRewriteNoConfig() {
drupal_load('module', 'ting_proxy');
$config = array();
foreach ($this->urls as $url) {
$url_rewrite = ting_proxy_rewrite_download_url($url, $this->proxy_url, $config);
// Urls should not be rewritten without a configuration
$this->assertEqual($url, $url_rewrite);
}
}
public function testRewriteNoHostnameMatch() {
drupal_load('module', 'ting_proxy');
$config = array(
array(
'hostname' => 'host1.com',
'expression' => array(
'regex' => '/part1/',
'replacement' => 'part3'
),
'disable_prefix' => 0,
),
);
foreach ($this->urls as $url) {
$url_rewrite = ting_proxy_rewrite_download_url($url, $this->proxy_url, $config);
// Urls should not be rewritten if hostnames does not match
$this->assertEqual($url, $url_rewrite);
}
}
public function testRewriteReplace() {
drupal_load('module', 'ting_proxy');
$config = array(
array(
'hostname' => 'www.host1.com',
'expression' => array(
'regex' => '/part1/',
'replacement' => 'part3'
),
'disable_prefix' => 1,
),
);
foreach ($this->urls as $url) {
$url_rewrite = ting_proxy_rewrite_download_url($url, $this->proxy_url, $config);
if (parse_url($url, PHP_URL_HOST) == 'www.host1.com' && strpos($url, '/part1/') !== FALSE) {
// Url components should be replaced if hostnames match
$url = preg_replace('/part1/', 'part3', $url);
$this->assertEqual($url, $url_rewrite);
}
}
}
public function testRewritePrefix() {
drupal_load('module', 'ting_proxy');
$config = array(
array(
'hostname' => 'www.host1.com',
'expression' => array(),
'disable_prefix' => 0,
),
);
foreach ($this->urls as $url) {
$url_rewrite = ting_proxy_rewrite_download_url($url, $this->proxy_url, $config);
if (parse_url($url, PHP_URL_HOST) == 'www.host1.com') {
// Prefix should be added if hostnames match
$this->assertEqual($url_rewrite, $this->proxy_url . urlencode($url));
}
}
}
public function testRewriteReplacePrefix() {
drupal_load('module', 'ting_proxy');
$config = array(
array(
'hostname' => 'www.host1.com',
'expression' => array(
'regex' => '/part1/',
'replacement' => 'part3'
),
'disable_prefix' => 0,
),
);
foreach ($this->urls as $url) {
$url_rewrite = ting_proxy_rewrite_download_url($url, $this->proxy_url, $config);
if (parse_url($url, PHP_URL_HOST) == 'www.host1.com') {
$url = preg_replace('/part1/', 'part3', $url);
// Prefix should be added and components replaced if hostnames match
$this->assertEqual($url_rewrite, $this->proxy_url . urlencode($url));
}
}
}
public function testRewriteFirstConfigPriority() {
drupal_load('module', 'ting_proxy');
$config = array(
array(
'hostname' => 'www.host1.com',
'expression' => array(),
'disable_prefix' => 0,
),
array(
'hostname' => 'www.host1.com',
'expression' => array(
'regex' => '/part1/',
'replacement' => 'part3',
),
'disable_prefix' => 1,
),
);
foreach ($this->urls as $url) {
$url_rewrite = ting_proxy_rewrite_download_url($url, $this->proxy_url, $config);
if (parse_url($url, PHP_URL_HOST) == 'www.host1.com') {
// If multiple hostnames match an url only the first should be executed.
$this->assertEqual($url_rewrite, $this->proxy_url . urlencode($url));
}
}
}
}