##// END OF EJS Templates
test-http: test http authentication...
Mads Kiilerich -
r15026:f32a2989 stable
parent child Browse files
Show More
@@ -1,115 +1,164 b''
1 1
2 2 $ hg init test
3 3 $ cd test
4 4 $ echo foo>foo
5 5 $ mkdir foo.d foo.d/bAr.hg.d foo.d/baR.d.hg
6 6 $ echo foo>foo.d/foo
7 7 $ echo bar>foo.d/bAr.hg.d/BaR
8 8 $ echo bar>foo.d/baR.d.hg/bAR
9 9 $ hg commit -A -m 1
10 10 adding foo
11 11 adding foo.d/bAr.hg.d/BaR
12 12 adding foo.d/baR.d.hg/bAR
13 13 adding foo.d/foo
14 14 $ hg serve -p $HGPORT -d --pid-file=../hg1.pid -E ../error.log
15 15 $ hg --config server.uncompressed=False serve -p $HGPORT1 -d --pid-file=../hg2.pid
16 16
17 17 Test server address cannot be reused
18 18
19 19 $ hg serve -p $HGPORT1 2>&1
20 20 abort: cannot start server at ':$HGPORT1': Address already in use
21 21 [255]
22 22 $ cd ..
23 23 $ cat hg1.pid hg2.pid >> $DAEMON_PIDS
24 24
25 25 clone via stream
26 26
27 27 $ hg clone --uncompressed http://localhost:$HGPORT/ copy 2>&1
28 28 streaming all changes
29 29 6 files to transfer, 606 bytes of data
30 30 transferred * bytes in * seconds (*/sec) (glob)
31 31 updating to branch default
32 32 4 files updated, 0 files merged, 0 files removed, 0 files unresolved
33 33 $ hg verify -R copy
34 34 checking changesets
35 35 checking manifests
36 36 crosschecking files in changesets and manifests
37 37 checking files
38 38 4 files, 1 changesets, 4 total revisions
39 39
40 40 try to clone via stream, should use pull instead
41 41
42 42 $ hg clone --uncompressed http://localhost:$HGPORT1/ copy2
43 43 requesting all changes
44 44 adding changesets
45 45 adding manifests
46 46 adding file changes
47 47 added 1 changesets with 4 changes to 4 files
48 48 updating to branch default
49 49 4 files updated, 0 files merged, 0 files removed, 0 files unresolved
50 50
51 51 clone via pull
52 52
53 53 $ hg clone http://localhost:$HGPORT1/ copy-pull
54 54 requesting all changes
55 55 adding changesets
56 56 adding manifests
57 57 adding file changes
58 58 added 1 changesets with 4 changes to 4 files
59 59 updating to branch default
60 60 4 files updated, 0 files merged, 0 files removed, 0 files unresolved
61 61 $ hg verify -R copy-pull
62 62 checking changesets
63 63 checking manifests
64 64 crosschecking files in changesets and manifests
65 65 checking files
66 66 4 files, 1 changesets, 4 total revisions
67 67 $ cd test
68 68 $ echo bar > bar
69 69 $ hg commit -A -d '1 0' -m 2
70 70 adding bar
71 71 $ cd ..
72 72
73 73 incoming via HTTP
74 74
75 75 $ hg clone http://localhost:$HGPORT1/ --rev 0 partial
76 76 adding changesets
77 77 adding manifests
78 78 adding file changes
79 79 added 1 changesets with 4 changes to 4 files
80 80 updating to branch default
81 81 4 files updated, 0 files merged, 0 files removed, 0 files unresolved
82 82 $ cd partial
83 83 $ touch LOCAL
84 84 $ hg ci -qAm LOCAL
85 85 $ hg incoming http://localhost:$HGPORT1/ --template '{desc}\n'
86 86 comparing with http://localhost:$HGPORT1/
87 87 searching for changes
88 88 2
89 89 $ cd ..
90 90
91 91 pull
92 92
93 93 $ cd copy-pull
94 94 $ echo '[hooks]' >> .hg/hgrc
95 95 $ echo 'changegroup = python "$TESTDIR"/printenv.py changegroup' >> .hg/hgrc
96 96 $ hg pull
97 97 pulling from http://localhost:$HGPORT1/
98 98 searching for changes
99 99 adding changesets
100 100 adding manifests
101 101 adding file changes
102 102 added 1 changesets with 1 changes to 1 files
103 103 changegroup hook: HG_NODE=5fed3813f7f5e1824344fdc9cf8f63bb662c292d HG_SOURCE=pull HG_URL=http://localhost:$HGPORT1/
104 104 (run 'hg update' to get a working copy)
105 105 $ cd ..
106 106
107 107 clone from invalid URL
108 108
109 109 $ hg clone http://localhost:$HGPORT/bad
110 110 abort: HTTP Error 404: Not Found
111 111 [255]
112 112
113 test http authentication
114
115 $ cd test
116 $ cat << EOT > userpass.py
117 > import base64
118 > from mercurial.hgweb import common
119 > def perform_authentication(hgweb, req, op):
120 > auth = req.env.get('HTTP_AUTHORIZATION')
121 > if not auth:
122 > raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, 'who',
123 > [('WWW-Authenticate', 'Basic Realm="mercurial"')])
124 > if base64.b64decode(auth.split()[1]).split(':', 1) != ['user', 'pass']:
125 > raise common.ErrorResponse(common.HTTP_FORBIDDEN, 'no')
126 > def extsetup():
127 > common.permhooks.insert(0, perform_authentication)
128 > EOT
129 $ hg --config extensions.x=userpass.py serve -p $HGPORT2 -d --pid-file=pid
130 $ cat pid >> $DAEMON_PIDS
131
132 $ hg id http://localhost:$HGPORT2/
133 abort: http authorization required
134 [255]
135 $ hg id http://user@localhost:$HGPORT2/
136 abort: http authorization required
137 [255]
138 $ hg id http://user:pass@localhost:$HGPORT2/
139 5fed3813f7f5
140 $ echo '[auth]' >> .hg/hgrc
141 $ echo 'l.schemes=http' >> .hg/hgrc
142 $ echo 'l.prefix=lo' >> .hg/hgrc
143 $ echo 'l.username=user' >> .hg/hgrc
144 $ echo 'l.password=pass' >> .hg/hgrc
145 $ hg id http://localhost:$HGPORT2/
146 5fed3813f7f5
147 $ hg id http://localhost:$HGPORT2/
148 5fed3813f7f5
149 $ hg id http://user@localhost:$HGPORT2/
150 5fed3813f7f5
151 $ hg id http://user:pass@localhost:$HGPORT2/
152 5fed3813f7f5
153 $ hg id http://user2@localhost:$HGPORT2/
154 abort: http authorization required
155 [255]
156 $ hg id http://user:pass2@localhost:$HGPORT2/
157 abort: HTTP Error 403: no
158 [255]
159
160 $ cd ..
161
113 162 check error log
114 163
115 164 $ cat error.log
General Comments 0
You need to be logged in to leave comments. Login now