~rodrigo-moya/system-service/new-interfaces

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
#!/usr/bin/python

import sys
sys.path.insert(0, "../")

import unittest

from UbuntuSystemService.utils import verify_proxy

class TestVerifyProxy(unittest.TestCase):

    test_cases = { "http://hh-1h.bla.com:8080/test/test.jsp?d=dd&id=dki" : False,
                   "http://foo:3128" : True,
                   "http://foo:3128/" : True,
                   "http://foo.bar-z.com:3128/" : True,
                   "http://foo.bar.com/port-not-after-host:3" : False,
                   "http://foo:" : False,
                   "does-not-start-with-proto" : False,
                   "http://bad-host-chars?:3128/" : False,
                   "http://host:2182/invalid-chars-in-str\\" : False,
                   "http:no-forward-slashes:3128" :False,
                 }

    def test_verify(self):
        for (str, result) in self.test_cases.iteritems():
            self.assertEqual(verify_proxy("http", str), result,
                             "%s expected %s" % (str, result))


if __name__ == "__main__":
    unittest.main()