mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Saltnado provide also get parameters to the context
This commit is contained in:
parent
98a14f8090
commit
a8dc33a5e3
2 changed files with 38 additions and 1 deletions
|
@ -1612,6 +1612,7 @@ class WebhookSaltAPIHandler(SaltAPIHandler): # pylint: disable=W0223
|
|||
|
||||
ret = self.event.fire_event({
|
||||
'post': self.raw_data,
|
||||
'get': dict(self.request.query_arguments),
|
||||
# In Tornado >= v4.0.3, the headers come
|
||||
# back as an HTTPHeaders instance, which
|
||||
# is a dictionary. We must cast this as
|
||||
|
|
|
@ -36,9 +36,11 @@ except ImportError:
|
|||
pass
|
||||
|
||||
import salt.ext.six as six
|
||||
from salt.ext.six.moves.urllib.parse import urlencode # pylint: disable=no-name-in-module
|
||||
from salt.ext.six.moves.urllib.parse import urlencode, urlparse # pylint: disable=no-name-in-module
|
||||
# pylint: enable=import-error
|
||||
|
||||
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
||||
|
||||
|
||||
@skipIf(HAS_TORNADO is False, 'The tornado package needs to be installed') # pylint: disable=W0223
|
||||
class SaltnadoTestCase(integration.ModuleCase, AsyncHTTPTestCase):
|
||||
|
@ -240,6 +242,40 @@ class TestBaseSaltAPIHandler(SaltnadoTestCase):
|
|||
self.assertEqual(returned_lowstate['arg'], ['10', 'foo'])
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class TestWebhookSaltHandler(SaltnadoTestCase):
|
||||
|
||||
def get_app(self):
|
||||
urls = [
|
||||
(r'/hook(/.*)?', saltnado.WebhookSaltAPIHandler),
|
||||
]
|
||||
return self.build_tornado_app(urls)
|
||||
|
||||
@patch('salt.utils.event.get_event')
|
||||
def test_hook_can_handle_get_parameters(self, get_event):
|
||||
self._app.mod_opts['webhook_disable_auth'] = True
|
||||
event = MagicMock()
|
||||
event.fire_event.return_value = True
|
||||
get_event.return_value = event
|
||||
response = self.fetch('/hook/my_service/?param=1¶m=2',
|
||||
body=json.dumps({}),
|
||||
method='POST',
|
||||
headers={'Content-Type': self.content_type_map['json']})
|
||||
self.assertEqual(response.code, 200, response.body)
|
||||
host = urlparse(response.effective_url).netloc
|
||||
event.fire_event.assert_called_once_with(
|
||||
{'headers': {'Content-Length': '2',
|
||||
'Connection': 'close',
|
||||
'Content-Type': 'application/json',
|
||||
'Host': host,
|
||||
'Accept-Encoding': 'gzip'},
|
||||
'post': {},
|
||||
'get': {'param': ['1', '2']}
|
||||
},
|
||||
'salt/netapi/hook/my_service/',
|
||||
)
|
||||
|
||||
|
||||
class TestSaltAuthHandler(SaltnadoTestCase):
|
||||
|
||||
def get_app(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue