Mercurial > hg
annotate tests/test-annotate.py @ 37048:fc5e261915b9
wireproto: require POST for all HTTPv2 requests
Wire protocol version 1 transfers argument data via request
headers by default. This has historically caused problems because
servers institute limits on the length of individual HTTP headers
as well as the total size of all request headers. Mercurial servers
can advertise the maximum length of an individual header. But
there's no guarantee any intermediate HTTP agents will accept
headers up to that length.
In the existing wire protocol, server operators typically also
key off the HTTP request method to implement authentication.
For example, GET requests translate to read-only requests and
can be allowed. But read-write commands must use POST and require
authentication. This has typically worked because the only wire
protocol commands that use POST modify the repo (e.g. the
"unbundle" command).
There is an experimental feature to enable clients to transmit
argument data via POST request bodies. This is technically a
better and more robust solution. But we can't enable it by default
because of servers assuming POST means write access.
In version 2 of the wire protocol, the permissions of a request
are encoded in the URL. And with it being a new protocol in a new
URL space, we're not constrained by backwards compatibility
requirements.
This commit adopts the technically superior mechanism of using
HTTP request bodies to send argument data by requiring POST for
all commands. Strictly speaking, it may be possible to send
request bodies on GET requests. But my experience is that not all
HTTP stacks support this. POST pretty much always works. Using POST
for read-only operations does sacrifice some RESTful design
purity. But this API cares about practicality, not about being
in Roy T. Fielding's REST ivory tower.
There's a chance we may relax this restriction in the future. But
for now, I want to see how far we can get with a POST only API.
Differential Revision: https://phab.mercurial-scm.org/D2837
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 13 Mar 2018 11:57:43 -0700 |
parents | ec46b0ee2e3c |
children | 434e520adb8c |
rev | line source |
---|---|
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
1 from __future__ import absolute_import |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
2 from __future__ import print_function |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
3 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
4 import unittest |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
5 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
6 from mercurial import ( |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
7 mdiff, |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
8 ) |
36917
7affcabf561e
dagop: move annotateline and _annotatepair from context.py
Yuya Nishihara <yuya@tcha.org>
parents:
35947
diff
changeset
|
9 from mercurial.dagop import ( |
34432
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34430
diff
changeset
|
10 annotateline, |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
11 _annotatepair, |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
12 ) |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
13 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
14 class AnnotateTests(unittest.TestCase): |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
15 """Unit tests for annotate code.""" |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
16 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
17 def testannotatepair(self): |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
18 self.maxDiff = None # camelcase-required |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
19 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
20 oldfctx = b'old' |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
21 p1fctx, p2fctx, childfctx = b'p1', b'p2', b'c' |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
22 olddata = b'a\nb\n' |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
23 p1data = b'a\nb\nc\n' |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
24 p2data = b'a\nc\nd\n' |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
25 childdata = b'a\nb2\nc\nc2\nd\n' |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
26 diffopts = mdiff.diffopts() |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
27 |
36935
ec46b0ee2e3c
annotate: correct parameter name of decorate() function
Yuya Nishihara <yuya@tcha.org>
parents:
36917
diff
changeset
|
28 def decorate(text, fctx): |
ec46b0ee2e3c
annotate: correct parameter name of decorate() function
Yuya Nishihara <yuya@tcha.org>
parents:
36917
diff
changeset
|
29 return ([annotateline(fctx=fctx, lineno=i) |
35946
cf887d601014
py3: use range instead of xrange
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34433
diff
changeset
|
30 for i in range(1, text.count(b'\n') + 1)], |
34432
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34430
diff
changeset
|
31 text) |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
32 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
33 # Basic usage |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
34 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
35 oldann = decorate(olddata, oldfctx) |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
36 p1ann = decorate(p1data, p1fctx) |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
37 p1ann = _annotatepair([oldann], p1fctx, p1ann, False, diffopts) |
34432
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34430
diff
changeset
|
38 self.assertEqual(p1ann[0], [ |
35947
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
39 annotateline(b'old', 1), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
40 annotateline(b'old', 2), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
41 annotateline(b'p1', 3), |
34432
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34430
diff
changeset
|
42 ]) |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
43 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
44 p2ann = decorate(p2data, p2fctx) |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
45 p2ann = _annotatepair([oldann], p2fctx, p2ann, False, diffopts) |
34432
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34430
diff
changeset
|
46 self.assertEqual(p2ann[0], [ |
35947
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
47 annotateline(b'old', 1), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
48 annotateline(b'p2', 2), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
49 annotateline(b'p2', 3), |
34432
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34430
diff
changeset
|
50 ]) |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
51 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
52 # Test with multiple parents (note the difference caused by ordering) |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
53 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
54 childann = decorate(childdata, childfctx) |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
55 childann = _annotatepair([p1ann, p2ann], childfctx, childann, False, |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
56 diffopts) |
34432
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34430
diff
changeset
|
57 self.assertEqual(childann[0], [ |
35947
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
58 annotateline(b'old', 1), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
59 annotateline(b'c', 2), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
60 annotateline(b'p2', 2), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
61 annotateline(b'c', 4), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
62 annotateline(b'p2', 3), |
34432
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34430
diff
changeset
|
63 ]) |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
64 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
65 childann = decorate(childdata, childfctx) |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
66 childann = _annotatepair([p2ann, p1ann], childfctx, childann, False, |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
67 diffopts) |
34432
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34430
diff
changeset
|
68 self.assertEqual(childann[0], [ |
35947
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
69 annotateline(b'old', 1), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
70 annotateline(b'c', 2), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
71 annotateline(b'p1', 3), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
72 annotateline(b'c', 4), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
73 annotateline(b'p2', 3), |
34432
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34430
diff
changeset
|
74 ]) |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
75 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
76 # Test with skipchild (note the difference caused by ordering) |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
77 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
78 childann = decorate(childdata, childfctx) |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
79 childann = _annotatepair([p1ann, p2ann], childfctx, childann, True, |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
80 diffopts) |
34432
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34430
diff
changeset
|
81 self.assertEqual(childann[0], [ |
35947
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
82 annotateline(b'old', 1), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
83 annotateline(b'old', 2, True), |
34433
2f5a135b2b04
annotate: track whether a particular annotation was the result of a skip
Siddharth Agarwal <sid0@fb.com>
parents:
34432
diff
changeset
|
84 # note that this line was carried over from earlier so it is *not* |
2f5a135b2b04
annotate: track whether a particular annotation was the result of a skip
Siddharth Agarwal <sid0@fb.com>
parents:
34432
diff
changeset
|
85 # marked skipped |
35947
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
86 annotateline(b'p2', 2), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
87 annotateline(b'p2', 2, True), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
88 annotateline(b'p2', 3), |
34432
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34430
diff
changeset
|
89 ]) |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
90 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
91 childann = decorate(childdata, childfctx) |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
92 childann = _annotatepair([p2ann, p1ann], childfctx, childann, True, |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
93 diffopts) |
34432
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34430
diff
changeset
|
94 self.assertEqual(childann[0], [ |
35947
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
95 annotateline(b'old', 1), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
96 annotateline(b'old', 2, True), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
97 annotateline(b'p1', 3), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
98 annotateline(b'p1', 3, True), |
a36d3c8a0e41
py3: add b'' prefixes to string literals in test files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35946
diff
changeset
|
99 annotateline(b'p2', 3), |
34432
2e32c6a31cc7
annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents:
34430
diff
changeset
|
100 ]) |
34430
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
101 |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
102 if __name__ == '__main__': |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
103 import silenttestrunner |
80215865d154
annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff
changeset
|
104 silenttestrunner.main(__name__) |