summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/federation/test_federation.py27
-rw-r--r--tests/federation/test_pdu_codec.py4
-rw-r--r--tests/handlers/test_directory.py5
-rw-r--r--tests/handlers/test_federation.py13
-rw-r--r--tests/handlers/test_presence.py55
-rw-r--r--tests/handlers/test_room.py5
-rw-r--r--tests/handlers/test_typing.py14
-rw-r--r--tests/rest/test_presence.py29
-rw-r--r--tests/rest/test_profile.py4
-rw-r--r--tests/rest/test_rooms.py41
-rw-r--r--tests/storage/test_directory.py25
-rw-r--r--tests/storage/test_registration.py4
-rw-r--r--tests/test_state.py2
-rw-r--r--tests/utils.py31
14 files changed, 197 insertions, 62 deletions
diff --git a/tests/federation/test_federation.py b/tests/federation/test_federation.py
index bb17e9aafe..933aa61c77 100644
--- a/tests/federation/test_federation.py
+++ b/tests/federation/test_federation.py
@@ -19,7 +19,7 @@ from tests import unittest
 # python imports
 from mock import Mock, ANY
 
-from ..utils import MockHttpResource, MockClock
+from ..utils import MockHttpResource, MockClock, MockKey
 
 from synapse.server import HomeServer
 from synapse.federation import initialize_http_replication
@@ -64,6 +64,8 @@ class FederationTestCase(unittest.TestCase):
         self.mock_persistence.get_received_txn_response.return_value = (
                 defer.succeed(None)
         )
+        self.mock_config = Mock()
+        self.mock_config.signing_key = [MockKey()]
         self.clock = MockClock()
         hs = HomeServer("test",
                 resource_for_federation=self.mock_resource,
@@ -71,6 +73,8 @@ class FederationTestCase(unittest.TestCase):
                 db_pool=None,
                 datastore=self.mock_persistence,
                 clock=self.clock,
+                config=self.mock_config,
+                keyring=Mock(),
         )
         self.federation = initialize_http_replication(hs)
         self.distributor = hs.get_distributor()
@@ -154,7 +158,7 @@ class FederationTestCase(unittest.TestCase):
                 origin="red",
                 destinations=["remote"],
                 context="my-context",
-                ts=123456789002,
+                origin_server_ts=123456789002,
                 pdu_type="m.test",
                 content={"testing": "content here"},
                 depth=1,
@@ -166,14 +170,14 @@ class FederationTestCase(unittest.TestCase):
                 "remote",
                 path="/_matrix/federation/v1/send/1000000/",
                 data={
-                    "ts": 1000000,
+                    "origin_server_ts": 1000000,
                     "origin": "test",
                     "pdus": [
                         {
                             "origin": "red",
                             "pdu_id": "abc123def456",
                             "prev_pdus": [],
-                            "ts": 123456789002,
+                            "origin_server_ts": 123456789002,
                             "context": "my-context",
                             "pdu_type": "m.test",
                             "is_state": False,
@@ -182,7 +186,7 @@ class FederationTestCase(unittest.TestCase):
                         },
                     ]
                 },
-                on_send_callback=ANY,
+                json_data_callback=ANY,
         )
 
     @defer.inlineCallbacks
@@ -203,10 +207,11 @@ class FederationTestCase(unittest.TestCase):
                 path="/_matrix/federation/v1/send/1000000/",
                 data={
                     "origin": "test",
-                    "ts": 1000000,
+                    "origin_server_ts": 1000000,
                     "pdus": [],
                     "edus": [
                         {
+                            # TODO: SYN-103: Remove "origin" and "destination"
                             "origin": "test",
                             "destination": "remote",
                             "edu_type": "m.test",
@@ -214,9 +219,10 @@ class FederationTestCase(unittest.TestCase):
                         }
                     ],
                 },
-                on_send_callback=ANY,
+                json_data_callback=ANY,
         )
 
+
     @defer.inlineCallbacks
     def test_recv_edu(self):
         recv_observer = Mock()
