Check for proper operation of the proxy regex. The regex neeeds to be copied over from yuminstall.py if it changes. Related: rhbz#602712 --- tests/regex/Makefile.am | 22 +++++++++ tests/regex/proxy.py | 111 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 0 deletions(-) create mode 100644 tests/regex/Makefile.am create mode 100644 tests/regex/__init__.py create mode 100644 tests/regex/proxy.py diff --git a/tests/regex/Makefile.am b/tests/regex/Makefile.am new file mode 100644 index 0000000..e0803af --- /dev/null +++ b/tests/regex/Makefile.am @@ -0,0 +1,22 @@ +# tests/regex/Makefile.am for anaconda +# +# Copyright (C) 2009 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# Author: Brian C. Lane <bcl@xxxxxxxxxx> + +EXTRA_DIST = *.py + +MAINTAINERCLEANFILES = Makefile.in diff --git a/tests/regex/__init__.py b/tests/regex/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regex/proxy.py b/tests/regex/proxy.py new file mode 100644 index 0000000..767330d --- /dev/null +++ b/tests/regex/proxy.py @@ -0,0 +1,111 @@ +import unittest +import re +import traceback + + +class ProxyRegexTestCase(unittest.TestCase): + def testProxy(self): + """ + Run a list of possible proxy= values through the regex and check for + correct results. + + tests are in the form of: (proxy string, match.groups() tuple) + """ + tests = [ ( "proxy.host", + (None, None, None, None, 'proxy.host', None, None) ), + + ( "proxy.host:3128", + (None, None, None, None, 'proxy.host', ':3128', None) ), + + ( "user:password@xxxxxxxxxx", + (None, 'user:password@', 'user', ':password', 'proxy.host', None, None) ), + + ( "user@xxxxxxxxxx", + (None, 'user@', 'user', None, 'proxy.host', None, None) ), + + ( "user:password@xxxxxxxxxx:3128", + (None, 'user:password@', 'user', ':password', 'proxy.host', ':3128', None) ), + + ( "user@xxxxxxxxxx:3128", + (None, 'user@', 'user', None, 'proxy.host', ':3128', None) ), + + ( "proxy.host/blah/blah", + (None, None, None, None, 'proxy.host', None, '/blah/blah') ), + + ( "proxy.host:3128/blah/blah", + (None, None, None, None, 'proxy.host', ':3128', '/blah/blah') ), + + ( "user:password@xxxxxxxxxx/blah/blah", + (None, 'user:password@', 'user', ':password', 'proxy.host', None, '/blah/blah') ), + + ( "user@xxxxxxxxxx/blah/blah", + (None, 'user@', 'user', None, 'proxy.host', None, '/blah/blah') ), + + ( "user:password@xxxxxxxxxx:3128/blah/blah", + (None, 'user:password@', 'user', ':password', 'proxy.host', ':3128', "/blah/blah") ), + + ( "user@xxxxxxxxxx:3128/blah/blah", + (None, 'user@', 'user', None, 'proxy.host', ':3128', "/blah/blah") ), + + + + ( "http://proxy.host", + ('http://', None, None, None, 'proxy.host', None, None) ), + + ( "http://proxy.host:3128", + ('http://', None, None, None, 'proxy.host', ':3128', None) ), + + ( "http://user:password@xxxxxxxxxx", + ('http://', 'user:password@', 'user', ':password', 'proxy.host', None, None) ), + + ( "http://user@xxxxxxxxxx", + ('http://', 'user@', 'user', None, 'proxy.host', None, None) ), + + ( "http://user:password@xxxxxxxxxx:3128", + ('http://', 'user:password@', 'user', ':password', 'proxy.host', ':3128', None) ), + + ( "http://user@xxxxxxxxxx:3128", + ('http://', 'user@', 'user', None, 'proxy.host', ':3128', None) ), + + ( "http://proxy.host/blah/blah", + ('http://', None, None, None, 'proxy.host', None, '/blah/blah') ), + + ( "http://proxy.host:3128/blah/blah", + ('http://', None, None, None, 'proxy.host', ':3128', '/blah/blah') ), + + ( "http://user:password@xxxxxxxxxx/blah/blah", + ("http://", 'user:password@', 'user', ':password', 'proxy.host', None, '/blah/blah') ), + + ( "http://user@xxxxxxxxxx/blah/blah", + ("http://", 'user@', 'user', None, 'proxy.host', None, '/blah/blah') ), + + ( "http://user:password@xxxxxxxxxx:3128/blah/blah", + ("http://", 'user:password@', 'user', ':password', 'proxy.host', ':3128', '/blah/blah') ), + + ( "http://user@xxxxxxxxxx:3128/blah/blah", + ("http://", 'user@', 'user', None, 'proxy.host', ':3128', '/blah/blah') ), + + ] + + + # This is from yumupdate.py and needs to be updated when it changes + pattern = re.compile("([A-Za-z]+://)?(([A-Za-z0-9]+)(:[^:@]+)?@)?([^:/]+)(:[0-9]+)?(/.*)?") + + got_error = False + for proxy, result in tests: + try: + self.assertEqual(pattern.match(proxy).groups(), result) + except AssertionError as error: + got_error = True + print error + + if got_error: + self.fail() + +def suite(): + return unittest.TestLoader().loadTestsFromTestCase(ProxyRegexTestCase) + + +if __name__ == "__main__": + unittest.main() + -- 1.7.0.1 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list