tests/test-hgweb-auth.py
author Martin von Zweigbergk <martinvonz@google.com>
Sun, 04 Mar 2018 08:41:29 -0800
changeset 40856 c8eb8d1fc6cf
parent 40663 c53f0ead5781
child 41451 30dd20a56f3e
permissions -rw-r--r--
rebase: move abort() onto rebaseruntime The function depends on a lot of the state of rebaseruntime, so it makes sense for it to be an instance method. This will let us remove many of the arguments to the method. That will be done in a later patch. Differential Revision: https://phab.mercurial-scm.org/D5392
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
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
     3
from mercurial import demandimport; 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
)
37940
31c37e703cee tests: use stringutil.pprint instead of custom dumper in test-hgweb-auth.py
Augie Fackler <augie@google.com>
parents: 36327
diff changeset
    11
from mercurial.utils import (
31c37e703cee tests: use stringutil.pprint instead of custom dumper in test-hgweb-auth.py
Augie Fackler <augie@google.com>
parents: 36327
diff changeset
    12
    stringutil,
31c37e703cee tests: use stringutil.pprint instead of custom dumper in test-hgweb-auth.py
Augie Fackler <augie@google.com>
parents: 36327
diff changeset
    13
)
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
28807
736f64b23a24 test-hgweb-auth: alias ui as uimod
Yuya Nishihara <yuya@tcha.org>
parents: 28748
diff changeset
    18
class myui(uimod.ui):
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    19
    def interactive(self):
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    20
        return False
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    21
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 29377
diff changeset
    22
origui = myui.load()
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    23
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    24
def writeauth(items):
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    25
    ui = origui.copy()
36327
58c1368ab629 py3: use dict.items() instead of dict.iteritems() in tests
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34023
diff changeset
    26
    for name, value in items.items():
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    27
        ui.setconfig('auth', name, value)
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    28
    return ui
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    29
15005
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    30
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
    31
    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
    32
    prefixes = set()
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    33
    for k in auth:
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    34
        prefixes.add(k.split('.', 1)[0])
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    35
    for p in prefixes:
15005
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    36
        for name in ('.username', '.password'):
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    37
            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
    38
                auth[p + name] = p
