tests/fakepatchtime.py
author Matt Harbison <matt_harbison@yahoo.com>
Sun, 01 Apr 2018 01:27:18 -0400
branchstable
changeset 37156 7de7bd407251
parent 34772 7be2f229285b
child 36325 9a75619776ca
permissions -rw-r--r--
server: ensure the incoming request falls under the prefix value Prior to this, the first test asserted in wsgiref.validate.check_environ() saying PATH didn't start with '/', but the second test served up the repo. The assertion was just added in this cycle (though the value of PATH is still wrong without the assertion). Allowing access to the repo at any URL outside of the prefix is a long standing bug. This also affected hgwebdir, at least when used via --subrepo. Paths are not being canonicalized, so accesses to things like 'foo/../bar' will get tossed out here, unless the prefix also matches.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     1
# extension to emulate invoking 'patch.internalpatch()' at the time
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     2
# specified by '[fakepatchtime] fakenow'
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     3
27284
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     4
from __future__ import absolute_import
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     5
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     6
from mercurial import (
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     7
    extensions,
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
     8
    patch as patchmod,
34772
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
     9
    registrar,
27284
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
    10
    util,
f624b0e69105 tests/fakepatchtime.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25756
diff changeset
    11
)
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    12
34772
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    13
configtable = {}
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    14
configitem = registrar.configitem(configtable)
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    15
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    16
configitem('fakepatchtime', 'fakenow',
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    17
    default=None,
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    18
)
7be2f229285b configitems: register the test 'fakepatchtime.fakenow' config
Boris Feld <boris.feld@octobus.net>
parents: 27284
diff changeset
    19
25756
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    20
def internalpatch(orig, ui, repo, patchobj, strip,
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    21
                  prefix='', files=None,
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    22
                  eolmode='strict', similarity=0):
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    23
    if files is None:
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    24
        files = set()
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    25
    r = orig(ui, repo, patchobj, strip,
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    26
             prefix=prefix, files=files,
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    27
             eolmode=eolmode, similarity=similarity)
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    28
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    29
    fakenow = ui.config('fakepatchtime', 'fakenow')
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    30
    if fakenow:
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    31
        # parsing 'fakenow' in YYYYmmddHHMM format makes comparison between
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    32
        # 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    33
        fakenow = util.parsedate(fakenow, ['%Y%m%d%H%M'])[0]
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    34
        for f in files:
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    35
            repo.wvfs.utime(f, (fakenow, fakenow))
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    36
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    37
    return r
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    38
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    39
def extsetup(ui):
a4a41525180c tests: add extension to emulate invoking internalpatch at the specific time
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    40
    extensions.wrapfunction(patchmod, 'internalpatch', internalpatch)