0001-wscall-allow-extra-data-on-POST-6622.patch
tests/test_workflows.py | ||
---|---|---|
400 | 400 |
item.perform(formdata) |
401 | 401 |
assert http_requests.get_last('url') == 'http://remote.example.net' |
402 | 402 |
assert http_requests.get_last('method') == 'POST' |
403 |
payload = json.loads(http_requests.get_last('body')) |
|
404 |
assert payload['url'].startswith('http://example.net/baz-') |
|
405 |
assert int(payload['display_id']) == 1 |
|
403 | 406 | |
404 | 407 |
item = WebserviceCallStatusItem() |
405 | 408 |
item.url = 'http://remote.example.net' |
... | ... | |
411 | 414 |
item = WebserviceCallStatusItem() |
412 | 415 |
item.url = 'http://remote.example.net' |
413 | 416 |
item.post = False |
417 |
item.post_data = {'str': 'abcd', 'one': '=1', |
|
418 |
'evalme': '=form_number', 'error':'=1=3'} |
|
419 |
pub.substitutions.feed(formdata) |
|
420 |
item.perform(formdata) |
|
421 |
assert http_requests.get_last('url') == 'http://remote.example.net' |
|
422 |
assert http_requests.get_last('method') == 'POST' |
|
423 |
payload = json.loads(http_requests.get_last('body')) |
|
424 |
assert payload == {'one': 1, 'str': 'abcd', 'evalme': formdata.id} |
|
425 | ||
426 |
item = WebserviceCallStatusItem() |
|
427 |
item.url = 'http://remote.example.net' |
|
428 |
item.post_data = {'str': 'abcd', 'one': '=1', |
|
429 |
'evalme': '=form_number', 'error':'=1=3'} |
|
430 |
pub.substitutions.feed(formdata) |
|
431 |
item.perform(formdata) |
|
432 |
assert http_requests.get_last('url') == 'http://remote.example.net' |
|
433 |
assert http_requests.get_last('method') == 'POST' |
|
434 |
payload = json.loads(http_requests.get_last('body')) |
|
435 |
assert payload['extra'] == {'one': 1, 'str': 'abcd', 'evalme': formdata.id} |
|
436 |
assert payload['url'].startswith('http://example.net/baz-') |
|
437 |
assert int(payload['display_id']) == 1 |
|
438 | ||
439 |
item = WebserviceCallStatusItem() |
|
440 |
item.url = 'http://remote.example.net' |
|
441 |
item.post = False |
|
414 | 442 |
item.request_signature_key = 'xxx' |
415 | 443 |
item.perform(formdata) |
416 | 444 |
assert 'signature=' in http_requests.get_last('url') |
wcs/wf/wscall.py | ||
---|---|---|
15 | 15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
import json |
18 |
import sys |
|
18 | 19 | |
19 | 20 |
from qommon.form import * |
20 |
from qommon.misc import http_get_page, http_post_request, get_variadic_url |
|
21 |
from qommon.misc import http_get_page, http_post_request, get_variadic_url, JSONEncoder
|
|
21 | 22 |
from wcs.workflows import WorkflowStatusItem, register_item_class, template_on_formdata |
22 | 23 |
from wcs.api import sign_url |
23 | 24 | |
... | ... | |
32 | 33 |
varname = None |
33 | 34 |
post = True |
34 | 35 |
request_signature_key = None |
36 |
post_data = None |
|
35 | 37 | |
36 | 38 |
def get_parameters(self): |
37 |
return ('url', 'post', 'varname', 'request_signature_key') |
|
39 |
return ('url', 'post', 'varname', 'request_signature_key', 'post_data')
|
|
38 | 40 | |
39 | 41 |
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None): |
40 | 42 |
if 'url' in parameters: |
... | ... | |
45 | 47 |
form.add(CheckboxWidget, '%spost' % prefix, |
46 | 48 |
title=_('Post formdata (JSON)'), |
47 | 49 |
value=self.post) |
50 |
if 'post_data' in parameters: |
|
51 |
form.add(WidgetDict, '%spost_data' % prefix, |
|
52 |
title=_('Post data'), |
|
53 |
value=self.post_data or {}) |
|
48 | 54 |
if 'varname' in parameters: |
49 | 55 |
form.add(VarnameWidget, '%svarname' % prefix, |
50 | 56 |
title=_('Variable Name'), value=self.varname) |
51 |
if 'request_signature_key': |
|
57 |
if 'request_signature_key' in parameters:
|
|
52 | 58 |
form.add(StringWidget, '%srequest_signature_key' % prefix, |
53 | 59 |
title=_('Request Signature Key'), |
54 | 60 |
value=self.request_signature_key) |
... | ... | |
69 | 75 | |
70 | 76 |
headers = {'Content-type': 'application/json', |
71 | 77 |
'Accept': 'application/json'} |
78 |
post_data = None # payload |
|
79 | ||
80 |
# if self.post_data exists, post_data is a dict built from it |
|
81 |
if self.post_data: |
|
82 |
post_data = {} |
|
83 |
for (key, value) in self.post_data.items(): |
|
84 |
try: |
|
85 |
post_data[key] = self.compute(value, raises=True) |
|
86 |
except: |
|
87 |
get_publisher().notify_of_exception(sys.exc_info()) |
|
88 | ||
89 |
# if formdata has to be sent, it's the payload. If post_data exists, |
|
90 |
# it's added in formdata['extra'] |
|
72 | 91 |
if self.post: |
73 |
formdata_as_json = formdata.export_to_json() |
|
74 |
response, status, data, auth_header = http_post_request( |
|
75 |
url, formdata_as_json, headers=headers, timeout=TIMEOUT) |
|
92 |
formdata_dict = formdata.get_json_export_dict() |
|
93 |
if post_data is not None: |
|
94 |
formdata_dict['extra'] = post_data |
|
95 |
post_data = formdata_dict |
|
96 | ||
97 |
if post_data is not None: |
|
98 |
post_data = json.dumps(post_data, cls=JSONEncoder, |
|
99 |
encoding=get_publisher().site_charset) |
|
100 |
response, status, data, authheader = http_post_request( |
|
101 |
url, post_data, headers=headers, timeout=TIMEOUT) |
|
76 | 102 |
else: |
77 | 103 |
response, status, data, auth_header = http_get_page( |
78 | 104 |
url, headers=headers, timeout=TIMEOUT) |
105 | ||
79 | 106 |
if self.varname: |
80 | 107 |
workflow_data = {'%s_status' % self.varname: status} |
81 | 108 |
if status == 200: |
wcs/workflows.py | ||
---|---|---|
836 | 836 |
value = getattr(self, '%s_parse' % f)(value) |
837 | 837 |
setattr(self, f, value) |
838 | 838 | |
839 |
def compute(self, var): |
|
839 |
def compute(self, var, raises=False):
|
|
840 | 840 |
if not isinstance(var, basestring): |
841 | 841 |
return var |
842 | 842 |
if not var.startswith('='): |
... | ... | |
845 | 845 |
try: |
846 | 846 |
return eval(var[1:], get_publisher().get_global_eval_dict(), vars) |
847 | 847 |
except: |
848 |
if raises: |
|
849 |
raise |
|
848 | 850 |
return var |
849 | 851 | |
850 | 852 |
def get_substitution_variables(self, formdata): |
851 |
- |