tests/test-hgweb-auth.py
author Gregory Szorc <gregory.szorc@gmail.com>
Sat, 19 Feb 2022 18:42:12 -0700
changeset 48938 4561ec90d3c1
parent 46907 ffd3e823a7e5
child 48966 6000f5b25c9b
permissions -rw-r--r--
automation: delete code related to Python 2.7 support The building of Inno and WiX installers took a python_version argument that allowed us to specify "2" or "3" for the major Python version. Since we no longer support Python 2, we can delete this argument and everything feeding into it. Differential Revision: https://phab.mercurial-scm.org/D12264
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
     1
from __future__ import absolute_import, print_function
28747
779addce6910 py3: use absolute_import in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 19378
diff changeset
     2
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
     3
from mercurial import demandimport
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
     4
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
     5
demandimport.enable()
28747
779addce6910 py3: use absolute_import in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 19378
diff changeset
     6
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
     7
    error,
37984
31c37e703cee tests: use stringutil.pprint instead of custom dumper in test-hgweb-auth.py
Augie Fackler <augie@google.com>
parents: 36360
diff changeset
     8
    pycompat,
28807
736f64b23a24 test-hgweb-auth: alias ui as uimod
Yuya Nishihara <yuya@tcha.org>
parents: 28748
diff changeset
     9
    ui as uimod,
28747
779addce6910 py3: use absolute_import in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 19378
diff changeset
    10
    url,
779addce6910 py3: use absolute_import in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 19378
diff changeset
    11
    util,
779addce6910 py3: use absolute_import in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 19378
diff changeset
    12
)
46907
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44470
diff changeset
    13
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: 44470
diff changeset
    14
    stringutil,
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44470
diff changeset
    15
    urlutil,
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44470
diff changeset
    16
)
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    17
28883
032c4c2f802a pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents: 28808
diff changeset
    18
urlerr = util.urlerr
032c4c2f802a pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents: 28808
diff changeset
    19
urlreq = util.urlreq
032c4c2f802a pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents: 28808
diff changeset
    20
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    21
28807
736f64b23a24 test-hgweb-auth: alias ui as uimod
Yuya Nishihara <yuya@tcha.org>
parents: 28748
diff changeset
    22
class myui(uimod.ui):
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    23
    def interactive(self):
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    24
        return False
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    25
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    26
30564
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 29377
diff changeset
    27
origui = myui.load()
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    28
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    29
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    30
def writeauth(items):
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    31
    ui = origui.copy()
36360
58c1368ab629 py3: use dict.items() instead of dict.iteritems() in tests
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34041
diff changeset
    32
    for name, value in items.items():
41471
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    33
        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
    34
    return ui
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    35
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    36
41471
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    37
def _stringifyauthinfo(ai):
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    38
    if ai is None:
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    39
        return ai
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    40
    realm, authuris, user, passwd = ai
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    41
    return (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    42
        pycompat.strurl(realm),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    43
        [pycompat.strurl(u) for u in authuris],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    44
        pycompat.strurl(user),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    45
        pycompat.strurl(passwd),
41471
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    46
    )
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    47
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    48
15005
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    49
def test(auth, urls=None):
37986
32bc3815efae stringutil: flip the default of pprint() to bprefix=False
Yuya Nishihara <yuya@tcha.org>
parents: 37984
diff changeset
    50
    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
    51
    prefixes = set()
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    52
    for k in auth:
41471
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    53
        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
    54
    for p in prefixes:
41471
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    55
        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
    56
            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
    57
                auth[p + name] = p
44470
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    58
    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
    59
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    60
    ui = writeauth(auth)
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    61
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    62
    def _test(uri):
41471
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    63
        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
    64
        try:
29377
2c019aac6b99 url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents: 28883
diff changeset
    65
            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: 44470
diff changeset
    66
            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
    67
            if authinfo is not None:
