general: add autodiscovery of webservice signature key (#11426)

This commit is contained in:
Frédéric Péters 2016-06-21 08:18:49 +02:00
parent 2dce89362e
commit 12cb4d0b9d
2 changed files with 39 additions and 1 deletions

View File

@ -60,3 +60,31 @@ def test_webservice_substitution_variable(pub):
pub.substitutions.feed(NamedWsCall)
variables = pub.substitutions.get_context_variables()
assert variables['webservice'].hello_world == {'foo': 'bar'}
def test_webservice_auto_sign(pub):
NamedWsCall.wipe()
wscall = NamedWsCall()
wscall.name = 'Hello world'
wscall.request = {'url': 'http://blah.example.net'}
try:
wscall.call()
except:
pass
assert not 'signature=' in http_requests.get_last('url')
wscall.request = {'url': 'http://idp.example.net'}
try:
wscall.call()
except:
pass
assert 'orig=example.net' in http_requests.get_last('url')
assert 'signature=' in http_requests.get_last('url')
wscall.request['request_signature_key'] = 'blah'
try:
wscall.call()
except:
pass
assert not 'orig=example.net' in http_requests.get_last('url')
assert 'signature=' in http_requests.get_last('url')

View File

@ -29,7 +29,7 @@ from qommon.xml_storage import XmlStorableObject
from qommon.form import (CompositeWidget, StringWidget, WidgetDict,
ComputedExpressionWidget, RadiobuttonsWidget, CheckboxWidget)
from wcs.api_utils import sign_url
from wcs.api_utils import sign_url, get_secret_and_orig, MissingSecret
from wcs.workflows import WorkflowStatusItem
TIMEOUT = 30
@ -42,6 +42,16 @@ def call_webservice(url, qs_data=None, request_signature_key=None,
variables = get_publisher().substitutions.get_context_variables()
url = get_variadic_url(url, variables)
if not request_signature_key:
try:
request_signature_key, orig = get_secret_and_orig(url)
except MissingSecret:
pass
else:
if not qs_data:
qs_data = {}
qs_data['orig'] = orig
if qs_data: # merge qs_data into url
publisher = get_publisher()
parsed = urlparse.urlparse(url)