mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 19:31:58 +00:00
Use form POST data for beanstalk and add shim for incorrectly-encoded emails
(imported from commit b5debaa02a6a23c01aee1b2beb6fd83e70e50d65)
This commit is contained in:
@@ -2529,10 +2529,10 @@ class BeanstalkHookTests(AuthedTestCase):
|
|||||||
def send_beanstalk_message(self, action):
|
def send_beanstalk_message(self, action):
|
||||||
email = "hamlet@humbughq.com"
|
email = "hamlet@humbughq.com"
|
||||||
api_key = self.get_api_key(email)
|
api_key = self.get_api_key(email)
|
||||||
|
data = {'payload': self.fixture_jsondata('beanstalk', action)}
|
||||||
return self.send_json_payload(email, "/api/v1/external/beanstalk",
|
return self.send_json_payload(email, "/api/v1/external/beanstalk",
|
||||||
self.fixture_jsondata('beanstalk', action),
|
data,
|
||||||
stream_name="commits",
|
stream_name="commits",
|
||||||
content_type="application/json",
|
|
||||||
HTTP_AUTHORIZATION=self.http_auth(email, api_key))
|
HTTP_AUTHORIZATION=self.http_auth(email, api_key))
|
||||||
|
|
||||||
def test_git_single(self):
|
def test_git_single(self):
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ import requests
|
|||||||
import os
|
import os
|
||||||
import base64
|
import base64
|
||||||
from os import path
|
from os import path
|
||||||
|
from functools import wraps
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from zephyr.lib import bugdown
|
from zephyr.lib import bugdown
|
||||||
|
|
||||||
@@ -1391,10 +1392,29 @@ def api_jira_webhook(request, api_key):
|
|||||||
return json_error(ret)
|
return json_error(ret)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
@authenticated_rest_api_view
|
# Beanstalk's web hook UI rejects url with a @ in the username section of a url
|
||||||
def api_beanstalk_webhook(request, user_profile):
|
# So we ask the user to replace them with %40
|
||||||
payload = simplejson.loads(request.body)
|
# We manually fix the username here before passing it along to @authenticated_rest_api_view
|
||||||
|
def beanstalk_decoder(view_func):
|
||||||
|
@wraps(view_func)
|
||||||
|
def _wrapped_view_func(request, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
auth_type, encoded_value = request.META['HTTP_AUTHORIZATION'].split()
|
||||||
|
if auth_type.lower() == "basic":
|
||||||
|
email, api_key = base64.b64decode(encoded_value).split(":")
|
||||||
|
email = email.replace('%40', '@')
|
||||||
|
request.META['HTTP_AUTHORIZATION'] = "Basic %s" % (base64.b64encode("%s:%s" % (email, api_key)))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return view_func(request, *args, **kwargs)
|
||||||
|
|
||||||
|
return _wrapped_view_func
|
||||||
|
|
||||||
|
@beanstalk_decoder
|
||||||
|
@authenticated_rest_api_view
|
||||||
|
@has_request_variables
|
||||||
|
def api_beanstalk_webhook(request, user_profile, payload=POST(converter=json_to_dict)):
|
||||||
# Beanstalk supports both SVN and git repositories
|
# Beanstalk supports both SVN and git repositories
|
||||||
# We distinguish between the two by checking for a
|
# We distinguish between the two by checking for a
|
||||||
# 'uri' key that is only present for git repos
|
# 'uri' key that is only present for git repos
|
||||||
|
|||||||
Reference in New Issue
Block a user