tests/test-hgweb-auth.py
author Manuel Jacob <me@manueljacob.de>
Tue, 07 Jul 2020 11:06:37 +0200
changeset 45068 8cd18aba5e6c
parent 44452 9d2b2df2c2ba
child 46907 ffd3e823a7e5
permissions -rw-r--r--
tests: proof test-stdio.py against buffer fill-up With the previous code, it could in theory happen that the pipe / PTY buffer of the child stdout / stderr fills up and the process never finishes. To prevent that, we read all of the stream before waiting for the end of the process. To ensure that the stream reaches EOF when the child finishes, we must close the parent "copy" of the child stdout / stderr.
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: 41451
diff changeset
     3
from mercurial import demandimport
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
     4
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
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,
37940
31c37e703cee tests: use stringutil.pprint instead of custom dumper in test-hgweb-auth.py
Augie Fackler <augie@google.com>
parents: 36327
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
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    13
from mercurial.utils import stringutil
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    14
28883
032c4c2f802a pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents: 28808
diff changeset
    15
urlerr = util.urlerr
032c4c2f802a pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents: 28808
diff changeset
    16
urlreq = util.urlreq
032c4c2f802a pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents: 28808
diff changeset
    17
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    18
28807
736f64b23a24 test-hgweb-auth: alias ui as uimod
Yuya Nishihara <yuya@tcha.org>
parents: 28748
diff changeset
    19
class myui(uimod.ui):
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    20
    def interactive(self):
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    21
        return False
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    22
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    23
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 29377
diff changeset
    24
origui = myui.load()
8333
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: 41451
diff changeset
    26
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    27
def writeauth(items):
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    28
    ui = origui.copy()
36327
58c1368ab629 py3: use dict.items() instead of dict.iteritems() in tests
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34023
diff changeset
    29
    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
    30
        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
    31
    return ui
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    32
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    33
41451
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
    34
def _stringifyauthinfo(ai):
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
    35
    if ai is None:
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
    36
        return ai
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
    37
    realm, authuris, user, passwd = ai
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    38
    return (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    39
        pycompat.strurl(realm),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    40
        [pycompat.strurl(u) for u in authuris],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    41
        pycompat.strurl(user),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    42
        pycompat.strurl(passwd),
41451
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
    43
    )
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
    44
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    45
15005
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    46
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
    47
    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
    48
    prefixes = set()
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    49
    for k in auth:
41451
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
    50
        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
    51
    for p in prefixes:
41451
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
    52
        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
    53
            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
    54
                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
    55
    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
    56
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    57
    ui = writeauth(auth)
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    58
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    59
    def _test(uri):
41451
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
    60
        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
    61
        try:
29377
2c019aac6b99 url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents: 28883
diff changeset
    62
            pm = url.passwordmgr(ui, urlreq.httppasswordmgrwithdefaultrealm())
15025
0593e8f81c71 http: pass user to readauthforuri() (fix 4a43e23b8c55)
Patrick Mezard <pmezard@gmail.com>
parents: 15024
diff changeset
    63
            u, authinfo = util.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
    64
            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
    65
                pm.add_password(*_stringifyauthinfo(authinfo))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    66
            print(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    67
                '    ',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    68
                tuple(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    69
                    pycompat.strurl(a)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    70
                    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
    71
                ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    72
            )
28808
10c2ce44c35d test-hgweb-auth: stop direct symbol import of mercurial.error.Abort
Yuya Nishihara <yuya@tcha.org>
parents: 28807
diff changeset
    73
        except error.Abort:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    74
            print('    ', 'abort')
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    75
15005
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    76
    if not urls:
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    77
        urls = [
41451
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
    78
            b'http://example.org/foo',
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/bar',
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
    80
            b'http://example.org/bar',
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
    81
            b'https://example.org/foo',
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/bar',
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
    83
            b'https://example.org/bar',
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
    84
            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
    85
            b'https://y@example.org/bar',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
    86
        ]
15005
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    87
    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
    88
        _test(u)
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    89
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    90
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
    91
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
    92
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
    93
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
    94
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
    95
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
    96
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
    97
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
    98
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
    99
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
   100
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
   101
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
   102
print('\n*** Test prefix matching\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   103
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   104
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   105
        b'x.prefix': b'http://example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   106
        b'y.prefix': b'http://example.org/bar',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   107
    }
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
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   110
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   111
        b'x.prefix': b'http://example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   112
        b'y.prefix': b'http://example.org/foo/bar',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   113
    }
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   114
)
41451
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
   115
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
   116
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
   117
