forked from GithubBackups/healthchecks
Webhook header values can contain variables.
This commit is contained in:
parent
620d8523d7
commit
4cdc7db035
@ -215,6 +215,26 @@ class NotifyTestCase(BaseTestCase):
|
|||||||
mock_request.assert_called_with(
|
mock_request.assert_called_with(
|
||||||
"get", "http://foo.com", headers=headers, timeout=5)
|
"get", "http://foo.com", headers=headers, timeout=5)
|
||||||
|
|
||||||
|
@patch("hc.api.transports.requests.request")
|
||||||
|
def test_webhooks_support_variables_in_headers(self, mock_request):
|
||||||
|
definition = {
|
||||||
|
"url_down": "http://foo.com",
|
||||||
|
"headers": {"X-Message": "$NAME is DOWN"}
|
||||||
|
}
|
||||||
|
|
||||||
|
self._setup_data("webhook", json.dumps(definition))
|
||||||
|
self.check.name = "Foo"
|
||||||
|
self.check.save()
|
||||||
|
|
||||||
|
self.channel.notify(self.check)
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"User-Agent": "healthchecks.io",
|
||||||
|
"X-Message": "Foo is DOWN"
|
||||||
|
}
|
||||||
|
mock_request.assert_called_with(
|
||||||
|
"get", "http://foo.com", headers=headers, timeout=5)
|
||||||
|
|
||||||
def test_email(self):
|
def test_email(self):
|
||||||
self._setup_data("email", "alice@example.org")
|
self._setup_data("email", "alice@example.org")
|
||||||
self.channel.notify(self.check)
|
self.channel.notify(self.check)
|
||||||
|
@ -166,7 +166,10 @@ class Webhook(HttpTransport):
|
|||||||
assert url
|
assert url
|
||||||
|
|
||||||
url = self.prepare(url, check, urlencode=True)
|
url = self.prepare(url, check, urlencode=True)
|
||||||
headers = self.channel.headers
|
headers = {}
|
||||||
|
for key, value in self.channel.headers.items():
|
||||||
|
headers[key] = self.prepare(value, check)
|
||||||
|
|
||||||
if self.channel.post_data:
|
if self.channel.post_data:
|
||||||
payload = self.prepare(self.channel.post_data, check)
|
payload = self.prepare(self.channel.post_data, check)
|
||||||
return self.post(url, data=payload.encode("utf-8"), headers=headers)
|
return self.post(url, data=payload.encode("utf-8"), headers=headers)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user