##// END OF EJS Templates
hgweb: add support to explicitly access hidden changesets...
marmoute -
r51308:4077d622 default
parent child Browse files
Show More
@@ -1244,6 +1244,11 b' coreconfigitem('
1244 1244 )
1245 1245 coreconfigitem(
1246 1246 b'experimental',
1247 b'server.allow-hidden-access',
1248 default=list,
1249 )
1250 coreconfigitem(
1251 b'experimental',
1247 1252 b'server.filesdata.recommended-batch-size',
1248 1253 default=50000,
1249 1254 )
@@ -13,6 +13,7 b' import mimetypes'
13 13 import os
14 14 import stat
15 15
16 from ..i18n import _
16 17 from ..pycompat import (
17 18 getattr,
18 19 open,
@@ -49,6 +50,32 b' def ismember(ui, username, userlist):'
49 50 return userlist == [b'*'] or username in userlist
50 51
51 52
53 def hashiddenaccess(repo, req):
54 if bool(req.qsparams.get(b'access-hidden')):
55 # Disable this by default for now. Main risk is to get critical
56 # information exposed through this. This is expecially risky if
57 # someone decided to make a changeset secret for good reason, but
58 # its predecessors are still draft.
59 #
60 # The feature is currently experimental, so we can still decide to
61 # change the default.
62 ui = repo.ui
63 allow = ui.configlist(b'experimental', b'server.allow-hidden-access')
64 user = req.remoteuser
65 if allow and ismember(ui, user, allow):
66 return True
67 else:
68 msg = (
69 _(
70 b'ignoring request to access hidden changeset by '
71 b'unauthorized user: %r\n'
72 )
73 % user
74 )
75 ui.warn(msg)
76 return False
77
78
52 79 def checkauthz(hgweb, req, op):
53 80 """Check permission for operation based on request data (including
54 81 authentication info). Return if op allowed, else raise an ErrorResponse
@@ -39,6 +39,7 b' from .. import ('
39 39 )
40 40
41 41 from . import (
42 common,
42 43 request as requestmod,
43 44 webcommands,
44 45 webutil,
@@ -124,6 +125,16 b' class requestcontext:'
124 125 self.req = req
125 126 self.res = res
126 127
128 # Only works if the filter actually support being upgraded to show
129 # visible changesets
130 current_filter = repo.filtername
131 if (
132 common.hashiddenaccess(repo, req)
133 and current_filter is not None
134 and current_filter + b'.hidden' in repoview.filtertable
135 ):
136 self.repo = self.repo.filtered(repo.filtername + b'.hidden')
137
127 138 self.maxchanges = self.configint(b'web', b'maxchanges')
128 139 self.stripecount = self.configint(b'web', b'stripes')
129 140 self.maxshortchanges = self.configint(b'web', b'maxshortchanges')
@@ -111,3 +111,47 b' changesets in secret and higher phases a'
111 111 revision: 0
112 112
113 113 $ killdaemons.py
114
115 Test accessing hidden changeset through hgweb
116 ---------------------------------------------
117
118 $ hg -R repo-with-hidden serve -p $HGPORT -d --pid-file hg.pid --config "experimental.server.allow-hidden-access=*" -E error.log --accesslog access.log
119 $ cat hg.pid >> $DAEMON_PIDS
120
121 Hidden changeset are hidden by default:
122
123 $ get-with-headers.py localhost:$HGPORT 'log?style=raw' | grep revision:
124 revision: 2
125 revision: 0
126
127 Hidden changeset are visible when requested:
128
129 $ get-with-headers.py localhost:$HGPORT 'log?style=raw&access-hidden=1' | grep revision:
130 revision: 3
131 revision: 2
132 revision: 1
133 revision: 0
134
135 Same check on a server that do not allow hidden access:
136 ```````````````````````````````````````````````````````
137
138 $ hg -R repo-with-hidden serve -p $HGPORT1 -d --pid-file hg2.pid --config "experimental.server.allow-hidden-access=" -E error.log --accesslog access.log
139 $ cat hg2.pid >> $DAEMON_PIDS
140
141 Hidden changeset are hidden by default:
142
143 $ get-with-headers.py localhost:$HGPORT1 'log?style=raw' | grep revision:
144 revision: 2
145 revision: 0
146
147 Hidden changeset are still hidden despite being the hidden access request:
148
149 $ get-with-headers.py localhost:$HGPORT1 'log?style=raw&access-hidden=1' | grep revision:
150 revision: 2
151 revision: 0
152
153 =============
154 Final cleanup
155 =============
156
157 $ killdaemons.py
General Comments 0
You need to be logged in to leave comments. Login now