diff options
author | Mark Haines <mjark@negativecurvature.net> | 2016-10-25 17:33:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-25 17:33:15 +0100 |
commit | 177f104432b3ab124bb0ae0b7e0e1c2eeae2f492 (patch) | |
tree | 0118fd2870598a004d7439f67e21c8651f425643 /tests/utils.py | |
parent | Merge branch 'release-v0.18.2' of github.com:matrix-org/synapse into develop (diff) | |
parent | Merge branch 'develop' into markjh/bearer_token (diff) | |
download | synapse-177f104432b3ab124bb0ae0b7e0e1c2eeae2f492.tar.xz |
Merge pull request #1098 from matrix-org/markjh/bearer_token
Allow clients to supply access_tokens as headers
Diffstat (limited to 'tests/utils.py')
-rw-r--r-- | tests/utils.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/tests/utils.py b/tests/utils.py index a91d167f90..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 |