diff -r d06b9c55ddab -r 4a43e23b8c55 tests/test-hgweb-auth.py --- a/tests/test-hgweb-auth.py Sun Jul 31 01:46:52 2011 +0200 +++ b/tests/test-hgweb-auth.py Mon Aug 01 23:58:50 2011 +0200 @@ -1,5 +1,5 @@ from mercurial import demandimport; demandimport.enable() -from mercurial import ui +from mercurial import ui, util from mercurial import url from mercurial.error import Abort @@ -19,13 +19,16 @@ return '{' + ', '.join(['%s: %s' % (k, dict[k]) for k in sorted(dict.iterkeys())]) + '}' -def test(auth): +def test(auth, urls=None): print 'CFG:', dumpdict(auth) prefixes = set() for k in auth: prefixes.add(k.split('.', 1)[0]) for p in prefixes: - auth.update({p + '.username': p, p + '.password': p}) + for name in ('.username', '.password'): + if (p + name) not in auth: + auth[p + name] = p + auth = dict((k, v) for k, v in auth.iteritems() if v is not None) ui = writeauth(auth) @@ -33,16 +36,26 @@ print 'URI:', uri try: pm = url.passwordmgr(ui) + authinfo = util.url(uri).authinfo()[1] + if authinfo is not None: + pm.add_password(*authinfo) print ' ', pm.find_user_password('test', uri) except Abort, e: print 'abort' - _test('http://example.org/foo') - _test('http://example.org/foo/bar') - _test('http://example.org/bar') - _test('https://example.org/foo') - _test('https://example.org/foo/bar') - _test('https://example.org/bar') + if not urls: + urls = [ + 'http://example.org/foo', + 'http://example.org/foo/bar', + 'http://example.org/bar', + 'https://example.org/foo', + 'https://example.org/foo/bar', + 'https://example.org/bar', + 'https://x@example.org/bar', + 'https://y@example.org/bar', + ] + for u in urls: + _test(u) print '\n*** Test in-uri schemes\n' @@ -62,3 +75,23 @@ test({'x.prefix': 'http://example.org/foo', 'y.prefix': 'http://example.org/foo/bar'}) test({'x.prefix': '*', 'y.prefix': 'https://example.org/bar'}) + +print '\n*** Test user matching\n' +test({'x.prefix': 'http://example.org/foo', + 'x.username': None, + 'x.password': 'xpassword'}, + urls=['http://y@example.org/foo']) +test({'x.prefix': 'http://example.org/foo', + 'x.username': None, + 'x.password': 'xpassword', + 'y.prefix': 'http://example.org/foo', + 'y.username': 'y', + 'y.password': 'ypassword'}, + urls=['http://y@example.org/foo']) +test({'x.prefix': 'http://example.org/foo/bar', + 'x.username': None, + 'x.password': 'xpassword', + 'y.prefix': 'http://example.org/foo', + 'y.username': 'y', + 'y.password': 'ypassword'}, + urls=['http://y@example.org/foo/bar'])