tests/test-hgweb-non-interactive.t
author Augie Fackler <augie@google.com>
Tue, 30 Jun 2015 19:19:17 -0400
changeset 25708 d3d32643c060
parent 16913 f2719b387380
child 26219 ae33fff17c1e
permissions -rw-r--r--
wireproto: correctly escape batched args and responses (issue4739) This issue appears to be as old as wireproto batching itself: I can reproduce the failure as far back as 08ef6b5f3715 trivially by rebasing the test changes in this patch, which was back in the 1.9 era. I didn't test before that change, because prior to that the testfile has a different name and I'm lazy. Note that the test thought it was checking this case, but it actually wasn't: it put a literal ; in the arg and response for its greet command, but the mangle/unmangle step defined in the test meant that instead of "Fo, =;o" going over the wire, "Gp-!><p" went instead, which doesn't contain any special characters (those being [.=;]) and thus not exercising the escaping. The test has been updated to use pre-unmangled special characters, so the request is now "Fo+<:o", which mangles to "Gp,=;p". I have confirmed that the test fails without the adjustment to the escaping rules in wireproto.py. No existing clients of RPC batching were depending on the old behavior in any way. The only *actual* users of batchable RPCs in core were: 1) largefiles, wherein it batches up many statlfile calls. It sends hexlified hashes over the wire and gets a 0, 1, or 2 back as a response. No risk of special characters. 2) setdiscovery, which was using heads() and known(), both of which communicate via hexlified nodes. Again, no risk of special characters. Since the escaping functionality has been completely broken since it was introduced, we know that it has no users. As such, we can change the escaping mechanism without having to worry about backwards compatibility issues. For the curious, this was detected by chance: it happens that the lz4-compressed text of a test file for remotefilelog compressed to something containing a ;, which then caused the failure when I moved remotefilelog to using batching for file content fetching.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12440
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
     1
Tests if hgweb can run without touching sys.stdin, as is required
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
     2
by the WSGI standard and strictly implemented by mod_wsgi.
5337
8c5ef3b87cb1 Don't try to determine interactivity if ui() called with interactive=False.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
     3
13956
ffb5c09ba822 tests: remove redundant mkdir
Martin Geisler <mg@lazybytes.net>
parents: 12743
diff changeset
     4
  $ hg init repo
12440
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
     5
  $ cd repo
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
     6
  $ echo foo > bar
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
     7
  $ hg add bar
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
     8
  $ hg commit -m "test"
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
     9
  $ cat > request.py <<EOF
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    10
  > from mercurial import dispatch
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    11
  > from mercurial.hgweb.hgweb_mod import hgweb
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    12
  > from mercurial.ui import ui
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    13
  > from mercurial import hg
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    14
  > from StringIO import StringIO
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    15
  > import os, sys
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    16
  > 
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    17
  > class FileLike(object):
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    18
  >     def __init__(self, real):
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    19
  >         self.real = real
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    20
  >     def fileno(self):
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    21
  >         print >> sys.__stdout__, 'FILENO'
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    22
  >         return self.real.fileno()
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    23
  >     def read(self):
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    24
  >         print >> sys.__stdout__, 'READ'
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    25
  >         return self.real.read()
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    26
  >     def readline(self):
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    27
  >         print >> sys.__stdout__, 'READLINE'
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    28
  >         return self.real.readline()
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    29
  > 
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    30
  > sys.stdin = FileLike(sys.stdin)
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    31
  > errors = StringIO()
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    32
  > input = StringIO()
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    33
  > output = StringIO()
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    34
  > 
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    35
  > def startrsp(status, headers):
12743
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    36
  >     print '---- STATUS'
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    37
  >     print status
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    38
  >     print '---- HEADERS'
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    39
  >     print [i for i in headers if i[0] != 'ETag']
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    40
  >     print '---- DATA'
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    41
  >     return output.write
12440
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    42
  > 
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    43
  > env = {
12743
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    44
  >     'wsgi.version': (1, 0),
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    45
  >     'wsgi.url_scheme': 'http',
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    46
  >     'wsgi.errors': errors,
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    47
  >     'wsgi.input': input,
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    48
  >     'wsgi.multithread': False,
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    49
  >     'wsgi.multiprocess': False,
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    50
  >     'wsgi.run_once': False,
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    51
  >     'REQUEST_METHOD': 'GET',
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    52
  >     'SCRIPT_NAME': '',
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    53
  >     'PATH_INFO': '',
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    54
  >     'QUERY_STRING': '',
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    55
  >     'SERVER_NAME': '127.0.0.1',
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    56
  >     'SERVER_PORT': os.environ['HGPORT'],
4c4aeaab2339 check-code: add 'no tab indent' check for unified tests
Adrian Buehlmann <adrian@cadifra.com>
parents: 12440
diff changeset
    57
  >     'SERVER_PROTOCOL': 'HTTP/1.0'
12440
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    58
  > }
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    59
  > 
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    60
  > i = hgweb('.')
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    61
  > i(env, startrsp)
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    62
  > print '---- ERRORS'
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    63
  > print errors.getvalue()
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    64
  > print '---- OS.ENVIRON wsgi variables'
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    65
  > print sorted([x for x in os.environ if x.startswith('wsgi')])
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    66
  > print '---- request.ENVIRON wsgi variables'
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    67
  > print sorted([x for x in i.repo.ui.environ if x.startswith('wsgi')])
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    68
  > EOF
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    69
  $ python request.py
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    70
  ---- STATUS
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    71
  200 Script output follows
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    72
  ---- HEADERS
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    73
  [('Content-Type', 'text/html; charset=ascii')]
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    74
  ---- DATA
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    75
  ---- ERRORS
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    76
  
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    77
  ---- OS.ENVIRON wsgi variables
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    78
  []
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    79
  ---- request.ENVIRON wsgi variables
d9f7753a94d5 tests: unify test-hgweb-non-interactive
Matt Mackall <mpm@selenic.com>
parents: 12183
diff changeset
    80
  ['wsgi.errors', 'wsgi.input', 'wsgi.multiprocess', 'wsgi.multithread', 'wsgi.run_once', 'wsgi.url_scheme', 'wsgi.version']
16913
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 13956
diff changeset
    81
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 13956
diff changeset
    82
  $ cd ..