print('\n*** Test user matching\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   118
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   119
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   120
        b'x.prefix': b'http://example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   121
        b'x.username': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   122
        b'x.password': b'xpassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   123
    },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   124
    urls=[b'http://y@example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   125
)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   126
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   127
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   128
        b'x.prefix': b'http://example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   129
        b'x.username': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   130
        b'x.password': b'xpassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   131
        b'y.prefix': b'http://example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   132
        b'y.username': b'y',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   133
        b'y.password': b'ypassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   134
    },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   135
    urls=[b'http://y@example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   136
)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   137
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   138
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   139
        b'x.prefix': b'http://example.org/foo/bar',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   140
        b'x.username': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   141
        b'x.password': b'xpassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   142
        b'y.prefix': b'http://example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   143
        b'y.username': b'y',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   144
        b'y.password': b'ypassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   145
    },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   146
    urls=[b'http://y@example.org/foo/bar'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   147
)
15024
0f1311e829c9 http: strip credentials from urllib2 manager URIs (issue2885)
Patrick Mezard <pmezard@gmail.com>
parents: 15005
diff changeset
   148
40663
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   149
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
   150
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   151
# prefix, username and URL have the same user
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   152
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   153
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   154
        b'x.prefix': b'https://example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   155
        b'x.username': None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   156
        b'x.password': b'xpassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   157
        b'y.prefix': b'http://y@example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   158
        b'y.username': b'y',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   159
        b'y.password': b'ypassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   160
    },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   161
    urls=[b'http://y@example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   162
)
40663
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   163
# Prefix has a different user from username and URL
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   164
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   165
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   166
        b'y.prefix': b'http://z@example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   167
        b'y.username': b'y',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   168
        b'y.password': b'ypassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   169
    },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   170
    urls=[b'http://y@example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   171
)
40663
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   172
# Prefix has a different user from URL; no username
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   173
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   174
    {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
   175
    urls=[b'http://y@example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   176
)
40663
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   177
# 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
   178
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   179
    {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   180
        b'y.prefix': b'http://y@example.org/foo',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   181
        b'y.username': b'z',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   182
        b'y.password': b'ypassword',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   183
    },
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   184
    urls=[b'http://y@example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   185
)
40663
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   186
# Prefix and URL have the same user; no username
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   187
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   188
    {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
   189
    urls=[b'http://y@example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   190
)
40663
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   191
# Prefix user, but no URL user or username
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   192
test(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   193
    {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
   194
    urls=[b'http://example.org/foo'],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   195
)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   196
40663
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   197
15024
0f1311e829c9 http: strip credentials from urllib2 manager URIs (issue2885)
Patrick Mezard <pmezard@gmail.com>
parents: 15005
diff changeset
   198
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
   199
    print('URIs:', fullurl, authurl)
28883
032c4c2f802a pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents: 28808
diff changeset
   200
    pm = urlreq.httppasswordmgrwithdefaultrealm()
41451
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
   201
    ai = _stringifyauthinfo(util.url(pycompat.bytesurl(fullurl)).authinfo()[1])
30dd20a56f3e tests: port test-hgweb-auth.py to Python 3
Augie Fackler <augie@google.com>
parents: 40663
diff changeset
   202
    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
   203
    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
   204
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41451
diff changeset
   205
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
   206
print('\n*** Test urllib2 and util.url\n')
15024
0f1311e829c9 http: strip credentials from urllib2 manager URIs (issue2885)
Patrick Mezard <pmezard@gmail.com>
parents: 15005
diff changeset
   207
testauthinfo('http://user@example.com:8080/foo', 'http://example.com:8080/foo')