Debian Codegraph @

tests/test-hgweb-no-path-info.t

raw
1 This tests if hgweb and hgwebdir still work if the REQUEST_URI variable is
2 no longer passed with the request. Instead, SCRIPT_NAME and PATH_INFO
3 should be used from d74fc8dec2b4 onward to route the request.
4
5 $ hg init repo
6 $ cd repo
7 $ echo foo > bar
8 $ hg add bar
9 $ hg commit -m "test"
10 $ hg tip
11 changeset: 0:61c9426e69fe
12 tag: tip
13 user: test
14 date: Thu Jan 01 00:00:00 1970 +0000
15 summary: test
16
17 $ cat > request.py <<EOF
18 > import os
19 > import sys
20 > from mercurial import (
21 > hgweb,
22 > util,
23 > )
24 > stringio = util.stringio
25 >
26 > errors = stringio()
27 > input = stringio()
28 >
29 > def startrsp(status, headers):
30 > print('---- STATUS')
31 > print(status)
32 > print('---- HEADERS')
33 > print([i for i in headers if i[0] != 'ETag'])
34 > print('---- DATA')
35 > sys.stdout.flush()
36 > return output.write
37 >
38 > env = {
39 > 'wsgi.version': (1, 0),
40 > 'wsgi.url_scheme': 'http',
41 > 'wsgi.errors': errors,
42 > 'wsgi.input': input,
43 > 'wsgi.multithread': False,
44 > 'wsgi.multiprocess': False,
45 > 'wsgi.run_once': False,
46 > 'REQUEST_METHOD': 'GET',
47 > 'PATH_INFO': '/',
48 > 'SCRIPT_NAME': '',
49 > 'SERVER_NAME': '$LOCALIP',
50 > 'SERVER_PORT': os.environ['HGPORT'],
51 > 'SERVER_PROTOCOL': 'HTTP/1.0'
52 > }
53 >
54 > def process(app):
55 > try:
56 > stdout = sys.stdout.buffer
57 > except AttributeError:
58 > stdout = sys.stdout
59 > content = app(env, startrsp)
60 > stdout.write(output.getvalue())
61 > stdout.write(b''.join(content))
62 > stdout.flush()
63 > getattr(content, 'close', lambda : None)()
64 > if errors.getvalue():
65 > print('---- ERRORS')
66 > print(errors.getvalue())
67 > sys.stdout.flush()
68 >
69 > output = stringio()
70 > env['QUERY_STRING'] = 'style=atom'
71 > process(hgweb.hgweb(b'.', name=b'repo'))
72 >
73 > output = stringio()
74 > env['QUERY_STRING'] = 'style=raw'
75 > process(hgweb.hgwebdir({b'repo': b'.'}))
76 > EOF
77 $ "$PYTHON" request.py
78 ---- STATUS
79 200 Script output follows
80 ---- HEADERS
81 [('Content-Type', 'application/atom+xml; charset=ascii')]
82 ---- DATA
83 <?xml version="1.0" encoding="ascii"?>
84 <feed xmlns="http://www.w3.org/2005/Atom">
85 <!-- Changelog -->
86 <id>http://$LOCALIP:$HGPORT/</id> (glob)
87 <link rel="self" href="http://$LOCALIP:$HGPORT/atom-log"/> (glob)
88 <link rel="alternate" href="http://$LOCALIP:$HGPORT/"/> (glob)
89 <title>repo Changelog</title>
90 <updated>1970-01-01T00:00:00+00:00</updated>
91
92 <entry>
93 <title>[default] test</title>
94 <id>http://$LOCALIP:$HGPORT/#changeset-61c9426e69fef294feed5e2bbfc97d39944a5b1c</id> (glob)
95 <link href="http://$LOCALIP:$HGPORT/rev/61c9426e69fe"/> (glob)
96 <author>
97 <name>test</name>
98 <email>&#116;&#101;&#115;&#116;</email>
99 </author>
100 <updated>1970-01-01T00:00:00+00:00</updated>
101 <published>1970-01-01T00:00:00+00:00</published>
102 <content type="xhtml">
103 <table xmlns="http://www.w3.org/1999/xhtml">
104 <tr>
105 <th style="text-align:left;">changeset</th>
106 <td>61c9426e69fe</td>
107 </tr>
108 <tr>
109 <th style="text-align:left;">branch</th>
110 <td>default</td>
111 </tr>
112 <tr>
113 <th style="text-align:left;">bookmark</th>
114 <td></td>
115 </tr>
116 <tr>
117 <th style="text-align:left;">tag</th>
118 <td>tip</td>
119 </tr>
120 <tr>
121 <th style="text-align:left;">user</th>
122 <td>&#116;&#101;&#115;&#116;</td>
123 </tr>
124 <tr>
125 <th style="text-align:left;vertical-align:top;">description</th>
126 <td>test</td>
127 </tr>
128 <tr>
129 <th style="text-align:left;vertical-align:top;">files</th>
130 <td>bar<br /></td>
131 </tr>
132 </table>
133 </content>
134 </entry>
135
136 </feed>
137 ---- STATUS
138 200 Script output follows
139 ---- HEADERS
140 [('Content-Type', 'text/plain; charset=ascii')]
141 ---- DATA
142
143 /repo/
144
145
146 $ cd ..