17 |
17 |
18 def dumpdict(dict): |
18 def dumpdict(dict): |
19 return '{' + ', '.join(['%s: %s' % (k, dict[k]) |
19 return '{' + ', '.join(['%s: %s' % (k, dict[k]) |
20 for k in sorted(dict.iterkeys())]) + '}' |
20 for k in sorted(dict.iterkeys())]) + '}' |
21 |
21 |
22 def test(auth): |
22 def test(auth, urls=None): |
23 print 'CFG:', dumpdict(auth) |
23 print 'CFG:', dumpdict(auth) |
24 prefixes = set() |
24 prefixes = set() |
25 for k in auth: |
25 for k in auth: |
26 prefixes.add(k.split('.', 1)[0]) |
26 prefixes.add(k.split('.', 1)[0]) |
27 for p in prefixes: |
27 for p in prefixes: |
28 auth.update({p + '.username': p, p + '.password': p}) |
28 for name in ('.username', '.password'): |
|
29 if (p + name) not in auth: |
|
30 auth[p + name] = p |
|
31 auth = dict((k, v) for k, v in auth.iteritems() if v is not None) |
29 |
32 |
30 ui = writeauth(auth) |
33 ui = writeauth(auth) |
31 |
34 |
32 def _test(uri): |
35 def _test(uri): |
33 print 'URI:', uri |
36 print 'URI:', uri |
34 try: |
37 try: |
35 pm = url.passwordmgr(ui) |
38 pm = url.passwordmgr(ui) |
|
39 authinfo = util.url(uri).authinfo()[1] |
|
40 if authinfo is not None: |
|
41 pm.add_password(*authinfo) |
36 print ' ', pm.find_user_password('test', uri) |
42 print ' ', pm.find_user_password('test', uri) |
37 except Abort, e: |
43 except Abort, e: |
38 print 'abort' |
44 print 'abort' |
39 |
45 |
40 _test('http://example.org/foo') |
46 if not urls: |
41 _test('http://example.org/foo/bar') |
47 urls = [ |
42 _test('http://example.org/bar') |
48 'http://example.org/foo', |
43 _test('https://example.org/foo') |
49 'http://example.org/foo/bar', |
44 _test('https://example.org/foo/bar') |
50 'http://example.org/bar', |
45 _test('https://example.org/bar') |
51 'https://example.org/foo', |
|
52 'https://example.org/foo/bar', |
|
53 'https://example.org/bar', |
|
54 'https://x@example.org/bar', |
|
55 'https://y@example.org/bar', |
|
56 ] |
|
57 for u in urls: |
|
58 _test(u) |
46 |
59 |
47 |
60 |
48 print '\n*** Test in-uri schemes\n' |
61 print '\n*** Test in-uri schemes\n' |
49 test({'x.prefix': 'http://example.org'}) |
62 test({'x.prefix': 'http://example.org'}) |
50 test({'x.prefix': 'https://example.org'}) |
63 test({'x.prefix': 'https://example.org'}) |
60 test({'x.prefix': 'http://example.org/foo', |
73 test({'x.prefix': 'http://example.org/foo', |
61 'y.prefix': 'http://example.org/bar'}) |
74 'y.prefix': 'http://example.org/bar'}) |
62 test({'x.prefix': 'http://example.org/foo', |
75 test({'x.prefix': 'http://example.org/foo', |
63 'y.prefix': 'http://example.org/foo/bar'}) |
76 'y.prefix': 'http://example.org/foo/bar'}) |
64 test({'x.prefix': '*', 'y.prefix': 'https://example.org/bar'}) |
77 test({'x.prefix': '*', 'y.prefix': 'https://example.org/bar'}) |
|
78 |
|
79 print '\n*** Test user matching\n' |
|
80 test({'x.prefix': 'http://example.org/foo', |
|
81 'x.username': None, |
|
82 'x.password': 'xpassword'}, |
|
83 urls=['http://y@example.org/foo']) |
|
84 test({'x.prefix': 'http://example.org/foo', |
|
85 'x.username': None, |
|
86 'x.password': 'xpassword', |
|
87 'y.prefix': 'http://example.org/foo', |
|
88 'y.username': 'y', |
|
89 'y.password': 'ypassword'}, |
|
90 urls=['http://y@example.org/foo']) |
|
91 test({'x.prefix': 'http://example.org/foo/bar', |
|
92 'x.username': None, |
|
93 'x.password': 'xpassword', |
|
94 'y.prefix': 'http://example.org/foo', |
|
95 'y.username': 'y', |
|
96 'y.password': 'ypassword'}, |
|
97 urls=['http://y@example.org/foo/bar']) |