@@ -228,7 +234,7 @@ class FederationTestCase(unittest.TestCase):
                 "/_matrix/federation/v1/send/1001000/",
                 """{
                     "origin": "remote",
-                    "ts": 1001000,
+                    "origin_server_ts": 1001000,
                     "pdus": [],
                     "edus": [
                         {
@@ -253,7 +259,7 @@ class FederationTestCase(unittest.TestCase):
         response = yield self.federation.make_query(
             destination="remote",
             query_type="a-question",
-            args={"one": "1", "two": "2"}
+            args={"one": "1", "two": "2"},
         )
 
         self.assertEquals({"your": "response"}, response)
@@ -261,7 +267,8 @@ class FederationTestCase(unittest.TestCase):
         self.mock_http_client.get_json.assert_called_with(
             destination="remote",
             path="/_matrix/federation/v1/query/a-question",
-            args={"one": "1", "two": "2"}
+            args={"one": "1", "two": "2"},
+            retry_on_dns_fail=True,
         )
 
     @defer.inlineCallbacks
diff --git a/tests/federation/test_pdu_codec.py b/tests/federation/test_pdu_codec.py
index 344e1baf60..0754ef92e8 100644
--- a/tests/federation/test_pdu_codec.py
+++ b/tests/federation/test_pdu_codec.py
@@ -68,7 +68,7 @@ class PduCodecTestCase(unittest.TestCase):
             context="rooooom",
             pdu_type="m.room.message",
             origin="bar.com",
-            ts=12345,
+            origin_server_ts=12345,
             depth=5,
             prev_pdus=[("alice", "bob.com")],
             is_state=False,
@@ -123,7 +123,7 @@ class PduCodecTestCase(unittest.TestCase):
             context="rooooom",
             pdu_type="m.room.topic",
             origin="bar.com",
-            ts=12345,
+            origin_server_ts=12345,
             depth=5,
             prev_pdus=[("alice", "bob.com")],
             is_state=True,
diff --git a/tests/handlers/test_directory.py b/tests/handlers/test_directory.py
index dd5d85dde6..e10a49a8ac 100644
--- a/tests/handlers/test_directory.py
+++ b/tests/handlers/test_directory.py
@@ -20,7 +20,6 @@ from twisted.internet import defer
 from mock import Mock
 
 from synapse.server import HomeServer
-from synapse.http.client import HttpClient
 from synapse.handlers.directory import DirectoryHandler
 from synapse.storage.directory import RoomAliasMapping
 
@@ -95,8 +94,8 @@ class DirectoryTestCase(unittest.TestCase):
             query_type="directory",
             args={
                 "room_alias": "#another:remote",
-                HttpClient.RETRY_DNS_LOOKUP_FAILURES: False
-            }
+            },
+            retry_on_dns_fail=False,
         )
 
     @defer.inlineCallbacks
diff --git a/tests/handlers/test_federation.py b/tests/handlers/test_federation.py
index 7208afdb3b..219b2c4c5e 100644
--- a/tests/handlers/test_federation.py
+++ b/tests/handlers/test_federation.py
@@ -26,12 +26,16 @@ from synapse.federation.units import Pdu
 
 from mock import NonCallableMock, ANY
 
-from ..utils import get_mock_call_args
+from ..utils import get_mock_call_args, MockKey
 
 
 class FederationTestCase(unittest.TestCase):
 
     def setUp(self):
+
+        self.mock_config = NonCallableMock()
+        self.mock_config.signing_key = [MockKey()]
+
         self.hostname = "test"
         hs = HomeServer(
             self.hostname,
@@ -48,6 +52,7 @@ class FederationTestCase(unittest.TestCase):
                 "room_member_handler",
                 "federation_handler",
             ]),
+            config=self.mock_config,
         )
 
         self.datastore = hs.get_datastore()
@@ -63,7 +68,7 @@ class FederationTestCase(unittest.TestCase):
             pdu_type=MessageEvent.TYPE,
             context="foo",
             content={"msgtype": u"fooo"},
-            ts=0,
+            origin_server_ts=0,
             pdu_id="a",
             origin="b",
         )
@@ -90,7 +95,7 @@ class FederationTestCase(unittest.TestCase):
             target_host=self.hostname,
             context=room_id,
             content={},
-            ts=0,
+            origin_server_ts=0,
             pdu_id="a",
             origin="b",
         )
@@ -122,7 +127,7 @@ class FederationTestCase(unittest.TestCase):
             state_key="@red:not%s" % self.hostname,
             context=room_id,
             content={},
-            ts=0,
+            origin_server_ts=0,
             pdu_id="a",
             origin="b",
         )
diff --git a/tests/handlers/test_presence.py b/tests/handlers/test_presence.py
index 765929d204..1850deacf5 100644
--- a/tests/handlers/test_presence.py
+++ b/tests/handlers/test_presence.py
@@ -17,11 +17,12 @@
 from tests import unittest
 from twisted.internet import defer, reactor
 
-from mock import Mock, call, ANY
+from mock import Mock, call, ANY, NonCallableMock, patch
 import json
 
 from tests.utils import (
-    MockHttpResource, MockClock, DeferredMockCallable, SQLiteMemoryDbPool
+    MockHttpResource, MockClock, DeferredMockCallable, SQLiteMemoryDbPool,
+    MockKey
 )
 
 from synapse.server import HomeServer
@@ -38,10 +39,11 @@ ONLINE = PresenceState.ONLINE
 def _expect_edu(destination, edu_type, content, origin="test"):
     return {
         "origin": origin,
-        "ts": 1000000,
+        "origin_server_ts": 1000000,
         "pdus": [],
         "edus": [
             {
+                # TODO: SYN-103: Remove "origin" and "destination" keys.
                 "origin": origin,
                 "destination": destination,
                 "edu_type": edu_type,
@@ -58,7 +60,6 @@ class JustPresenceHandlers(object):
     def __init__(self, hs):
         self.presence_handler = PresenceHandler(hs)
 
-
 class PresenceStateTestCase(unittest.TestCase):
     """ Tests presence management. """
 
@@ -67,12 +68,17 @@ class PresenceStateTestCase(unittest.TestCase):
         db_pool = SQLiteMemoryDbPool()
         yield db_pool.prepare()
 
+        self.mock_config = NonCallableMock()
+        self.mock_config.signing_key = [MockKey()]
+
         hs = HomeServer("test",
             clock=MockClock(),
             db_pool=db_pool,
             handlers=None,
             resource_for_federation=Mock(),
             http_client=None,
+            config=self.mock_config,
+            keyring=Mock(),
         )
         hs.handlers = JustPresenceHandlers(hs)
 
@@ -214,6 +220,9 @@ class PresenceInvitesTestCase(unittest.TestCase):
         db_pool = SQLiteMemoryDbPool()
         yield db_pool.prepare()
 
+        self.mock_config = NonCallableMock()
+        self.mock_config.signing_key = [MockKey()]
+
         hs = HomeServer("test",
             clock=MockClock(),
             db_pool=db_pool,
@@ -221,6 +230,8 @@ class PresenceInvitesTestCase(unittest.TestCase):
             resource_for_client=Mock(),
             resource_for_federation=self.mock_federation_resource,
             http_client=self.mock_http_client,
+            config=self.mock_config,
+            keyring=Mock(),
         )
         hs.handlers = JustPresenceHandlers(hs)
 
@@ -290,7 +301,7 @@ class PresenceInvitesTestCase(unittest.TestCase):
                         "observed_user": "@cabbage:elsewhere",
                     }
                 ),
-                on_send_callback=ANY,
+                json_data_callback=ANY,
             ),
             defer.succeed((200, "OK"))
         )
@@ -319,7 +330,7 @@ class PresenceInvitesTestCase(unittest.TestCase):
                         "observed_user": "@apple:test",
                     }
                 ),
-                on_send_callback=ANY,
+                json_data_callback=ANY,
             ),
             defer.succeed((200, "OK"))
         )
@@ -355,7 +366,7 @@ class PresenceInvitesTestCase(unittest.TestCase):
                         "observed_user": "@durian:test",
                     }
                 ),
-                on_send_callback=ANY,
+                json_data_callback=ANY,
             ),
             defer.succeed((200, "OK"))
         )
@@ -503,6 +514,9 @@ class PresencePushTestCase(unittest.TestCase):
 
         self.mock_federation_resource = MockHttpResource()
 
+        self.mock_config = NonCallableMock()
+        self.mock_config.signing_key = [MockKey()]
+
         hs = HomeServer("test",
                 clock=self.clock,
                 db_pool=None,
@@ -520,6 +534,8 @@ class PresencePushTestCase(unittest.TestCase):
                 resource_for_client=Mock(),
                 resource_for_federation=self.mock_federation_resource,
                 http_client=self.mock_http_client,
+                config=self.mock_config,
+                keyring=Mock(),
             )
         hs.handlers = JustPresenceHandlers(hs)
 
@@ -771,7 +787,7 @@ class PresencePushTestCase(unittest.TestCase):
                         ],
                     }
                 ),
-                on_send_callback=ANY,
+                json_data_callback=ANY,
             ),
             defer.succeed((200, "OK"))
         )
@@ -787,7 +803,7 @@ class PresencePushTestCase(unittest.TestCase):
                         ],
                     }
                 ),
-                on_send_callback=ANY,
+                json_data_callback=ANY,
             ),
             defer.succeed((200, "OK"))
         )
@@ -913,7 +929,7 @@ class PresencePushTestCase(unittest.TestCase):
                         ],
                     }
                 ),
-                on_send_callback=ANY,
+                json_data_callback=ANY,
             ),
             defer.succeed((200, "OK"))
         )
@@ -928,7 +944,7 @@ class PresencePushTestCase(unittest.TestCase):
                         ],
                     }
                 ),
-                on_send_callback=ANY,
+                json_data_callback=ANY,
             ),
             defer.succeed((200, "OK"))
         )
@@ -958,7 +974,7 @@ class PresencePushTestCase(unittest.TestCase):
                         ],
                     }
                 ),
-                on_send_callback=ANY,
+                json_data_callback=ANY,
             ),
             defer.succeed((200, "OK"))
         )
@@ -995,6 +1011,9 @@ class PresencePollingTestCase(unittest.TestCase):
 
         self.mock_federation_resource = MockHttpResource()
 
+        self.mock_config = NonCallableMock()
+        self.mock_config.signing_key = [MockKey()]
+
         hs = HomeServer("test",
                 clock=MockClock(),
                 db_pool=None,
@@ -1009,6 +1028,8 @@ class PresencePollingTestCase(unittest.TestCase):
                 resource_for_client=Mock(),
                 resource_for_federation=self.mock_federation_resource,
                 http_client=self.mock_http_client,
+                config=self.mock_config,
+                keyring=Mock(),
             )
         hs.handlers = JustPresenceHandlers(hs)
 
@@ -1155,7 +1176,7 @@ class PresencePollingTestCase(unittest.TestCase):
                         "poll": [ "@potato:remote" ],
                     },
                 ),
-                on_send_callback=ANY,
+                json_data_callback=ANY,
             ),
             defer.succeed((200, "OK"))
         )
@@ -1168,7 +1189,7 @@ class PresencePollingTestCase(unittest.TestCase):
                         "push": [ {"user_id": "@clementine:test" }],
                     },
                 ),
-                on_send_callback=ANY,
+                json_data_callback=ANY,
             ),
             defer.succeed((200, "OK"))
         )
@@ -1197,7 +1218,7 @@ class PresencePollingTestCase(unittest.TestCase):
                         "push": [ {"user_id": "@fig:test" }],
                     },
                 ),
-                on_send_callback=ANY,
+                json_data_callback=ANY,
             ),
             defer.succeed((200, "OK"))
         )
@@ -1230,7 +1251,7 @@ class PresencePollingTestCase(unittest.TestCase):
                         "unpoll": [ "@potato:remote" ],
                     },
                 ),
-                on_send_callback=ANY,
+                json_data_callback=ANY,
             ),
             defer.succeed((200, "OK"))
         )
@@ -1262,7 +1283,7 @@ class PresencePollingTestCase(unittest.TestCase):
                         ],
                     },
                 ),
-                on_send_callback=ANY,
+                json_data_callback=ANY,
             ),
             defer.succeed((200, "OK"))
         )
diff --git a/tests/handlers/test_room.py b/tests/handlers/test_room.py
index a1a2e80492..c88d1c8840 100644
--- a/tests/handlers/test_room.py
+++ b/tests/handlers/test_room.py
@@ -24,6 +24,7 @@ from synapse.api.constants import Membership
 from synapse.handlers.room import RoomMemberHandler, RoomCreationHandler
 from synapse.handlers.profile import ProfileHandler
 from synapse.server import HomeServer
+from ..utils import MockKey
 
 from mock import Mock, NonCallableMock
 
@@ -31,6 +32,8 @@ from mock import Mock, NonCallableMock
 class RoomMemberHandlerTestCase(unittest.TestCase):
 
     def setUp(self):
+        self.mock_config = NonCallableMock()
+        self.mock_config.signing_key = [MockKey()]
         self.hostname = "red"
         hs = HomeServer(
             self.hostname,
@@ -38,7 +41,6 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
             ratelimiter=NonCallableMock(spec_set=[
                 "send_message",
             ]),
-            config=NonCallableMock(),
             datastore=NonCallableMock(spec_set=[
                 "persist_event",
                 "get_joined_hosts_for_room",
@@ -57,6 +59,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
             ]),
             auth=NonCallableMock(spec_set=["check"]),
             state_handler=NonCallableMock(spec_set=["handle_new_event"]),
+            config=self.mock_config,
         )
 
         self.federation = NonCallableMock(spec_set=[
diff --git a/tests/handlers/test_typing.py b/tests/handlers/test_typing.py
index a66f208abf..f1d3b27f74 100644
--- a/tests/handlers/test_typing.py
+++ b/tests/handlers/test_typing.py
@@ -20,7 +20,7 @@ from twisted.internet import defer
 from mock import Mock, call, ANY
 import json
 
-from ..utils import MockHttpResource, MockClock, DeferredMockCallable
+from ..utils import MockHttpResource, MockClock, DeferredMockCallable, MockKey
 
 from synapse.server import HomeServer
 from synapse.handlers.typing import TypingNotificationHandler
@@ -29,10 +29,11 @@ from synapse.handlers.typing import TypingNotificationHandler
 def _expect_edu(destination, edu_type, content, origin="test"):
     return {
         "origin": origin,
-        "ts": 1000000,
+        "origin_server_ts": 1000000,
         "pdus": [],
         "edus": [
             {
+                # TODO: SYN-103: Remove "origin" and "destination" keys.
                 "origin": origin,
                 "destination": destination,
                 "edu_type": edu_type,
@@ -61,6 +62,9 @@ class TypingNotificationsTestCase(unittest.TestCase):
 
         self.mock_federation_resource = MockHttpResource()
 
+        self.mock_config = Mock()
+        self.mock_config.signing_key = [MockKey()]
+
         hs = HomeServer("test",
                 clock=self.clock,
                 db_pool=None,
@@ -75,6 +79,8 @@ class TypingNotificationsTestCase(unittest.TestCase):
                 resource_for_client=Mock(),
                 resource_for_federation=self.mock_federation_resource,
                 http_client=self.mock_http_client,
+                config=self.mock_config,
+                keyring=Mock(),
             )
         hs.handlers = JustTypingNotificationHandlers(hs)
 
@@ -170,7 +176,7 @@ class TypingNotificationsTestCase(unittest.TestCase):
                         "typing": True,
                     }
                 ),
-                on_send_callback=ANY,
+                json_data_callback=ANY,
             ),
             defer.succeed((200, "OK"))
         )
@@ -221,7 +227,7 @@ class TypingNotificationsTestCase(unittest.TestCase):
                         "typing": False,
                     }
                 ),
-                on_send_callback=ANY,
+                json_data_callback=ANY,
             ),
             defer.succeed((200, "OK"))
         )
diff --git a/tests/rest/test_presence.py b/tests/rest/test_presence.py
index ea3478ac5d..769c7824bc 100644
--- a/tests/rest/test_presence.py
+++ b/tests/rest/test_presence.py
@@ -20,7 +20,7 @@ from twisted.internet import defer
 
 from mock import Mock
 
-from ..utils import MockHttpResource
+from ..utils import MockHttpResource, MockKey
 
 from synapse.api.constants import PresenceState
 from synapse.handlers.presence import PresenceHandler
@@ -45,16 +45,19 @@ class PresenceStateTestCase(unittest.TestCase):
 
     def setUp(self):
         self.mock_resource = MockHttpResource(prefix=PATH_PREFIX)
-
+        self.mock_config = Mock()
+        self.mock_config.signing_key = [MockKey()]
         hs = HomeServer("test",
             db_pool=None,
             datastore=Mock(spec=[
                 "get_presence_state",
                 "set_presence_state",
+                "insert_client_ip",
             ]),
             http_client=None,
             resource_for_client=self.mock_resource,
             resource_for_federation=self.mock_resource,
+            config=self.mock_config,
         )
         hs.handlers = JustPresenceHandlers(hs)
 
@@ -65,7 +68,11 @@ class PresenceStateTestCase(unittest.TestCase):
         self.datastore.get_presence_list = get_presence_list
 
         def _get_user_by_token(token=None):
-            return hs.parse_userid(myid)
+            return {
+                "user": hs.parse_userid(myid),
+                "admin": False,
+                "device_id": None,
+            }
 
         hs.get_auth().get_user_by_token = _get_user_by_token
 
@@ -119,6 +126,8 @@ class PresenceListTestCase(unittest.TestCase):
 
     def setUp(self):
         self.mock_resource = MockHttpResource(prefix=PATH_PREFIX)
+        self.mock_config = Mock()
+        self.mock_config.signing_key = [MockKey()]
 
         hs = HomeServer("test",
             db_pool=None,
@@ -131,10 +140,12 @@ class PresenceListTestCase(unittest.TestCase):
                 "set_presence_list_accepted",
                 "del_presence_list",
                 "get_presence_list",
+                "insert_client_ip",
             ]),
             http_client=None,
             resource_for_client=self.mock_resource,
-            resource_for_federation=self.mock_resource
+            resource_for_federation=self.mock_resource,
+            config=self.mock_config,
         )
         hs.handlers = JustPresenceHandlers(hs)
 
@@ -147,7 +158,11 @@ class PresenceListTestCase(unittest.TestCase):
         self.datastore.has_presence_state = has_presence_state
 
         def _get_user_by_token(token=None):
-            return hs.parse_userid(myid)
+            return {
+                "user": hs.parse_userid(myid),
+                "admin": False,
+                "device_id": None,
+            }
 
         room_member_handler = hs.handlers.room_member_handler = Mock(
             spec=[
@@ -225,6 +240,9 @@ class PresenceEventStreamTestCase(unittest.TestCase):
     def setUp(self):
         self.mock_resource = MockHttpResource(prefix=PATH_PREFIX)
 
+        self.mock_config = Mock()
+        self.mock_config.signing_key = [MockKey()]
+
         # HIDEOUS HACKERY
         # TODO(paul): This should be injected in via the HomeServer DI system
         from synapse.streams.events import (
@@ -255,6 +273,7 @@ class PresenceEventStreamTestCase(unittest.TestCase):
                 "cancel_call_later",
                 "time_msec",
             ]),
+            config=self.mock_config,
         )
 
         hs.get_clock().time_msec.return_value = 1000000
diff --git a/tests/rest/test_profile.py b/tests/rest/test_profile.py
index e6e51f6dd0..b0f48e7fd8 100644
--- a/tests/rest/test_profile.py
+++ b/tests/rest/test_profile.py
@@ -50,10 +50,10 @@ class ProfileTestCase(unittest.TestCase):
             datastore=None,
         )
 
-        def _get_user_by_token(token=None):
+        def _get_user_by_req(request=None):
             return hs.parse_userid(myid)
 
-        hs.get_auth().get_user_by_token = _get_user_by_token
+        hs.get_auth().get_user_by_req = _get_user_by_req
 
         hs.get_handlers().profile_handler = self.mock_handler
 
diff --git a/tests/rest/test_rooms.py b/tests/rest/test_rooms.py
index 4ea5828d4f..1ce9b8a83d 100644
--- a/tests/rest/test_rooms.py
+++ b/tests/rest/test_rooms.py
@@ -69,7 +69,11 @@ class RoomPermissionsTestCase(RestTestCase):
         hs.get_handlers().federation_handler = Mock()
 
         def _get_user_by_token(token=None):
-            return hs.parse_userid(self.auth_user_id)
+            return {
+                "user": hs.parse_userid(self.auth_user_id),
+                "admin": False,
+                "device_id": None,
+            }
         hs.get_auth().get_user_by_token = _get_user_by_token
 
         self.auth_user_id = self.rmcreator_id
@@ -425,7 +429,11 @@ class RoomsMemberListTestCase(RestTestCase):
         self.auth_user_id = self.user_id
 
         def _get_user_by_token(token=None):
-            return hs.parse_userid(self.auth_user_id)
+            return {
+                "user": hs.parse_userid(self.auth_user_id),
+                "admin": False,
+                "device_id": None,
+            }
         hs.get_auth().get_user_by_token = _get_user_by_token
 
         synapse.rest.room.register_servlets(hs, self.mock_resource)
@@ -508,7 +516,11 @@ class RoomsCreateTestCase(RestTestCase):
         hs.get_handlers().federation_handler = Mock()
 
         def _get_user_by_token(token=None):
-            return hs.parse_userid(self.auth_user_id)
+            return {
+                "user": hs.parse_userid(self.auth_user_id),
+                "admin": False,
+                "device_id": None,
+            }
         hs.get_auth().get_user_by_token = _get_user_by_token
 
         synapse.rest.room.register_servlets(hs, self.mock_resource)
@@ -605,7 +617,11 @@ class RoomTopicTestCase(RestTestCase):
         hs.get_handlers().federation_handler = Mock()
 
         def _get_user_by_token(token=None):
-            return hs.parse_userid(self.auth_user_id)
+            return {
+                "user": hs.parse_userid(self.auth_user_id),
+                "admin": False,
+                "device_id": None,
+            }
         hs.get_auth().get_user_by_token = _get_user_by_token
 
         synapse.rest.room.register_servlets(hs, self.mock_resource)
@@ -715,7 +731,16 @@ class RoomMemberStateTestCase(RestTestCase):
         hs.get_handlers().federation_handler = Mock()
 
         def _get_user_by_token(token=None):
-            return hs.parse_userid(self.auth_user_id)
+            return {
+                "user": hs.parse_userid(self.auth_user_id),
+                "admin": False,
+                "device_id": None,
+            }
+            return {
+                "user": hs.parse_userid(self.auth_user_id),
+                "admin": False,
+                "device_id": None,
+            }
         hs.get_auth().get_user_by_token = _get_user_by_token
 
         synapse.rest.room.register_servlets(hs, self.mock_resource)
@@ -847,7 +872,11 @@ class RoomMessagesTestCase(RestTestCase):
         hs.get_handlers().federation_handler = Mock()
 
         def _get_user_by_token(token=None):
-            return hs.parse_userid(self.auth_user_id)
+            return {
+                "user": hs.parse_userid(self.auth_user_id),
+                "admin": False,
+                "device_id": None,
+            }
         hs.get_auth().get_user_by_token = _get_user_by_token
 
         synapse.rest.room.register_servlets(hs, self.mock_resource)
diff --git a/tests/storage/test_directory.py b/tests/storage/test_directory.py
index 7e8e7e1e83..e9c242cc07 100644
--- a/tests/storage/test_directory.py
+++ b/tests/storage/test_directory.py
@@ -30,7 +30,8 @@ class DirectoryStoreTestCase(unittest.TestCase):
         db_pool = SQLiteMemoryDbPool()
         yield db_pool.prepare()
 
-        hs = HomeServer("test",
+        hs = HomeServer(
+            "test",
             db_pool=db_pool,
         )
 
@@ -60,9 +61,25 @@ class DirectoryStoreTestCase(unittest.TestCase):
             servers=["test"],
         )
 
-
         self.assertObjectHasAttributes(
-            {"room_id": self.room.to_string(),
-             "servers": ["test"]},
+            {
+                "room_id": self.room.to_string(),
+                "servers": ["test"],
+            },
+            (yield self.store.get_association_from_room_alias(self.alias))
+        )
+
+    @defer.inlineCallbacks
+    def test_delete_alias(self):
+        yield self.store.create_room_alias_association(
+            room_alias=self.alias,
+            room_id=self.room.to_string(),
+            servers=["test"],
+        )
+
+        room_id = yield self.store.delete_room_alias(self.alias)
+        self.assertEqual(self.room.to_string(), room_id)
+
+        self.assertIsNone(
             (yield self.store.get_association_from_room_alias(self.alias))
         )
diff --git a/tests/storage/test_registration.py b/tests/storage/test_registration.py
index 91e221d53e..84bfde7568 100644
--- a/tests/storage/test_registration.py
+++ b/tests/storage/test_registration.py
@@ -53,7 +53,7 @@ class RegistrationStoreTestCase(unittest.TestCase):
         )
 
         self.assertEquals(
-            self.user_id,
+            {"admin": 0, "device_id": None, "name": self.user_id},
             (yield self.store.get_user_by_token(self.tokens[0]))
         )
 
@@ -63,7 +63,7 @@ class RegistrationStoreTestCase(unittest.TestCase):
         yield self.store.add_access_token_to_user(self.user_id, self.tokens[1])
 
         self.assertEquals(
-            self.user_id,
+            {"admin": 0, "device_id": None, "name": self.user_id},
             (yield self.store.get_user_by_token(self.tokens[1]))
         )
 
diff --git a/tests/test_state.py b/tests/test_state.py
index b1624f0b25..4b1feaf410 100644
--- a/tests/test_state.py
+++ b/tests/test_state.py
@@ -599,7 +599,7 @@ def new_fake_pdu(pdu_id, context, pdu_type, state_key, prev_state_id,
         prev_state_id=prev_state_id,
         origin="example.com",
         context="context",
-        ts=1405353060021,
+        origin_server_ts=1405353060021,
         depth=depth,
         content_json="{}",
         unrecognized_keys="{}",
diff --git a/tests/utils.py b/tests/utils.py
index bb8e9964dd..60fd6085ac 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -76,6 +76,13 @@ class MockHttpResource(HttpServer):
         mock_content.configure_mock(**config)
         mock_request.content = mock_content
 
+        mock_request.method = http_method
+        mock_request.uri = path
+
+        mock_request.requestHeaders.getRawHeaders.return_value=[
+            "X-Matrix origin=test,key=,sig="
+        ]
+
         # return the right path if the event requires it
         mock_request.path = path
 
@@ -108,6 +115,21 @@ class MockHttpResource(HttpServer):
         self.callbacks.append((method, path_pattern, callback))
 
 
+class MockKey(object):
+    alg = "mock_alg"
+    version = "mock_version"
+
+    @property
+    def verify_key(self):
+        return self
+
+    def sign(self, message):
+        return b"\x9a\x87$"
+
+    def verify(self, message, sig):
+        assert sig == b"\x9a\x87$"
+
+
 class MockClock(object):
     now = 1000
 
@@ -167,7 +189,11 @@ class MemoryDataStore(object):
 
     def get_user_by_token(self, token):
         try:
-            return self.tokens_to_users[token]
+            return {
+                "name": self.tokens_to_users[token],
+                "admin": 0,
+                "device_id": None,
+            }
         except:
             raise StoreError(400, "User does not exist.")
 
@@ -264,6 +290,9 @@ class MemoryDataStore(object):
     def get_ops_levels(self, room_id):
         return defer.succeed((5, 5, 5))
 
+    def insert_client_ip(self, user, device_id, access_token, ip, user_agent):
+        return defer.succeed(None)
+
 
 def _format_call(args, kwargs):
     return ", ".join(