diff options
author | Erik Johnston <erik@matrix.org> | 2016-10-27 11:02:30 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-10-27 11:02:30 +0100 |
commit | 45bdacd9a75c7e32b0b8708ae58fb9e661376bfd (patch) | |
tree | 0118fd2870598a004d7439f67e21c8651f425643 /tests/utils.py | |
parent | Fixup change log (diff) | |
parent | Merge pull request #1098 from matrix-org/markjh/bearer_token (diff) | |
download | synapse-45bdacd9a75c7e32b0b8708ae58fb9e661376bfd.tar.xz |
Merge branch 'develop' of github.com:matrix-org/synapse into release-v0.18.2
Diffstat (limited to 'tests/utils.py')
-rw-r--r-- | tests/utils.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/tests/utils.py b/tests/utils.py index f74526b6a7..5929f1c729 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -116,6 +116,15 @@ def get_mock_call_args(pattern_func, mock_func): return getcallargs(pattern_func, *invoked_args, **invoked_kargs) +def mock_getRawHeaders(headers=None): + headers = headers if headers is not None else {} + + def getRawHeaders(name, default=None): + return headers.get(name, default) + + return getRawHeaders + + # This is a mock /resource/ not an entire server class MockHttpResource(HttpServer): @@ -128,7 +137,7 @@ class MockHttpResource(HttpServer): @patch('twisted.web.http.Request') @defer.inlineCallbacks - def trigger(self, http_method, path, content, mock_request): + def trigger(self, http_method, path, content, mock_request, federation_auth=False): """ Fire an HTTP event. Args: @@ -156,9 +165,10 @@ class MockHttpResource(HttpServer): mock_request.getClientIP.return_value = "-" - mock_request.requestHeaders.getRawHeaders.return_value = [ - "X-Matrix origin=test,key=,sig=" - ] + headers = {} + if federation_auth: + headers["Authorization"] = ["X-Matrix origin=test,key=,sig="] + mock_request.requestHeaders.getRawHeaders = mock_getRawHeaders(headers) # return the right path if the event requires it mock_request.path = path @@ -189,7 +199,7 @@ class MockHttpResource(HttpServer): ) defer.returnValue((code, response)) except CodeMessageException as e: - defer.returnValue((e.code, cs_error(e.msg))) + defer.returnValue((e.code, cs_error(e.msg, code=e.errcode))) raise KeyError("No event can handle %s" % path) |