##// END OF EJS Templates
hgweb: transition permissions hooks to modern request type (API)...
Gregory Szorc -
r36893:02bea04b default
parent child Browse files
Show More
@@ -46,7 +46,7 b' def checkauthz(hgweb, req, op):'
46 authentication info). Return if op allowed, else raise an ErrorResponse
46 authentication info). Return if op allowed, else raise an ErrorResponse
47 exception.'''
47 exception.'''
48
48
49 user = req.env.get(r'REMOTE_USER')
49 user = req.remoteuser
50
50
51 deny_read = hgweb.configlist('web', 'deny_read')
51 deny_read = hgweb.configlist('web', 'deny_read')
52 if deny_read and (not user or ismember(hgweb.repo.ui, user, deny_read)):
52 if deny_read and (not user or ismember(hgweb.repo.ui, user, deny_read)):
@@ -62,14 +62,13 b' def checkauthz(hgweb, req, op):'
62 return
62 return
63
63
64 # enforce that you can only push using POST requests
64 # enforce that you can only push using POST requests
65 if req.env[r'REQUEST_METHOD'] != r'POST':
65 if req.method != 'POST':
66 msg = 'push requires POST request'
66 msg = 'push requires POST request'
67 raise ErrorResponse(HTTP_METHOD_NOT_ALLOWED, msg)
67 raise ErrorResponse(HTTP_METHOD_NOT_ALLOWED, msg)
68
68
69 # require ssl by default for pushing, auth info cannot be sniffed
69 # require ssl by default for pushing, auth info cannot be sniffed
70 # and replayed
70 # and replayed
71 scheme = req.env.get('wsgi.url_scheme')
71 if hgweb.configbool('web', 'push_ssl') and req.urlscheme != 'https':
72 if hgweb.configbool('web', 'push_ssl') and scheme != 'https':
73 raise ErrorResponse(HTTP_FORBIDDEN, 'ssl required')
72 raise ErrorResponse(HTTP_FORBIDDEN, 'ssl required')
74
73
75 deny = hgweb.configlist('web', 'deny_push')
74 deny = hgweb.configlist('web', 'deny_push')
@@ -322,7 +322,7 b' class hgweb(object):'
322 res.headers['Content-Security-Policy'] = rctx.csp
322 res.headers['Content-Security-Policy'] = rctx.csp
323
323
324 handled = wireprotoserver.handlewsgirequest(
324 handled = wireprotoserver.handlewsgirequest(
325 rctx, wsgireq, req, res, self.check_perm)
325 rctx, req, res, self.check_perm)
326 if handled:
326 if handled:
327 return res.sendresponse()
327 return res.sendresponse()
328
328
@@ -380,7 +380,7 b' class hgweb(object):'
380
380
381 # check read permissions non-static content
381 # check read permissions non-static content
382 if cmd != 'static':
382 if cmd != 'static':
383 self.check_perm(rctx, wsgireq, None)
383 self.check_perm(rctx, req, None)
384
384
385 if cmd == '':
385 if cmd == '':
386 req.qsparams['cmd'] = tmpl.cache['default']
386 req.qsparams['cmd'] = tmpl.cache['default']
@@ -148,13 +148,12 b' class httpv1protocolhandler(wireprototyp'
148 def iscmd(cmd):
148 def iscmd(cmd):
149 return cmd in wireproto.commands
149 return cmd in wireproto.commands
150
150
151 def handlewsgirequest(rctx, wsgireq, req, res, checkperm):
151 def handlewsgirequest(rctx, req, res, checkperm):
152 """Possibly process a wire protocol request.
152 """Possibly process a wire protocol request.
153
153
154 If the current request is a wire protocol request, the request is
154 If the current request is a wire protocol request, the request is
155 processed by this function.
155 processed by this function.
156
156
157 ``wsgireq`` is a ``wsgirequest`` instance.
158 ``req`` is a ``parsedrequest`` instance.
157 ``req`` is a ``parsedrequest`` instance.
159 ``res`` is a ``wsgiresponse`` instance.
158 ``res`` is a ``wsgiresponse`` instance.
160
159
@@ -197,7 +196,7 b' def handlewsgirequest(rctx, wsgireq, req'
197 return True
196 return True
198
197
199 proto = httpv1protocolhandler(req, repo.ui,
198 proto = httpv1protocolhandler(req, repo.ui,
200 lambda perm: checkperm(rctx, wsgireq, perm))
199 lambda perm: checkperm(rctx, req, perm))
201
200
202 # The permissions checker should be the only thing that can raise an
201 # The permissions checker should be the only thing that can raise an
203 # ErrorResponse. It is kind of a layer violation to catch an hgweb
202 # ErrorResponse. It is kind of a layer violation to catch an hgweb
@@ -177,7 +177,7 b' test http authentication'
177 > import base64
177 > import base64
178 > from mercurial.hgweb import common
178 > from mercurial.hgweb import common
179 > def perform_authentication(hgweb, req, op):
179 > def perform_authentication(hgweb, req, op):
180 > auth = req.env.get('HTTP_AUTHORIZATION')
180 > auth = req.headers.get('Authorization')
181 > if not auth:
181 > if not auth:
182 > raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, 'who',
182 > raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, 'who',
183 > [('WWW-Authenticate', 'Basic Realm="mercurial"')])
183 > [('WWW-Authenticate', 'Basic Realm="mercurial"')])
@@ -168,7 +168,7 b' test http authentication'
168 > import base64
168 > import base64
169 > from mercurial.hgweb import common
169 > from mercurial.hgweb import common
170 > def perform_authentication(hgweb, req, op):
170 > def perform_authentication(hgweb, req, op):
171 > auth = req.env.get('HTTP_AUTHORIZATION')
171 > auth = req.headers.get('Authorization')
172 > if not auth:
172 > if not auth:
173 > raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, 'who',
173 > raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, 'who',
174 > [('WWW-Authenticate', 'Basic Realm="mercurial"')])
174 > [('WWW-Authenticate', 'Basic Realm="mercurial"')])
@@ -510,7 +510,7 b' We raise HTTP 500 because its message is'
510 > from mercurial import util
510 > from mercurial import util
511 > from mercurial.hgweb import common
511 > from mercurial.hgweb import common
512 > def perform_authentication(hgweb, req, op):
512 > def perform_authentication(hgweb, req, op):
513 > cookie = req.env.get('HTTP_COOKIE')
513 > cookie = req.headers.get('Cookie')
514 > if not cookie:
514 > if not cookie:
515 > raise common.ErrorResponse(common.HTTP_SERVER_ERROR, 'no-cookie')
515 > raise common.ErrorResponse(common.HTTP_SERVER_ERROR, 'no-cookie')
516 > raise common.ErrorResponse(common.HTTP_SERVER_ERROR, 'Cookie: %s' % cookie)
516 > raise common.ErrorResponse(common.HTTP_SERVER_ERROR, 'Cookie: %s' % cookie)
@@ -424,7 +424,7 b' a large file from the server rather than'
424 > import base64
424 > import base64
425 > from mercurial.hgweb import common
425 > from mercurial.hgweb import common
426 > def perform_authentication(hgweb, req, op):
426 > def perform_authentication(hgweb, req, op):
427 > auth = req.env.get('HTTP_AUTHORIZATION')
427 > auth = req.headers.get('Authorization')
428 > if not auth:
428 > if not auth:
429 > raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, 'who',
429 > raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, 'who',
430 > [('WWW-Authenticate', 'Basic Realm="mercurial"')])
430 > [('WWW-Authenticate', 'Basic Realm="mercurial"')])
General Comments 0
You need to be logged in to leave comments. Login now