36327
58c1368ab629 py3: use dict.items() instead of dict.iteritems() in tests
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34023
diff changeset
    39
    auth = dict((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
    40
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    41
    ui = writeauth(auth)
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    42
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    43
    def _test(uri):
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
    44
        print('URI:', uri)
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    45
        try:
29377
2c019aac6b99 url: extract password database from password manager
liscju <piotr.listkiewicz@gmail.com>
parents: 28883
diff changeset
    46
            pm = url.passwordmgr(ui, urlreq.httppasswordmgrwithdefaultrealm())
15025
0593e8f81c71 http: pass user to readauthforuri() (fix 4a43e23b8c55)
Patrick Mezard <pmezard@gmail.com>
parents: 15024
diff changeset
    47
            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
    48
            if authinfo is not None:
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    49
                pm.add_password(*authinfo)
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
    50
            print('    ', pm.find_user_password('test', u))
28808
10c2ce44c35d test-hgweb-auth: stop direct symbol import of mercurial.error.Abort
Yuya Nishihara <yuya@tcha.org>
parents: 28807
diff changeset
    51
        except error.Abort:
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
    52
            print('    ','abort')
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    53
15005
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    54
    if not urls:
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    55
        urls = [
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    56
            'http://example.org/foo',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    57
            'http://example.org/foo/bar',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    58
            'http://example.org/bar',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    59
            'https://example.org/foo',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    60
            'https://example.org/foo/bar',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    61
            'https://example.org/bar',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    62
            'https://x@example.org/bar',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    63
            'https://y@example.org/bar',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    64
            ]
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    65
    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
    66
        _test(u)
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    67
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    68
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
    69
print('\n*** Test in-uri schemes\n')
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    70
test({'x.prefix': 'http://example.org'})
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    71
test({'x.prefix': 'https://example.org'})
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    72
test({'x.prefix': 'http://example.org', 'x.schemes': 'https'})
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    73
test({'x.prefix': 'https://example.org', 'x.schemes': 'http'})
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    74
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
    75
print('\n*** Test separately configured schemes\n')
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    76
test({'x.prefix': 'example.org', 'x.schemes': 'http'})
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    77
test({'x.prefix': 'example.org', 'x.schemes': 'https'})
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    78
test({'x.prefix': 'example.org', 'x.schemes': 'http https'})
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    79
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
    80
print('\n*** Test prefix matching\n')
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 8333
diff changeset
    81
test({'x.prefix': 'http://example.org/foo',
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 8333
diff changeset
    82
      'y.prefix': 'http://example.org/bar'})
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 8333
diff changeset
    83
test({'x.prefix': 'http://example.org/foo',
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 8333
diff changeset
    84
      'y.prefix': 'http://example.org/foo/bar'})
8333
89c80c3dc584 allow http authentication information to be specified in the configuration
Sune Foldager <cryo@cyanite.org>
parents:
diff changeset
    85
test({'x.prefix': '*', 'y.prefix': '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
    86
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
    87
print('\n*** Test user matching\n')
15005
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    88
test({'x.prefix': 'http://example.org/foo',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    89
      'x.username': None,
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    90
      'x.password': 'xpassword'},
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    91
     urls=['http://y@example.org/foo'])
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    92
test({'x.prefix': 'http://example.org/foo',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    93
      'x.username': None,
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    94
      'x.password': 'xpassword',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    95
      'y.prefix': 'http://example.org/foo',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    96
      'y.username': 'y',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    97
      'y.password': 'ypassword'},
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    98
     urls=['http://y@example.org/foo'])
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
    99
test({'x.prefix': 'http://example.org/foo/bar',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   100
      'x.username': None,
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   101
      'x.password': 'xpassword',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   102
      'y.prefix': 'http://example.org/foo',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   103
      'y.username': 'y',
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   104
      'y.password': 'ypassword'},
4a43e23b8c55 hgweb: do not ignore [auth] if url has a username (issue2822)
Patrick Mezard <pmezard@gmail.com>
parents: 10282
diff changeset
   105
     urls=['http://y@example.org/foo/bar'])
15024
0f1311e829c9 http: strip credentials from urllib2 manager URIs (issue2885)
Patrick Mezard <pmezard@gmail.com>
parents: 15005
diff changeset
   106
40663
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   107
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
   108
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   109
# prefix, username and URL have the same user
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   110
test({'x.prefix': 'https://example.org/foo',
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   111
      'x.username': None,
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   112
      'x.password': 'xpassword',
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   113
      'y.prefix': 'http://y@example.org/foo',
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   114
      'y.username': 'y',
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   115
      'y.password': 'ypassword'},
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   116
     urls=['http://y@example.org/foo'])
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   117
# Prefix has a different user from username and URL
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   118
test({'y.prefix': 'http://z@example.org/foo',
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   119
      'y.username': 'y',
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   120
      'y.password': 'ypassword'},
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   121
     urls=['http://y@example.org/foo'])
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   122
# Prefix has a different user from URL; no username
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   123
test({'y.prefix': 'http://z@example.org/foo',
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   124
      'y.password': 'ypassword'},
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   125
     urls=['http://y@example.org/foo'])
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   126
# Prefix and URL have same user, but doesn't match username
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   127
test({'y.prefix': 'http://y@example.org/foo',
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   128
      'y.username': 'z',
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   129
      'y.password': 'ypassword'},
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   130
     urls=['http://y@example.org/foo'])
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   131
# Prefix and URL have the same user; no username
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   132
test({'y.prefix': 'http://y@example.org/foo',
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   133
      'y.password': 'ypassword'},
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   134
     urls=['http://y@example.org/foo'])
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   135
# Prefix user, but no URL user or username
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   136
test({'y.prefix': 'http://y@example.org/foo',
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   137
      'y.password': 'ypassword'},
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   138
     urls=['http://example.org/foo'])
c53f0ead5781 http: allow 'auth.prefix' to have a username consistent with the URI
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
   139
15024
0f1311e829c9 http: strip credentials from urllib2 manager URIs (issue2885)
Patrick Mezard <pmezard@gmail.com>
parents: 15005
diff changeset
   140
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
   141
    print('URIs:', fullurl, authurl)
28883
032c4c2f802a pycompat: switch to util.urlreq/util.urlerr for py3 compat
timeless <timeless@mozdev.org>
parents: 28808
diff changeset
   142
    pm = urlreq.httppasswordmgrwithdefaultrealm()
15024
0f1311e829c9 http: strip credentials from urllib2 manager URIs (issue2885)
Patrick Mezard <pmezard@gmail.com>
parents: 15005
diff changeset
   143
    pm.add_password(*util.url(fullurl).authinfo()[1])
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
   144
    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
   145
28748
c2ba5a810fa1 py3: use print_function in test-hgweb-auth.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28747
diff changeset
   146
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
   147
testauthinfo('http://user@example.com:8080/foo', 'http://example.com:8080/foo')