esup_signature: add a field to define HTTP headers (#78003)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
0c06086585
commit
b74e848dbd
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 3.2.18 on 2023-05-30 14:07
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('esup_signature', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='esupsignature',
|
||||
name='forced_headers',
|
||||
field=models.TextField(
|
||||
blank=True,
|
||||
help_text='Headers to always add (one per line, format "Header-Name: value")',
|
||||
verbose_name='Headers',
|
||||
),
|
||||
),
|
||||
]
|
|
@ -178,6 +178,11 @@ def to_bool(some_str):
|
|||
|
||||
class EsupSignature(BaseResource, HTTPResource):
|
||||
base_url = models.URLField(_('API URL'))
|
||||
forced_headers = models.TextField(
|
||||
_('Headers'),
|
||||
blank=True,
|
||||
help_text=_('Headers to always add (one per line, format "Header-Name: value")'),
|
||||
)
|
||||
|
||||
category = _('Business Process Connectors')
|
||||
|
||||
|
@ -188,6 +193,16 @@ class EsupSignature(BaseResource, HTTPResource):
|
|||
url = urllib.parse.urljoin(self.base_url, path)
|
||||
kwargs = {}
|
||||
|
||||
headers = {}
|
||||
for header in self.forced_headers.splitlines():
|
||||
header = header.strip()
|
||||
if header.startswith('#'):
|
||||
continue
|
||||
header = header.split(':', 1)
|
||||
if len(header) == 2:
|
||||
headers[header[0].strip()] = header[1].strip()
|
||||
kwargs['headers'] = headers
|
||||
|
||||
if method == 'post':
|
||||
kwargs['params'] = params
|
||||
kwargs['files'] = files
|
||||
|
|
|
@ -139,3 +139,19 @@ def test_get_last_file(app, connector):
|
|||
)
|
||||
resp = app.get('/esup-signature/esup-signature/get-last-file?signrequests_id=1')
|
||||
assert resp.text == 'who hwat'
|
||||
|
||||
|
||||
def test_forced_headers(app, connector):
|
||||
connector.forced_headers = 'X-Foo:bar'
|
||||
connector.save()
|
||||
with responses.RequestsMock() as rsps:
|
||||
headers = {'Content-Type': 'text/plain', 'Content-Disposition': 'attachment; filename=foo.txt'}
|
||||
rsps.get(
|
||||
'https://esup-signature.invalid/ws/signrequests/get-last-file/1',
|
||||
status=200,
|
||||
body='who hwat',
|
||||
headers=headers,
|
||||
)
|
||||
app.get('/esup-signature/esup-signature/get-last-file?signrequests_id=1')
|
||||
headers = rsps.calls[0].request.headers
|
||||
assert headers['X-Foo'] == 'bar'
|
||||
|
|
Loading…
Reference in New Issue