Mercurial > hg
annotate tests/test-hgweb-auth.py @ 52182:bd8081e9fd62
rust: don't star export from the `revlog` module
This made a lot of the imports confusing because they didn't make sense
at the top level (so, outside of `revlog`), and they hide the more common
types when autocompleting.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 26 Sep 2024 14:26:24 +0200 |
parents | 6000f5b25c9b |
children |
rev | line source |
---|---|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
1 from mercurial import demandimport |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
2 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
3 demandimport.enable() |
28747
779addce6910
py3: use absolute_import in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
19378
diff
changeset
|
4 from mercurial import ( |
28808
10c2ce44c35d
test-hgweb-auth: stop direct symbol import of mercurial.error.Abort
Yuya Nishihara <yuya@tcha.org>
parents:
28807
diff
changeset
|
5 error, |
37940
31c37e703cee
tests: use stringutil.pprint instead of custom dumper in test-hgweb-auth.py
Augie Fackler <augie@google.com>
parents:
36327
diff
changeset
|
6 pycompat, |
28807
736f64b23a24
test-hgweb-auth: alias ui as uimod
Yuya Nishihara <yuya@tcha.org>
parents:
28748
diff
changeset
|
7 ui as uimod, |
28747
779addce6910
py3: use absolute_import in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
19378
diff
changeset
|
8 url, |
779addce6910
py3: use absolute_import in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
19378
diff
changeset
|
9 util, |
779addce6910
py3: use absolute_import in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
19378
diff
changeset
|
10 ) |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44452
diff
changeset
|
11 from mercurial.utils import ( |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44452
diff
changeset
|
12 stringutil, |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44452
diff
changeset
|
13 urlutil, |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44452
diff
changeset
|
14 ) |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
15 |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28808
diff
changeset
|
16 urlerr = util.urlerr |
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28808
diff
changeset
|
17 urlreq = util.urlreq |
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28808
diff
changeset
|
18 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
19 |
28807
736f64b23a24
test-hgweb-auth: alias ui as uimod
Yuya Nishihara <yuya@tcha.org>
parents:
28748
diff
changeset
|
20 class myui(uimod.ui): |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
21 def interactive(self): |
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
22 return False |
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
23 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
24 |
30559
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
29377
diff
changeset
|
25 origui = myui.load() |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
26 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
27 |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
28 def writeauth(items): |
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
29 ui = origui.copy() |
36327
58c1368ab629
py3: use dict.items() instead of dict.iteritems() in tests
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34023
diff
changeset
|
30 for name, value in items.items(): |
41451
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
31 ui.setconfig(b'auth', name, value) |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
32 return ui |
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
33 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
34 |
41451
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
35 def _stringifyauthinfo(ai): |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
36 if ai is None: |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
37 return ai |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
38 realm, authuris, user, passwd = ai |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
39 return ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
40 pycompat.strurl(realm), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
41 [pycompat.strurl(u) for u in authuris], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
42 pycompat.strurl(user), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
43 pycompat.strurl(passwd), |
41451
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
44 ) |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
45 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
46 |
15005
4a43e23b8c55
hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
47 def test(auth, urls=None): |
37942
32bc3815efae
stringutil: flip the default of pprint() to bprefix=False
Yuya Nishihara <yuya@tcha.org>
parents:
37940
diff
changeset
|
48 print('CFG:', pycompat.sysstr(stringutil.pprint(auth, bprefix=True))) |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
49 prefixes = set() |
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
50 for k in auth: |
41451
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
51 prefixes.add(k.split(b'.', 1)[0]) |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
52 for p in prefixes: |
41451
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
53 for name in (b'.username', b'.password'): |
15005
4a43e23b8c55
hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
54 if (p + name) not in auth: |
4a43e23b8c55
hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
55 auth[p + name] = p |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
56 auth = {k: v for k, v in auth.items() if v is not None} |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
57 |
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
58 ui = writeauth(auth) |
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
59 |
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
60 def _test(uri): |
41451
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
61 print('URI:', pycompat.strurl(uri)) |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
62 try: |
29377
2c019aac6b99
url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents:
28883
diff
changeset
|
63 pm = url.passwordmgr(ui, urlreq.httppasswordmgrwithdefaultrealm()) |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44452
diff
changeset
|
64 u, authinfo = urlutil.url(uri).authinfo() |
15005
4a43e23b8c55
hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
65 if authinfo is not None: |
41451
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
66 pm.add_password(*_stringifyauthinfo(authinfo)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
67 print( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
68 ' ', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
69 tuple( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
70 pycompat.strurl(a) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
71 for a in pm.find_user_password('test', pycompat.strurl(u)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
72 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
73 ) |
28808
10c2ce44c35d
test-hgweb-auth: stop direct symbol import of mercurial.error.Abort
Yuya Nishihara <yuya@tcha.org>
parents:
28807
diff
changeset
|
74 except error.Abort: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
75 print(' ', 'abort') |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
76 |
15005
4a43e23b8c55
hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
77 if not urls: |
4a43e23b8c55
hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
78 urls = [ |
41451
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
79 b'http://example.org/foo', |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
80 b'http://example.org/foo/bar', |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
81 b'http://example.org/bar', |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
82 b'https://example.org/foo', |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
83 b'https://example.org/foo/bar', |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
84 b'https://example.org/bar', |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
85 b'https://x@example.org/bar', |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
86 b'https://y@example.org/bar', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
87 ] |
15005
4a43e23b8c55
hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
88 for u in urls: |
4a43e23b8c55
hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
89 _test(u) |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
90 |
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
91 |
28748
c2ba5a810fa1
py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28747
diff
changeset
|
92 print('\n*** Test in-uri schemes\n') |
41451
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
93 test({b'x.prefix': b'http://example.org'}) |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
94 test({b'x.prefix': b'https://example.org'}) |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
95 test({b'x.prefix': b'http://example.org', b'x.schemes': b'https'}) |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
96 test({b'x.prefix': b'https://example.org', b'x.schemes': b'http'}) |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
97 |
28748
c2ba5a810fa1
py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28747
diff
changeset
|
98 print('\n*** Test separately configured schemes\n') |
41451
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
99 test({b'x.prefix': b'example.org', b'x.schemes': b'http'}) |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
100 test({b'x.prefix': b'example.org', b'x.schemes': b'https'}) |
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
101 test({b'x.prefix': b'example.org', b'x.schemes': b'http https'}) |
8333
89c80c3dc584
allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff
changeset
|
102 |
28748
c2ba5a810fa1
py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28747
diff
changeset
|
103 print('\n*** Test prefix matching\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
104 test( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
105 { |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
106 b'x.prefix': b'http://example.org/foo', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
107 b'y.prefix': b'http://example.org/bar', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
108 } |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
109 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
110 test( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
111 { |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
112 b'x.prefix': b'http://example.org/foo', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
113 b'y.prefix': b'http://example.org/foo/bar', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
114 } |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
115 ) |
41451
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
116 test({b'x.prefix': b'*', b'y.prefix': b'https://example.org/bar'}) |
15005
4a43e23b8c55
hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents:
10282
diff
changeset
|
117 |
28748
c2ba5a810fa1
py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28747
diff
changeset
|
118 print('\n*** Test user matching\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
119 test( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
120 { |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
121 b'x.prefix': b'http://example.org/foo', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
122 b'x.username': None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
123 b'x.password': b'xpassword', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
124 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
125 urls=[b'http://y@example.org/foo'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
126 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
127 test( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
128 { |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
129 b'x.prefix': b'http://example.org/foo', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
130 b'x.username': None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
131 b'x.password': b'xpassword', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
132 b'y.prefix': b'http://example.org/foo', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
133 b'y.username': b'y', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
134 b'y.password': b'ypassword', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
135 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
136 urls=[b'http://y@example.org/foo'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
137 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
138 test( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
139 { |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
140 b'x.prefix': b'http://example.org/foo/bar', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
141 b'x.username': None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
142 b'x.password': b'xpassword', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
143 b'y.prefix': b'http://example.org/foo', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
144 b'y.username': b'y', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
145 b'y.password': b'ypassword', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
146 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
147 urls=[b'http://y@example.org/foo/bar'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
148 ) |
15024
0f1311e829c9
http: strip credentials from urllib2 manager URIs (issue2885)
Patrick Mezard <pmezard@gmail.com>
parents:
15005
diff
changeset
|
149 |
40663
c53f0ead5781
http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents:
37942
diff
changeset
|
150 print('\n*** Test user matching with name in prefix\n') |
c53f0ead5781
http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents:
37942
diff
changeset
|
151 |
c53f0ead5781
http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents:
37942
diff
changeset
|
152 # prefix, username and URL have the same user |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
153 test( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
154 { |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
155 b'x.prefix': b'https://example.org/foo', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
156 b'x.username': None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
157 b'x.password': b'xpassword', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
158 b'y.prefix': b'http://y@example.org/foo', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
159 b'y.username': b'y', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
160 b'y.password': b'ypassword', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
161 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
162 urls=[b'http://y@example.org/foo'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
163 ) |
40663
c53f0ead5781
http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents:
37942
diff
changeset
|
164 # Prefix has a different user from username and URL |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
165 test( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
166 { |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
167 b'y.prefix': b'http://z@example.org/foo', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
168 b'y.username': b'y', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
169 b'y.password': b'ypassword', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
170 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
171 urls=[b'http://y@example.org/foo'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
172 ) |
40663
c53f0ead5781
http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents:
37942
diff
changeset
|
173 # Prefix has a different user from URL; no username |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
174 test( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
175 {b'y.prefix': b'http://z@example.org/foo', b'y.password': b'ypassword'}, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
176 urls=[b'http://y@example.org/foo'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
177 ) |
40663
c53f0ead5781
http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents:
37942
diff
changeset
|
178 # Prefix and URL have same user, but doesn't match username |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
179 test( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
180 { |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
181 b'y.prefix': b'http://y@example.org/foo', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
182 b'y.username': b'z', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
183 b'y.password': b'ypassword', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
184 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
185 urls=[b'http://y@example.org/foo'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
186 ) |
40663
c53f0ead5781
http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents:
37942
diff
changeset
|
187 # Prefix and URL have the same user; no username |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
188 test( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
189 {b'y.prefix': b'http://y@example.org/foo', b'y.password': b'ypassword'}, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
190 urls=[b'http://y@example.org/foo'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
191 ) |
40663
c53f0ead5781
http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents:
37942
diff
changeset
|
192 # Prefix user, but no URL user or username |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
193 test( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
194 {b'y.prefix': b'http://y@example.org/foo', b'y.password': b'ypassword'}, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
195 urls=[b'http://example.org/foo'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
196 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
197 |
40663
c53f0ead5781
http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents:
37942
diff
changeset
|
198 |
15024
0f1311e829c9
http: strip credentials from urllib2 manager URIs (issue2885)
Patrick Mezard <pmezard@gmail.com>
parents:
15005
diff
changeset
|
199 def testauthinfo(fullurl, authurl): |
28748
c2ba5a810fa1
py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28747
diff
changeset
|
200 print('URIs:', fullurl, authurl) |
28883
032c4c2f802a
pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents:
28808
diff
changeset
|
201 pm = urlreq.httppasswordmgrwithdefaultrealm() |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44452
diff
changeset
|
202 ai = _stringifyauthinfo( |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44452
diff
changeset
|
203 urlutil.url(pycompat.bytesurl(fullurl)).authinfo()[1] |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44452
diff
changeset
|
204 ) |
41451
30dd20a56f3e
tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents:
40663
diff
changeset
|
205 pm.add_password(*ai) |
28748
c2ba5a810fa1
py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28747
diff
changeset
|
206 print(pm.find_user_password('test', authurl)) |
15024
0f1311e829c9
http: strip credentials from urllib2 manager URIs (issue2885)
Patrick Mezard <pmezard@gmail.com>
parents:
15005
diff
changeset
|
207 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41451
diff
changeset
|
208 |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44452
diff
changeset
|
209 print('\n*** Test urllib2 and urlutil.url\n') |
15024
0f1311e829c9
http: strip credentials from urllib2 manager URIs (issue2885)
Patrick Mezard <pmezard@gmail.com>
parents:
15005
diff
changeset
|
210 testauthinfo('http://user@example.com:8080/foo', 'http://example.com:8080/foo') |