|
@ -8,24 +8,32 @@ class AddWebhookTestCase(BaseTestCase): |
|
|
def test_instructions_work(self): |
|
|
def test_instructions_work(self): |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.get(self.url) |
|
|
r = self.client.get(self.url) |
|
|
self.assertContains(r, "Runs a HTTP GET or HTTP POST") |
|
|
|
|
|
|
|
|
self.assertContains(r, "Executes an HTTP request") |
|
|
|
|
|
|
|
|
def test_it_adds_two_webhook_urls_and_redirects(self): |
|
|
def test_it_adds_two_webhook_urls_and_redirects(self): |
|
|
form = {"url_down": "http://foo.com", "url_up": "https://bar.com"} |
|
|
|
|
|
|
|
|
form = { |
|
|
|
|
|
"method_down": "GET", |
|
|
|
|
|
"url_down": "http://foo.com", |
|
|
|
|
|
"method_up": "GET", |
|
|
|
|
|
"url_up": "https://bar.com", |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.post(self.url, form) |
|
|
r = self.client.post(self.url, form) |
|
|
self.assertRedirects(r, "/integrations/") |
|
|
self.assertRedirects(r, "/integrations/") |
|
|
|
|
|
|
|
|
c = Channel.objects.get() |
|
|
c = Channel.objects.get() |
|
|
self.assertEqual( |
|
|
|
|
|
c.value, |
|
|
|
|
|
'{"headers": {}, "post_data": "", "url_down": "http://foo.com", "url_up": "https://bar.com"}', |
|
|
|
|
|
) |
|
|
|
|
|
self.assertEqual(c.project, self.project) |
|
|
self.assertEqual(c.project, self.project) |
|
|
|
|
|
self.assertEqual(c.down_webhook_spec["url"], "http://foo.com") |
|
|
|
|
|
self.assertEqual(c.up_webhook_spec["url"], "https://bar.com") |
|
|
|
|
|
|
|
|
def test_it_adds_webhook_using_team_access(self): |
|
|
def test_it_adds_webhook_using_team_access(self): |
|
|
form = {"url_down": "http://foo.com", "url_up": "https://bar.com"} |
|
|
|
|
|
|
|
|
form = { |
|
|
|
|
|
"method_down": "GET", |
|
|
|
|
|
"url_down": "http://foo.com", |
|
|
|
|
|
"method_up": "GET", |
|
|
|
|
|
"url_up": "https://bar.com", |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
# Logging in as bob, not alice. Bob has team access so this |
|
|
# Logging in as bob, not alice. Bob has team access so this |
|
|
# should work. |
|
|
# should work. |
|
@ -34,10 +42,8 @@ class AddWebhookTestCase(BaseTestCase): |
|
|
|
|
|
|
|
|
c = Channel.objects.get() |
|
|
c = Channel.objects.get() |
|
|
self.assertEqual(c.project, self.project) |
|
|
self.assertEqual(c.project, self.project) |
|
|
self.assertEqual( |
|
|
|
|
|
c.value, |
|
|
|
|
|
'{"headers": {}, "post_data": "", "url_down": "http://foo.com", "url_up": "https://bar.com"}', |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
self.assertEqual(c.down_webhook_spec["url"], "http://foo.com") |
|
|
|
|
|
self.assertEqual(c.up_webhook_spec["url"], "https://bar.com") |
|
|
|
|
|
|
|
|
def test_it_rejects_bad_urls(self): |
|
|
def test_it_rejects_bad_urls(self): |
|
|
urls = [ |
|
|
urls = [ |
|
@ -52,7 +58,12 @@ class AddWebhookTestCase(BaseTestCase): |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
for url in urls: |
|
|
for url in urls: |
|
|
form = {"url_down": url, "url_up": ""} |
|
|
|
|
|
|
|
|
form = { |
|
|
|
|
|
"method_down": "GET", |
|
|
|
|
|
"url_down": url, |
|
|
|
|
|
"method_up": "GET", |
|
|
|
|
|
"url_up": "", |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
r = self.client.post(self.url, form) |
|
|
r = self.client.post(self.url, form) |
|
|
self.assertContains(r, "Enter a valid URL.", msg_prefix=url) |
|
|
self.assertContains(r, "Enter a valid URL.", msg_prefix=url) |
|
@ -60,35 +71,41 @@ class AddWebhookTestCase(BaseTestCase): |
|
|
self.assertEqual(Channel.objects.count(), 0) |
|
|
self.assertEqual(Channel.objects.count(), 0) |
|
|
|
|
|
|
|
|
def test_it_handles_empty_down_url(self): |
|
|
def test_it_handles_empty_down_url(self): |
|
|
form = {"url_down": "", "url_up": "http://foo.com"} |
|
|
|
|
|
|
|
|
form = { |
|
|
|
|
|
"method_down": "GET", |
|
|
|
|
|
"url_down": "", |
|
|
|
|
|
"method_up": "GET", |
|
|
|
|
|
"url_up": "http://foo.com", |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.post(self.url, form) |
|
|
self.client.post(self.url, form) |
|
|
|
|
|
|
|
|
c = Channel.objects.get() |
|
|
c = Channel.objects.get() |
|
|
self.assertEqual( |
|
|
|
|
|
c.value, |
|
|
|
|
|
'{"headers": {}, "post_data": "", "url_down": "", "url_up": "http://foo.com"}', |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
self.assertEqual(c.down_webhook_spec["url"], "") |
|
|
|
|
|
self.assertEqual(c.up_webhook_spec["url"], "http://foo.com") |
|
|
|
|
|
|
|
|
def test_it_adds_post_data(self): |
|
|
|
|
|
form = {"url_down": "http://foo.com", "post_data": "hello"} |
|
|
|
|
|
|
|
|
def test_it_adds_request_body(self): |
|
|
|
|
|
form = { |
|
|
|
|
|
"method_down": "POST", |
|
|
|
|
|
"url_down": "http://foo.com", |
|
|
|
|
|
"body_down": "hello", |
|
|
|
|
|
"method_up": "GET", |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
r = self.client.post(self.url, form) |
|
|
r = self.client.post(self.url, form) |
|
|
self.assertRedirects(r, "/integrations/") |
|
|
self.assertRedirects(r, "/integrations/") |
|
|
|
|
|
|
|
|
c = Channel.objects.get() |
|
|
c = Channel.objects.get() |
|
|
self.assertEqual( |
|
|
|
|
|
c.value, |
|
|
|
|
|
'{"headers": {}, "post_data": "hello", "url_down": "http://foo.com", "url_up": ""}', |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
self.assertEqual(c.down_webhook_spec["body"], "hello") |
|
|
|
|
|
|
|
|
def test_it_adds_headers(self): |
|
|
def test_it_adds_headers(self): |
|
|
form = { |
|
|
form = { |
|
|
|
|
|
"method_down": "GET", |
|
|
"url_down": "http://foo.com", |
|
|
"url_down": "http://foo.com", |
|
|
"header_key[]": ["test", "test2"], |
|
|
|
|
|
"header_value[]": ["123", "abc"], |
|
|
|
|
|
|
|
|
"headers_down": "test:123\ntest2:abc", |
|
|
|
|
|
"method_up": "GET", |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
@ -96,16 +113,34 @@ class AddWebhookTestCase(BaseTestCase): |
|
|
self.assertRedirects(r, "/integrations/") |
|
|
self.assertRedirects(r, "/integrations/") |
|
|
|
|
|
|
|
|
c = Channel.objects.get() |
|
|
c = Channel.objects.get() |
|
|
self.assertEqual(c.headers, {"test": "123", "test2": "abc"}) |
|
|
|
|
|
|
|
|
self.assertEqual( |
|
|
|
|
|
c.down_webhook_spec["headers"], {"test": "123", "test2": "abc"} |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
def test_it_rejects_bad_header_names(self): |
|
|
|
|
|
|
|
|
def test_it_rejects_bad_headers(self): |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
self.client.login(username="[email protected]", password="password") |
|
|
form = { |
|
|
form = { |
|
|
|
|
|
"method_down": "GET", |
|
|
"url_down": "http://example.org", |
|
|
"url_down": "http://example.org", |
|
|
"header_key[]": ["ill:egal"], |
|
|
|
|
|
"header_value[]": ["123"], |
|
|
|
|
|
|
|
|
"headers_down": "invalid-headers", |
|
|
|
|
|
"method_up": "GET", |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
r = self.client.post(self.url, form) |
|
|
r = self.client.post(self.url, form) |
|
|
self.assertContains(r, "Please use valid HTTP header names.") |
|
|
|
|
|
|
|
|
self.assertContains(r, """invalid-headers""") |
|
|
self.assertEqual(Channel.objects.count(), 0) |
|
|
self.assertEqual(Channel.objects.count(), 0) |
|
|
|
|
|
|
|
|
|
|
|
def test_it_strips_headers(self): |
|
|
|
|
|
form = { |
|
|
|
|
|
"method_down": "GET", |
|
|
|
|
|
"url_down": "http://foo.com", |
|
|
|
|
|
"headers_down": " test : 123 ", |
|
|
|
|
|
"method_up": "GET", |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self.client.login(username="[email protected]", password="password") |
|
|
|
|
|
r = self.client.post(self.url, form) |
|
|
|
|
|
self.assertRedirects(r, "/integrations/") |
|
|
|
|
|
|
|
|
|
|
|
c = Channel.objects.get() |
|
|
|
|
|
self.assertEqual(c.down_webhook_spec["headers"], {"test": "123"}) |