Show More
@@ -85,8 +85,22 b' class digestauthserver(object):' | |||||
85 |
|
85 | |||
86 | return True |
|
86 | return True | |
87 |
|
87 | |||
|
88 | digest = digestauthserver() | |||
|
89 | ||||
88 | def perform_authentication(hgweb, req, op): |
|
90 | def perform_authentication(hgweb, req, op): | |
89 | auth = req.headers.get(b'Authorization') |
|
91 | auth = req.headers.get(b'Authorization') | |
|
92 | ||||
|
93 | if req.headers.get(b'X-HgTest-AuthType') == b'Digest': | |||
|
94 | if not auth: | |||
|
95 | challenge = digest.makechallenge(b'mercurial') | |||
|
96 | raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who', | |||
|
97 | [(b'WWW-Authenticate', b'Digest %s' % challenge)]) | |||
|
98 | ||||
|
99 | if not digest.checkauth(req, auth[7:]): | |||
|
100 | raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no') | |||
|
101 | ||||
|
102 | return | |||
|
103 | ||||
90 | if not auth: |
|
104 | if not auth: | |
91 | raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who', |
|
105 | raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who', | |
92 | [(b'WWW-Authenticate', b'Basic Realm="mercurial"')]) |
|
106 | [(b'WWW-Authenticate', b'Basic Realm="mercurial"')]) | |
@@ -96,3 +110,4 b' def perform_authentication(hgweb, req, o' | |||||
96 |
|
110 | |||
97 | def extsetup(ui): |
|
111 | def extsetup(ui): | |
98 | common.permhooks.insert(0, perform_authentication) |
|
112 | common.permhooks.insert(0, perform_authentication) | |
|
113 | digest.adduser(b'user', b'pass', b'mercurial') |
@@ -173,7 +173,7 b' test http authentication' | |||||
173 | $ cd test |
|
173 | $ cd test | |
174 |
|
174 | |||
175 | $ hg serve --config extensions.x=$TESTDIR/httpserverauth.py -p $HGPORT2 -d \ |
|
175 | $ hg serve --config extensions.x=$TESTDIR/httpserverauth.py -p $HGPORT2 -d \ | |
176 | > --pid-file=pid --config server.preferuncompressed=True \ |
|
176 | > --pid-file=pid --config server.preferuncompressed=True -E ../errors2.log \ | |
177 | > --config web.push_ssl=False --config web.allow_push=* -A ../access.log |
|
177 | > --config web.push_ssl=False --config web.allow_push=* -A ../access.log | |
178 | $ cat pid >> $DAEMON_PIDS |
|
178 | $ cat pid >> $DAEMON_PIDS | |
179 |
|
179 | |||
@@ -209,6 +209,26 b' test http authentication' | |||||
209 | $ hg id http://user@localhost:$HGPORT2/ |
|
209 | $ hg id http://user@localhost:$HGPORT2/ | |
210 | 5fed3813f7f5 |
|
210 | 5fed3813f7f5 | |
211 |
|
211 | |||
|
212 | $ cat > use_digests.py << EOF | |||
|
213 | > from mercurial import ( | |||
|
214 | > exthelper, | |||
|
215 | > url, | |||
|
216 | > ) | |||
|
217 | > | |||
|
218 | > eh = exthelper.exthelper() | |||
|
219 | > uisetup = eh.finaluisetup | |||
|
220 | > | |||
|
221 | > @eh.wrapfunction(url, 'opener') | |||
|
222 | > def urlopener(orig, *args, **kwargs): | |||
|
223 | > opener = orig(*args, **kwargs) | |||
|
224 | > opener.addheaders.append((r'X-HgTest-AuthType', r'Digest')) | |||
|
225 | > return opener | |||
|
226 | > EOF | |||
|
227 | ||||
|
228 | $ hg id http://localhost:$HGPORT2/ --config extensions.x=use_digests.py || true | |||
|
229 | abort: HTTP Error 403: bad user (py3 !) | |||
|
230 | 5fed3813f7f5 (no-py3 !) | |||
|
231 | ||||
212 | #if no-reposimplestore |
|
232 | #if no-reposimplestore | |
213 | $ hg clone http://user:pass@localhost:$HGPORT2/ dest 2>&1 |
|
233 | $ hg clone http://user:pass@localhost:$HGPORT2/ dest 2>&1 | |
214 | streaming all changes |
|
234 | streaming all changes | |
@@ -362,6 +382,15 b' test http authentication' | |||||
362 | "GET /?cmd=lookup HTTP/1.1" 200 - x-hgarg-1:key=tip x-hgproto-1:0.1 0.2 comp=$USUAL_COMPRESSIONS$ partial-pull |
|
382 | "GET /?cmd=lookup HTTP/1.1" 200 - x-hgarg-1:key=tip x-hgproto-1:0.1 0.2 comp=$USUAL_COMPRESSIONS$ partial-pull | |
363 | "GET /?cmd=listkeys HTTP/1.1" 200 - x-hgarg-1:namespace=namespaces x-hgproto-1:0.1 0.2 comp=$USUAL_COMPRESSIONS$ partial-pull |
|
383 | "GET /?cmd=listkeys HTTP/1.1" 200 - x-hgarg-1:namespace=namespaces x-hgproto-1:0.1 0.2 comp=$USUAL_COMPRESSIONS$ partial-pull | |
364 | "GET /?cmd=listkeys HTTP/1.1" 200 - x-hgarg-1:namespace=bookmarks x-hgproto-1:0.1 0.2 comp=$USUAL_COMPRESSIONS$ partial-pull |
|
384 | "GET /?cmd=listkeys HTTP/1.1" 200 - x-hgarg-1:namespace=bookmarks x-hgproto-1:0.1 0.2 comp=$USUAL_COMPRESSIONS$ partial-pull | |
|
385 | "GET /?cmd=capabilities HTTP/1.1" 401 - x-hgtest-authtype:Digest | |||
|
386 | "GET /?cmd=capabilities HTTP/1.1" 403 - x-hgtest-authtype:Digest (py3 !) | |||
|
387 | "GET /?cmd=capabilities HTTP/1.1" 200 - x-hgtest-authtype:Digest (no-py3 !) | |||
|
388 | "GET /?cmd=lookup HTTP/1.1" 401 - x-hgarg-1:key=tip x-hgproto-1:0.1 0.2 comp=$USUAL_COMPRESSIONS$ partial-pull x-hgtest-authtype:Digest (no-py3 !) | |||
|
389 | "GET /?cmd=lookup HTTP/1.1" 200 - x-hgarg-1:key=tip x-hgproto-1:0.1 0.2 comp=$USUAL_COMPRESSIONS$ partial-pull x-hgtest-authtype:Digest (no-py3 !) | |||
|
390 | "GET /?cmd=listkeys HTTP/1.1" 401 - x-hgarg-1:namespace=namespaces x-hgproto-1:0.1 0.2 comp=$USUAL_COMPRESSIONS$ partial-pull x-hgtest-authtype:Digest (no-py3 !) | |||
|
391 | "GET /?cmd=listkeys HTTP/1.1" 200 - x-hgarg-1:namespace=namespaces x-hgproto-1:0.1 0.2 comp=$USUAL_COMPRESSIONS$ partial-pull x-hgtest-authtype:Digest (no-py3 !) | |||
|
392 | "GET /?cmd=listkeys HTTP/1.1" 401 - x-hgarg-1:namespace=bookmarks x-hgproto-1:0.1 0.2 comp=$USUAL_COMPRESSIONS$ partial-pull x-hgtest-authtype:Digest (no-py3 !) | |||
|
393 | "GET /?cmd=listkeys HTTP/1.1" 200 - x-hgarg-1:namespace=bookmarks x-hgproto-1:0.1 0.2 comp=$USUAL_COMPRESSIONS$ partial-pull x-hgtest-authtype:Digest (no-py3 !) | |||
365 | "GET /?cmd=capabilities HTTP/1.1" 401 - (no-reposimplestore !) |
|
394 | "GET /?cmd=capabilities HTTP/1.1" 401 - (no-reposimplestore !) | |
366 | "GET /?cmd=capabilities HTTP/1.1" 200 - (no-reposimplestore !) |
|
395 | "GET /?cmd=capabilities HTTP/1.1" 200 - (no-reposimplestore !) | |
367 | "GET /?cmd=batch HTTP/1.1" 200 - x-hgarg-1:cmds=heads+%3Bknown+nodes%3D x-hgproto-1:0.1 0.2 comp=$USUAL_COMPRESSIONS$ partial-pull (no-reposimplestore !) |
|
396 | "GET /?cmd=batch HTTP/1.1" 200 - x-hgarg-1:cmds=heads+%3Bknown+nodes%3D x-hgproto-1:0.1 0.2 comp=$USUAL_COMPRESSIONS$ partial-pull (no-reposimplestore !) | |
@@ -431,6 +460,9 b' check error log' | |||||
431 |
|
460 | |||
432 | $ cat error.log |
|
461 | $ cat error.log | |
433 |
|
462 | |||
|
463 | $ cat errors2.log | |||
|
464 | $LOCALIP - - [$ERRDATE$] HG error: No hash found for user/realm "b'user'/mercurial" (glob) (py3 !) | |||
|
465 | ||||
434 | check abort error reporting while pulling/cloning |
|
466 | check abort error reporting while pulling/cloning | |
435 |
|
467 | |||
436 | $ $RUNTESTDIR/killdaemons.py |
|
468 | $ $RUNTESTDIR/killdaemons.py |
General Comments 0
You need to be logged in to leave comments.
Login now