##// END OF EJS Templates
phabricator: auto-sanitise API tokens and HTTP cookies from VCR recordings...
Ian Moody -
r42636:d3c81439 default
parent child Browse files
Show More
@@ -134,6 +134,19 b' def vcrcommand(name, flags, spec, helpca'
134 r2params = r2.body.split(b'&')
134 r2params = r2.body.split(b'&')
135 return set(r1params) == set(r2params)
135 return set(r1params) == set(r2params)
136
136
137 def sanitiserequest(request):
138 request.body = re.sub(
139 r'cli-[a-z0-9]+',
140 r'cli-hahayouwish',
141 request.body
142 )
143 return request
144
145 def sanitiseresponse(response):
146 if r'set-cookie' in response[r'headers']:
147 del response[r'headers'][r'set-cookie']
148 return response
149
137 def decorate(fn):
150 def decorate(fn):
138 def inner(*args, **kwargs):
151 def inner(*args, **kwargs):
139 cassette = pycompat.fsdecode(kwargs.pop(r'test_vcr', None))
152 cassette = pycompat.fsdecode(kwargs.pop(r'test_vcr', None))
@@ -144,6 +157,8 b' def vcrcommand(name, flags, spec, helpca'
144 import vcr.stubs as stubs
157 import vcr.stubs as stubs
145 vcr = vcrmod.VCR(
158 vcr = vcrmod.VCR(
146 serializer=r'json',
159 serializer=r'json',
160 before_record_request=sanitiserequest,
161 before_record_response=sanitiseresponse,
147 custom_patches=[
162 custom_patches=[
148 (urlmod, r'httpconnection',
163 (urlmod, r'httpconnection',
149 stubs.VCRHTTPConnection),
164 stubs.VCRHTTPConnection),
@@ -15,8 +15,8 b''
15 > hgphab.prefix = phab.mercurial-scm.org
15 > hgphab.prefix = phab.mercurial-scm.org
16 > # When working on the extension and making phabricator interaction
16 > # When working on the extension and making phabricator interaction
17 > # changes, edit this to be a real phabricator token. When done, edit
17 > # changes, edit this to be a real phabricator token. When done, edit
18 > # it back, and make sure to also edit your VCR transcripts to match
18 > # it back. The VCR transcripts will be auto-sanitised to replace your real
19 > # whatever value you put here.
19 > # token with this value.
20 > hgphab.phabtoken = cli-hahayouwish
20 > hgphab.phabtoken = cli-hahayouwish
21 > EOF
21 > EOF
22 $ VCR="$TESTDIR/phabricator"
22 $ VCR="$TESTDIR/phabricator"
General Comments 0
You need to be logged in to leave comments. Login now