41471
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    68
                pm.add_password(*_stringifyauthinfo(authinfo))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    69
            print(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    70
                '    ',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    71
                tuple(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    72
                    pycompat.strurl(a)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    73
                    for a in pm.find_user_password('test', pycompat.strurl(u))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    74
                ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    75
            )
28808
10c2ce44c35d test-hgweb-auth: stop direct symbol import of mercurial.error.Abort
Yuya Nishihara <yuya@tcha.org>
parents: 28807
diff changeset
    76
        except error.Abort:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    77
            print('    ', 'abort')
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    78
15005
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    79
    if not urls:
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    80
        urls = [
41471
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    81
            b'http://example.org/foo',
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    82
            b'http://example.org/foo/bar',
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    83
            b'http://example.org/bar',
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    84
            b'https://example.org/foo',
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    85
            b'https://example.org/foo/bar',
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    86
            b'https://example.org/bar',
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    87
            b'https://x@example.org/bar',
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    88
            b'https://y@example.org/bar',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
    89
        ]
15005
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    90
    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
    91
        _test(u)
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    92
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    93
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
    94
print('\n*** Test in-uri schemes\n')
41471
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    95
test({b'x.prefix': b'http://example.org'})
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    96
test({b'x.prefix': b'https://example.org'})
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
    97
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: 40704
diff changeset
    98
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
    99
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
   100
print('\n*** Test separately configured schemes\n')
41471
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
   101
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: 40704
diff changeset
   102
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: 40704
diff changeset
   103
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
   104
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
   105
print('\n*** Test prefix matching\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   106
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   107
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   108
        b'x.prefix': b'http://example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   109
        b'y.prefix': b'http://example.org/bar',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   110
    }
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   111
)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   112
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   113
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   114
        b'x.prefix': b'http://example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   115
        b'y.prefix': b'http://example.org/foo/bar',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   116
    }
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   117
)
41471
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
   118
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
   119
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
   120
print('\n*** Test user matching\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   121
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   122
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   123
        b'x.prefix': b'http://example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   124
        b'x.username': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   125
        b'x.password': b'xpassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   126
    },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   127
    urls=[b'http://y@example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   128
)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   129
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   130
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   131
        b'x.prefix': b'http://example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   132
        b'x.username': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   133
        b'x.password': b'xpassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   134
        b'y.prefix': b'http://example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   135
        b'y.username': b'y',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   136
        b'y.password': b'ypassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   137
    },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   138
    urls=[b'http://y@example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   139
)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   140
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   141
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   142
        b'x.prefix': b'http://example.org/foo/bar',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   143
        b'x.username': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   144
        b'x.password': b'xpassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   145
        b'y.prefix': b'http://example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   146
        b'y.username': b'y',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   147
        b'y.password': b'ypassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   148
    },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   149
    urls=[b'http://y@example.org/foo/bar'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   150
)
15024
0f1311e829c9 http: strip credentials from urllib2 manager URIs (issue2885)
Patrick Mezard <pmezard@gmail.com>
parents: 15005
diff changeset
   151
40704
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37986
diff changeset
   152
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: 37986
diff changeset
   153
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37986
diff changeset
   154
# prefix, username and URL have the same user
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   155
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   156
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   157
        b'x.prefix': b'https://example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   158
        b'x.username': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   159
        b'x.password': b'xpassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   160
        b'y.prefix': b'http://y@example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   161
        b'y.username': b'y',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   162
        b'y.password': b'ypassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   163
    },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   164
    urls=[b'http://y@example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   165
)
40704
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37986
diff changeset
   166
# Prefix has a different user from username and URL
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   167
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   168
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   169
        b'y.prefix': b'http://z@example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   170
        b'y.username': b'y',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   171
        b'y.password': b'ypassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   172
    },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   173
    urls=[b'http://y@example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   174
)
40704
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37986
diff changeset
   175
# Prefix has a different user from URL; no username
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   176
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   177
    {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: 41471
diff changeset
   178
    urls=[b'http://y@example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   179
)
40704
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37986
diff changeset
   180
# Prefix and URL have same user, but doesn't match username
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   181
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   182
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   183
        b'y.prefix': b'http://y@example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   184
        b'y.username': b'z',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   185
        b'y.password': b'ypassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   186
    },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   187
    urls=[b'http://y@example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   188
)
40704
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37986
diff changeset
   189
# Prefix and URL have the same user; no username
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   190
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   191
    {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: 41471
diff changeset
   192
    urls=[b'http://y@example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   193
)
40704
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37986
diff changeset
   194
# Prefix user, but no URL user or username
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   195
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   196
    {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: 41471
diff changeset
   197
    urls=[b'http://example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   198
)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   199
40704
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37986
diff changeset
   200
15024
0f1311e829c9 http: strip credentials from urllib2 manager URIs (issue2885)
Patrick Mezard <pmezard@gmail.com>
parents: 15005
diff changeset
   201
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
   202
    print('URIs:', fullurl, authurl)
28883
032c4c2f802a pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents: 28808
diff changeset
   203
    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: 44470
diff changeset
   204
    ai = _stringifyauthinfo(
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44470
diff changeset
   205
        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: 44470
diff changeset
   206
    )
41471
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40704
diff changeset
   207
    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
   208
    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
   209
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41471
diff changeset
   210
46907
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 44470
diff changeset
   211
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
   212
testauthinfo('http://user@example.com:8080/foo', 'http://example.com:8080/foo')