Show More
@@ -261,6 +261,7 b' test-hgignore.t' | |||
|
261 | 261 | test-hgk.t |
|
262 | 262 | test-hgrc.t |
|
263 | 263 | test-hgweb-annotate-whitespace.t |
|
264 | test-hgweb-auth.py | |
|
264 | 265 | test-hgweb-bundle.t |
|
265 | 266 | test-hgweb-commands.t |
|
266 | 267 | test-hgweb-csp.t |
@@ -24,16 +24,26 b' origui = myui.load()' | |||
|
24 | 24 | def writeauth(items): |
|
25 | 25 | ui = origui.copy() |
|
26 | 26 | for name, value in items.items(): |
|
27 | ui.setconfig('auth', name, value) | |
|
27 | ui.setconfig(b'auth', name, value) | |
|
28 | 28 | return ui |
|
29 | 29 | |
|
30 | def _stringifyauthinfo(ai): | |
|
31 | if ai is None: | |
|
32 | return ai | |
|
33 | realm, authuris, user, passwd = ai | |
|
34 | return (pycompat.strurl(realm), | |
|
35 | [pycompat.strurl(u) for u in authuris], | |
|
36 | pycompat.strurl(user), | |
|
37 | pycompat.strurl(passwd), | |
|
38 | ) | |
|
39 | ||
|
30 | 40 | def test(auth, urls=None): |
|
31 | 41 | print('CFG:', pycompat.sysstr(stringutil.pprint(auth, bprefix=True))) |
|
32 | 42 | prefixes = set() |
|
33 | 43 | for k in auth: |
|
34 | prefixes.add(k.split('.', 1)[0]) | |
|
44 | prefixes.add(k.split(b'.', 1)[0]) | |
|
35 | 45 | for p in prefixes: |
|
36 | for name in ('.username', '.password'): | |
|
46 | for name in (b'.username', b'.password'): | |
|
37 | 47 | if (p + name) not in auth: |
|
38 | 48 | auth[p + name] = p |
|
39 | 49 | auth = dict((k, v) for k, v in auth.items() if v is not None) |
@@ -41,106 +51,109 b' def test(auth, urls=None):' | |||
|
41 | 51 | ui = writeauth(auth) |
|
42 | 52 | |
|
43 | 53 | def _test(uri): |
|
44 | print('URI:', uri) | |
|
54 | print('URI:', pycompat.strurl(uri)) | |
|
45 | 55 | try: |
|
46 | 56 | pm = url.passwordmgr(ui, urlreq.httppasswordmgrwithdefaultrealm()) |
|
47 | 57 | u, authinfo = util.url(uri).authinfo() |
|
48 | 58 | if authinfo is not None: |
|
49 | pm.add_password(*authinfo) | |
|
50 | print(' ', pm.find_user_password('test', u)) | |
|
59 | pm.add_password(*_stringifyauthinfo(authinfo)) | |
|
60 | print(' ', tuple(pycompat.strurl(a) for a in | |
|
61 | pm.find_user_password('test', | |
|
62 | pycompat.strurl(u)))) | |
|
51 | 63 | except error.Abort: |
|
52 | 64 | print(' ','abort') |
|
53 | 65 | |
|
54 | 66 | if not urls: |
|
55 | 67 | urls = [ |
|
56 | 'http://example.org/foo', | |
|
57 | 'http://example.org/foo/bar', | |
|
58 | 'http://example.org/bar', | |
|
59 | 'https://example.org/foo', | |
|
60 | 'https://example.org/foo/bar', | |
|
61 | 'https://example.org/bar', | |
|
62 | 'https://x@example.org/bar', | |
|
63 | 'https://y@example.org/bar', | |
|
68 | b'http://example.org/foo', | |
|
69 | b'http://example.org/foo/bar', | |
|
70 | b'http://example.org/bar', | |
|
71 | b'https://example.org/foo', | |
|
72 | b'https://example.org/foo/bar', | |
|
73 | b'https://example.org/bar', | |
|
74 | b'https://x@example.org/bar', | |
|
75 | b'https://y@example.org/bar', | |
|
64 | 76 | ] |
|
65 | 77 | for u in urls: |
|
66 | 78 | _test(u) |
|
67 | 79 | |
|
68 | 80 | |
|
69 | 81 | print('\n*** Test in-uri schemes\n') |
|
70 | test({'x.prefix': 'http://example.org'}) | |
|
71 | test({'x.prefix': 'https://example.org'}) | |
|
72 | test({'x.prefix': 'http://example.org', 'x.schemes': 'https'}) | |
|
73 | test({'x.prefix': 'https://example.org', 'x.schemes': 'http'}) | |
|
82 | test({b'x.prefix': b'http://example.org'}) | |
|
83 | test({b'x.prefix': b'https://example.org'}) | |
|
84 | test({b'x.prefix': b'http://example.org', b'x.schemes': b'https'}) | |
|
85 | test({b'x.prefix': b'https://example.org', b'x.schemes': b'http'}) | |
|
74 | 86 | |
|
75 | 87 | print('\n*** Test separately configured schemes\n') |
|
76 | test({'x.prefix': 'example.org', 'x.schemes': 'http'}) | |
|
77 | test({'x.prefix': 'example.org', 'x.schemes': 'https'}) | |
|
78 | test({'x.prefix': 'example.org', 'x.schemes': 'http https'}) | |
|
88 | test({b'x.prefix': b'example.org', b'x.schemes': b'http'}) | |
|
89 | test({b'x.prefix': b'example.org', b'x.schemes': b'https'}) | |
|
90 | test({b'x.prefix': b'example.org', b'x.schemes': b'http https'}) | |
|
79 | 91 | |
|
80 | 92 | print('\n*** Test prefix matching\n') |
|
81 | test({'x.prefix': 'http://example.org/foo', | |
|
82 | 'y.prefix': 'http://example.org/bar'}) | |
|
83 | test({'x.prefix': 'http://example.org/foo', | |
|
84 | 'y.prefix': 'http://example.org/foo/bar'}) | |
|
85 | test({'x.prefix': '*', 'y.prefix': 'https://example.org/bar'}) | |
|
93 | test({b'x.prefix': b'http://example.org/foo', | |
|
94 | b'y.prefix': b'http://example.org/bar'}) | |
|
95 | test({b'x.prefix': b'http://example.org/foo', | |
|
96 | b'y.prefix': b'http://example.org/foo/bar'}) | |
|
97 | test({b'x.prefix': b'*', b'y.prefix': b'https://example.org/bar'}) | |
|
86 | 98 | |
|
87 | 99 | print('\n*** Test user matching\n') |
|
88 | test({'x.prefix': 'http://example.org/foo', | |
|
89 | 'x.username': None, | |
|
90 | 'x.password': 'xpassword'}, | |
|
91 | urls=['http://y@example.org/foo']) | |
|
92 | test({'x.prefix': 'http://example.org/foo', | |
|
93 | 'x.username': None, | |
|
94 | 'x.password': 'xpassword', | |
|
95 | 'y.prefix': 'http://example.org/foo', | |
|
96 | 'y.username': 'y', | |
|
97 | 'y.password': 'ypassword'}, | |
|
98 | urls=['http://y@example.org/foo']) | |
|
99 | test({'x.prefix': 'http://example.org/foo/bar', | |
|
100 | 'x.username': None, | |
|
101 | 'x.password': 'xpassword', | |
|
102 | 'y.prefix': 'http://example.org/foo', | |
|
103 | 'y.username': 'y', | |
|
104 | 'y.password': 'ypassword'}, | |
|
105 | urls=['http://y@example.org/foo/bar']) | |
|
100 | test({b'x.prefix': b'http://example.org/foo', | |
|
101 | b'x.username': None, | |
|
102 | b'x.password': b'xpassword'}, | |
|
103 | urls=[b'http://y@example.org/foo']) | |
|
104 | test({b'x.prefix': b'http://example.org/foo', | |
|
105 | b'x.username': None, | |
|
106 | b'x.password': b'xpassword', | |
|
107 | b'y.prefix': b'http://example.org/foo', | |
|
108 | b'y.username': b'y', | |
|
109 | b'y.password': b'ypassword'}, | |
|
110 | urls=[b'http://y@example.org/foo']) | |
|
111 | test({b'x.prefix': b'http://example.org/foo/bar', | |
|
112 | b'x.username': None, | |
|
113 | b'x.password': b'xpassword', | |
|
114 | b'y.prefix': b'http://example.org/foo', | |
|
115 | b'y.username': b'y', | |
|
116 | b'y.password': b'ypassword'}, | |
|
117 | urls=[b'http://y@example.org/foo/bar']) | |
|
106 | 118 | |
|
107 | 119 | print('\n*** Test user matching with name in prefix\n') |
|
108 | 120 | |
|
109 | 121 | # prefix, username and URL have the same user |
|
110 | test({'x.prefix': 'https://example.org/foo', | |
|
111 | 'x.username': None, | |
|
112 | 'x.password': 'xpassword', | |
|
113 | 'y.prefix': 'http://y@example.org/foo', | |
|
114 | 'y.username': 'y', | |
|
115 | 'y.password': 'ypassword'}, | |
|
116 | urls=['http://y@example.org/foo']) | |
|
122 | test({b'x.prefix': b'https://example.org/foo', | |
|
123 | b'x.username': None, | |
|
124 | b'x.password': b'xpassword', | |
|
125 | b'y.prefix': b'http://y@example.org/foo', | |
|
126 | b'y.username': b'y', | |
|
127 | b'y.password': b'ypassword'}, | |
|
128 | urls=[b'http://y@example.org/foo']) | |
|
117 | 129 | # Prefix has a different user from username and URL |
|
118 | test({'y.prefix': 'http://z@example.org/foo', | |
|
119 | 'y.username': 'y', | |
|
120 | 'y.password': 'ypassword'}, | |
|
121 | urls=['http://y@example.org/foo']) | |
|
130 | test({b'y.prefix': b'http://z@example.org/foo', | |
|
131 | b'y.username': b'y', | |
|
132 | b'y.password': b'ypassword'}, | |
|
133 | urls=[b'http://y@example.org/foo']) | |
|
122 | 134 | # Prefix has a different user from URL; no username |
|
123 | test({'y.prefix': 'http://z@example.org/foo', | |
|
124 | 'y.password': 'ypassword'}, | |
|
125 | urls=['http://y@example.org/foo']) | |
|
135 | test({b'y.prefix': b'http://z@example.org/foo', | |
|
136 | b'y.password': b'ypassword'}, | |
|
137 | urls=[b'http://y@example.org/foo']) | |
|
126 | 138 | # Prefix and URL have same user, but doesn't match username |
|
127 | test({'y.prefix': 'http://y@example.org/foo', | |
|
128 | 'y.username': 'z', | |
|
129 | 'y.password': 'ypassword'}, | |
|
130 | urls=['http://y@example.org/foo']) | |
|
139 | test({b'y.prefix': b'http://y@example.org/foo', | |
|
140 | b'y.username': b'z', | |
|
141 | b'y.password': b'ypassword'}, | |
|
142 | urls=[b'http://y@example.org/foo']) | |
|
131 | 143 | # Prefix and URL have the same user; no username |
|
132 | test({'y.prefix': 'http://y@example.org/foo', | |
|
133 | 'y.password': 'ypassword'}, | |
|
134 | urls=['http://y@example.org/foo']) | |
|
144 | test({b'y.prefix': b'http://y@example.org/foo', | |
|
145 | b'y.password': b'ypassword'}, | |
|
146 | urls=[b'http://y@example.org/foo']) | |
|
135 | 147 | # Prefix user, but no URL user or username |
|
136 | test({'y.prefix': 'http://y@example.org/foo', | |
|
137 | 'y.password': 'ypassword'}, | |
|
138 | urls=['http://example.org/foo']) | |
|
148 | test({b'y.prefix': b'http://y@example.org/foo', | |
|
149 | b'y.password': b'ypassword'}, | |
|
150 | urls=[b'http://example.org/foo']) | |
|
139 | 151 | |
|
140 | 152 | def testauthinfo(fullurl, authurl): |
|
141 | 153 | print('URIs:', fullurl, authurl) |
|
142 | 154 | pm = urlreq.httppasswordmgrwithdefaultrealm() |
|
143 |
|
|
|
155 | ai = _stringifyauthinfo(util.url(pycompat.bytesurl(fullurl)).authinfo()[1]) | |
|
156 | pm.add_password(*ai) | |
|
144 | 157 | print(pm.find_user_password('test', authurl)) |
|
145 | 158 | |
|
146 | 159 | print('\n*** Test urllib2 and util.url\n') |
General Comments 0
You need to be logged in to leave comments.
Login now