|
1 /* |
|
2 libconninet - Internet Connectivity support library |
|
3 |
|
4 Copyright (C) 2010 Nokia Corporation. All rights reserved. |
|
5 |
|
6 Contact: Jukka Rissanen <jukka.rissanen@nokia.com> |
|
7 |
|
8 This library is free software; you can redistribute it and/or |
|
9 modify it under the terms of the GNU Lesser General Public License |
|
10 version 2.1 as published by the Free Software Foundation. |
|
11 |
|
12 This library is distributed in the hope that it will be useful, but |
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 Lesser General Public License for more details. |
|
16 |
|
17 You should have received a copy of the GNU Lesser General Public |
|
18 License along with this library; if not, write to the Free Software |
|
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
|
20 02110-1301 USA |
|
21 */ |
|
22 |
|
23 |
|
24 #include <QtTest/QtTest> |
|
25 #include <QDebug> |
|
26 #include <QNetworkProxy> |
|
27 #include <conn_settings.h> |
|
28 |
|
29 #include "../src/proxyconf.h" |
|
30 |
|
31 class Ut_ProxyConf : public QObject |
|
32 { |
|
33 Q_OBJECT |
|
34 |
|
35 private Q_SLOTS: |
|
36 void init(); |
|
37 void cleanup(); |
|
38 void initTestCase(); |
|
39 void cleanupTestCase(); |
|
40 |
|
41 // tests without the factory |
|
42 void proxy_ftp_no_factory_ok_auto(); |
|
43 void proxy_ftp_no_factory_ok_manual(); |
|
44 void proxy_http_no_factory_ok_manual(); |
|
45 void proxy_https_no_factory_ok_manual(); |
|
46 void proxy_socks_no_factory_ok_manual(); |
|
47 void proxy_default_no_factory_ok_manual(); |
|
48 |
|
49 // tests using the factory |
|
50 void proxy_ftp_factory_ok_auto(); |
|
51 void proxy_ftp_factory_ok_manual(); |
|
52 void proxy_http_factory_ok_manual(); |
|
53 void proxy_https_factory_ok_manual(); |
|
54 void proxy_socks_factory_ok_manual(); |
|
55 void proxy_http_factory_ok_manual_clear(); |
|
56 void proxy_default_factory_ok_manual(); |
|
57 void proxy_http_factory_ok_manual_ignore_list(); |
|
58 void proxy_default_factory_ok_manual_system(); |
|
59 |
|
60 private: |
|
61 Maemo::ProxyConf *pc; |
|
62 }; |
|
63 |
|
64 |
|
65 void put(QString var, QString type, QString value) |
|
66 { |
|
67 QProcess gconf; |
|
68 if (value.isEmpty()) |
|
69 gconf.start(QString("gconftool-2 -u /system/proxy/"+var)); |
|
70 else |
|
71 gconf.start(QString("gconftool-2 -s /system/proxy/"+var+" -t "+type+" "+value)); |
|
72 gconf.waitForFinished(); |
|
73 } |
|
74 |
|
75 void put_http(QString var, QString type, QString value) |
|
76 { |
|
77 QProcess gconf; |
|
78 if (value.isEmpty()) |
|
79 gconf.start(QString("gconftool-2 -u /system/http_proxy/"+var)); |
|
80 else |
|
81 gconf.start(QString("gconftool-2 -s /system/http_proxy/"+var+" -t "+type+" "+value)); |
|
82 gconf.waitForFinished(); |
|
83 } |
|
84 |
|
85 void put_list(QString var, QString type, QList<QString> value) |
|
86 { |
|
87 QProcess gconf; |
|
88 QString values = "["; |
|
89 foreach (QString str, value) |
|
90 values = values + str + ","; |
|
91 values.chop(1); |
|
92 values = values + "]"; |
|
93 |
|
94 gconf.start(QString("gconftool-2 -s /system/http_proxy/"+var+" -t list --list-type="+type+" "+values)); |
|
95 gconf.waitForFinished(); |
|
96 } |
|
97 |
|
98 |
|
99 void Ut_ProxyConf::init() |
|
100 { |
|
101 put_http("host", "string", "my.proxy.com"); |
|
102 put_http("port", "int", "8080"); |
|
103 |
|
104 QList<QString> list; |
|
105 list.append("foo.bar.com"); |
|
106 list.append("192.168.19.69"); |
|
107 list.append("192.168.20.0/24"); |
|
108 list.append("bar.foo.com"); |
|
109 put_list("ignore_hosts", "string", list); |
|
110 put_http("use_http_host", "boolean", "true"); |
|
111 |
|
112 put("mode", "string", "auto"); |
|
113 put("autoconfig_url", "string", "http://foo.bar.com/autoconf"); |
|
114 put("secure_host", "string", "secure_host.com"); |
|
115 put("secure_port", "int", "112"); |
|
116 |
|
117 put("ftp_host", "string", "ftp.nuukia.com"); |
|
118 put("ftp_port", "int", "2000"); |
|
119 put("socks_host", "string", "socks.host.com"); |
|
120 put("socks_port", "int", "10080"); |
|
121 put("rtsp_host", "string", "rtsp.voice.com"); |
|
122 put("rtsp_port", "int", "1554"); |
|
123 |
|
124 pc = new Maemo::ProxyConf(); |
|
125 } |
|
126 |
|
127 void Ut_ProxyConf::cleanup() |
|
128 { |
|
129 delete pc; |
|
130 pc = 0; |
|
131 } |
|
132 |
|
133 void Ut_ProxyConf::initTestCase() |
|
134 { |
|
135 } |
|
136 |
|
137 void Ut_ProxyConf::cleanupTestCase() |
|
138 { |
|
139 } |
|
140 |
|
141 |
|
142 void Ut_ProxyConf::proxy_ftp_no_factory_ok_auto() |
|
143 { |
|
144 QList<QNetworkProxy> nplist; |
|
145 QNetworkProxyQuery query = QNetworkProxyQuery(QUrl("ftp://maps.google.com/")); |
|
146 |
|
147 nplist = pc->flush(query); |
|
148 QVERIFY(nplist.length()==0); |
|
149 } |
|
150 |
|
151 |
|
152 void Ut_ProxyConf::proxy_ftp_no_factory_ok_manual() |
|
153 { |
|
154 QList<QNetworkProxy> nplist; |
|
155 QNetworkProxyQuery query = QNetworkProxyQuery(QUrl("ftp://maps.google.com/")); |
|
156 |
|
157 put("mode", "string", "manual"); |
|
158 |
|
159 nplist = pc->flush(query); |
|
160 foreach (QNetworkProxy proxy, nplist) { |
|
161 qDebug() << "proxy: " << proxy.hostName() << "port" << proxy.port(); |
|
162 } |
|
163 QVERIFY(nplist.length()==3); |
|
164 QVERIFY(nplist.first().type() == QNetworkProxy::FtpCachingProxy); |
|
165 } |
|
166 |
|
167 |
|
168 void Ut_ProxyConf::proxy_http_no_factory_ok_manual() |
|
169 { |
|
170 QList<QNetworkProxy> nplist; |
|
171 QNetworkProxyQuery query = QNetworkProxyQuery(QUrl("http://maps.google.com/")); |
|
172 |
|
173 put("mode", "string", "manual"); |
|
174 |
|
175 nplist = pc->flush(query); |
|
176 foreach (QNetworkProxy proxy, nplist) { |
|
177 qDebug() << "proxy: " << proxy.hostName() << "port" << proxy.port(); |
|
178 } |
|
179 QVERIFY(nplist.length()==3); |
|
180 QVERIFY(nplist.first().type() == QNetworkProxy::HttpProxy); |
|
181 } |
|
182 |
|
183 |
|
184 void Ut_ProxyConf::proxy_https_no_factory_ok_manual() |
|
185 { |
|
186 QList<QNetworkProxy> nplist; |
|
187 QNetworkProxyQuery query = QNetworkProxyQuery(QUrl("https://maps.google.com/")); |
|
188 |
|
189 put("mode", "string", "manual"); |
|
190 |
|
191 nplist = pc->flush(query); |
|
192 foreach (QNetworkProxy proxy, nplist) { |
|
193 qDebug() << "proxy: " << proxy.hostName() << "port" << proxy.port(); |
|
194 } |
|
195 QVERIFY(nplist.length()==2); |
|
196 QVERIFY(nplist.first().type() == QNetworkProxy::HttpProxy); |
|
197 } |
|
198 |
|
199 |
|
200 void Ut_ProxyConf::proxy_socks_no_factory_ok_manual() |
|
201 { |
|
202 QList<QNetworkProxy> nplist; |
|
203 QNetworkProxyQuery query = QNetworkProxyQuery(QUrl("http://maps.google.com/")); |
|
204 |
|
205 put("mode", "string", "manual"); |
|
206 put_http("host", "string", ""); |
|
207 |
|
208 nplist = pc->flush(query); |
|
209 foreach (QNetworkProxy proxy, nplist) { |
|
210 qDebug() << "proxy: " << proxy.hostName() << "port" << proxy.port(); |
|
211 } |
|
212 QVERIFY(nplist.length()==2); |
|
213 QVERIFY(nplist.first().type() == QNetworkProxy::Socks5Proxy); |
|
214 } |
|
215 |
|
216 |
|
217 void Ut_ProxyConf::proxy_default_no_factory_ok_manual() |
|
218 { |
|
219 QList<QNetworkProxy> nplist; |
|
220 QNetworkProxyQuery query = QNetworkProxyQuery(QUrl("foobar://maps.google.com/")); |
|
221 |
|
222 put("mode", "string", "manual"); |
|
223 put("socks_host", "string", ""); |
|
224 put("secure_host", "string", ""); |
|
225 |
|
226 nplist = pc->flush(query); |
|
227 foreach (QNetworkProxy proxy, nplist) { |
|
228 qDebug() << "proxy: " << proxy.hostName() << "port" << proxy.port(); |
|
229 } |
|
230 QVERIFY(nplist.length()==0); |
|
231 } |
|
232 |
|
233 |
|
234 void Ut_ProxyConf::proxy_ftp_factory_ok_auto() |
|
235 { |
|
236 QNetworkProxyQuery query = QNetworkProxyQuery(QUrl("ftp://maps.google.com/")); |
|
237 Maemo::ProxyConf::update(); |
|
238 QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::proxyForQuery(query); |
|
239 QVERIFY(listOfProxies.length()==1); |
|
240 QVERIFY(listOfProxies.first().type() == QNetworkProxy::NoProxy); |
|
241 Maemo::ProxyConf::clear(); |
|
242 } |
|
243 |
|
244 |
|
245 void Ut_ProxyConf::proxy_ftp_factory_ok_manual() |
|
246 { |
|
247 QNetworkProxyQuery query = QNetworkProxyQuery(QUrl("ftp://maps.google.com/")); |
|
248 Maemo::ProxyConf::update(); |
|
249 |
|
250 put("mode", "string", "manual"); |
|
251 |
|
252 QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::proxyForQuery(query); |
|
253 |
|
254 foreach (QNetworkProxy proxy, listOfProxies) { |
|
255 qDebug() << "proxy: " << proxy.hostName() << "port" << proxy.port(); |
|
256 } |
|
257 QVERIFY(listOfProxies.length()==3); |
|
258 QVERIFY(listOfProxies.first().type() == QNetworkProxy::FtpCachingProxy); |
|
259 Maemo::ProxyConf::clear(); |
|
260 } |
|
261 |
|
262 |
|
263 void Ut_ProxyConf::proxy_http_factory_ok_manual() |
|
264 { |
|
265 QNetworkProxyQuery query = QNetworkProxyQuery(QUrl("http://maps.google.com/")); |
|
266 Maemo::ProxyConf::update(); |
|
267 |
|
268 put("mode", "string", "manual"); |
|
269 |
|
270 QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::proxyForQuery(query); |
|
271 |
|
272 foreach (QNetworkProxy proxy, listOfProxies) { |
|
273 qDebug() << "proxy: " << proxy.hostName() << "port" << proxy.port(); |
|
274 } |
|
275 QVERIFY(listOfProxies.length()==3); |
|
276 QVERIFY(listOfProxies.first().type() == QNetworkProxy::HttpProxy); |
|
277 Maemo::ProxyConf::clear(); |
|
278 } |
|
279 |
|
280 |
|
281 void Ut_ProxyConf::proxy_https_factory_ok_manual() |
|
282 { |
|
283 QNetworkProxyQuery query = QNetworkProxyQuery(QUrl("https://maps.google.com/")); |
|
284 Maemo::ProxyConf::update(); |
|
285 |
|
286 put("mode", "string", "manual"); |
|
287 |
|
288 QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::proxyForQuery(query); |
|
289 |
|
290 foreach (QNetworkProxy proxy, listOfProxies) { |
|
291 qDebug() << "proxy: " << proxy.hostName() << "port" << proxy.port(); |
|
292 } |
|
293 QVERIFY(listOfProxies.length()==2); |
|
294 QVERIFY(listOfProxies.first().type() == QNetworkProxy::HttpProxy); |
|
295 Maemo::ProxyConf::clear(); |
|
296 } |
|
297 |
|
298 |
|
299 void Ut_ProxyConf::proxy_socks_factory_ok_manual() |
|
300 { |
|
301 QNetworkProxyQuery query = QNetworkProxyQuery(QUrl("http://maps.google.com/")); |
|
302 Maemo::ProxyConf::update(); |
|
303 |
|
304 put("mode", "string", "manual"); |
|
305 put_http("host", "string", ""); |
|
306 |
|
307 QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::proxyForQuery(query); |
|
308 |
|
309 foreach (QNetworkProxy proxy, listOfProxies) { |
|
310 qDebug() << "proxy: " << proxy.hostName() << "port" << proxy.port(); |
|
311 } |
|
312 QVERIFY(listOfProxies.length()==2); |
|
313 QVERIFY(listOfProxies.first().type() == QNetworkProxy::Socks5Proxy); |
|
314 Maemo::ProxyConf::clear(); |
|
315 } |
|
316 |
|
317 |
|
318 void Ut_ProxyConf::proxy_http_factory_ok_manual_clear() |
|
319 { |
|
320 QNetworkProxyQuery query = QNetworkProxyQuery(QUrl("http://maps.google.com/")); |
|
321 Maemo::ProxyConf::update(); |
|
322 |
|
323 put("mode", "string", "manual"); |
|
324 put_http("host", "string", "192.168.1.1"); |
|
325 |
|
326 QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::proxyForQuery(query); |
|
327 |
|
328 foreach (QNetworkProxy proxy, listOfProxies) { |
|
329 qDebug() << "proxy: " << proxy.hostName() << "port" << proxy.port(); |
|
330 } |
|
331 QVERIFY(listOfProxies.length()==3); |
|
332 QVERIFY(listOfProxies.first().type() == QNetworkProxy::HttpProxy); |
|
333 |
|
334 Maemo::ProxyConf::clear(); |
|
335 listOfProxies = QNetworkProxyFactory::proxyForQuery(query); |
|
336 QVERIFY(listOfProxies.length()==1); |
|
337 QVERIFY(listOfProxies.first().type() == QNetworkProxy::NoProxy); |
|
338 } |
|
339 |
|
340 |
|
341 void Ut_ProxyConf::proxy_default_factory_ok_manual() |
|
342 { |
|
343 QNetworkProxyQuery query = QNetworkProxyQuery(QUrl("foobar://maps.google.com/")); |
|
344 Maemo::ProxyConf::update(); |
|
345 |
|
346 put("mode", "string", "manual"); |
|
347 put("socks_host", "string", ""); |
|
348 put("secure_host", "string", ""); |
|
349 |
|
350 QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::proxyForQuery(query); |
|
351 |
|
352 QVERIFY(listOfProxies.length()==1); |
|
353 QVERIFY(listOfProxies.first().type() == QNetworkProxy::NoProxy); |
|
354 Maemo::ProxyConf::clear(); |
|
355 } |
|
356 |
|
357 |
|
358 void Ut_ProxyConf::proxy_http_factory_ok_manual_ignore_list() |
|
359 { |
|
360 QNetworkProxyQuery query = QNetworkProxyQuery(QUrl("http://192.168.19.70/")); |
|
361 Maemo::ProxyConf::update(); |
|
362 |
|
363 put("mode", "string", "manual"); |
|
364 |
|
365 QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::proxyForQuery(query); |
|
366 |
|
367 foreach (QNetworkProxy proxy, listOfProxies) { |
|
368 qDebug() << "proxy: " << proxy.hostName() << "port" << proxy.port(); |
|
369 } |
|
370 QVERIFY(listOfProxies.length()==3); |
|
371 QVERIFY(listOfProxies.first().type() == QNetworkProxy::HttpProxy); |
|
372 |
|
373 query = QNetworkProxyQuery(QUrl("http://192.168.20.10/")); |
|
374 listOfProxies = QNetworkProxyFactory::proxyForQuery(query); |
|
375 QVERIFY(listOfProxies.length()==1); |
|
376 QVERIFY(listOfProxies.first().type() == QNetworkProxy::NoProxy); |
|
377 Maemo::ProxyConf::clear(); |
|
378 } |
|
379 |
|
380 |
|
381 void Ut_ProxyConf::proxy_default_factory_ok_manual_system() |
|
382 { |
|
383 QNetworkProxyQuery query = QNetworkProxyQuery(QUrl("http://maps.google.com/")); |
|
384 Maemo::ProxyConf::update(); |
|
385 |
|
386 put("mode", "string", "manual"); |
|
387 |
|
388 QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::systemProxyForQuery(query); |
|
389 |
|
390 QVERIFY(listOfProxies.length()==1); |
|
391 QVERIFY(listOfProxies.first().type() == QNetworkProxy::NoProxy); |
|
392 Maemo::ProxyConf::clear(); |
|
393 } |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 QTEST_MAIN(Ut_ProxyConf) |
|
399 |
|
400 #include "ut_proxyconf.moc" |