summary refs log tree commit diff
path: root/tests/utils.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2016-09-12 10:46:02 +0100
committerMark Haines <mark.haines@matrix.org>2016-09-12 10:46:02 +0100
commitec609f80949972327274142e4eb5b506f55aba1a (patch)
treec87745ad5255dc595ddc859913b52f13ad57ef06 /tests/utils.py
parentMerge branch 'develop' into markjh/bearer_token (diff)
downloadsynapse-ec609f80949972327274142e4eb5b506f55aba1a.tar.xz
Fix unit tests
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/tests/utils.py b/tests/utils.py
index 915b934e94..1b89470c60 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -115,6 +115,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):
 
@@ -127,7 +136,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:
@@ -155,9 +164,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