Add unknown user ID check. Use store.get_aliases_for_room(room_id) when searching for services by alias.

pull/50/head
Kegan Dougal 2015-02-05 11:25:32 +00:00
parent 27091f146a
commit f0c730252f
2 changed files with 20 additions and 5 deletions

View File

@ -15,10 +15,10 @@
from twisted.internet import defer from twisted.internet import defer
from ._base import BaseHandler
from synapse.api.errors import Codes, StoreError, SynapseError from synapse.api.errors import Codes, StoreError, SynapseError
from synapse.appservice import ApplicationService from synapse.appservice import ApplicationService
from synapse.appservice.api import ApplicationServiceApi from synapse.appservice.api import ApplicationServiceApi
from synapse.types import UserID
import synapse.util.stringutils as stringutils import synapse.util.stringutils as stringutils
import logging import logging
@ -74,7 +74,7 @@ class ApplicationServicesHandler(object):
event based on the service regex. event based on the service regex.
""" """
# We need to know the aliases associated with this event.room_id, if any # We need to know the aliases associated with this event.room_id, if any
alias_list = [] # TODO alias_list = yield self.store.get_aliases_for_room(event.room_id)
services = yield self.store.get_app_services() services = yield self.store.get_app_services()
interested_list = [ interested_list = [
s for s in services if ( s for s in services if (
@ -100,7 +100,7 @@ class ApplicationServicesHandler(object):
# Do we know this user exists? If not, poke the user query API for # Do we know this user exists? If not, poke the user query API for
# all services which match that user regex. # all services which match that user regex.
unknown_user = False # TODO check unknown_user = yield self._is_unknown_user(event.sender)
if unknown_user: if unknown_user:
user_query_services = yield self.get_services_for_event( user_query_services = yield self.get_services_for_event(
event=event, event=event,
@ -117,7 +117,7 @@ class ApplicationServicesHandler(object):
# Do we know this room alias exists? If not, poke the room alias query # Do we know this room alias exists? If not, poke the room alias query
# API for all services which match that room alias regex. # API for all services which match that room alias regex.
unknown_room_alias = False # TODO check unknown_room_alias = False # TODO
if unknown_room_alias: if unknown_room_alias:
alias = "something" # TODO alias = "something" # TODO
alias_query_services = yield self.get_services_for_event( alias_query_services = yield self.get_services_for_event(
@ -137,5 +137,19 @@ class ApplicationServicesHandler(object):
for service in services: for service in services:
self.appservice_api.push(service, event) self.appservice_api.push(service, event)
@defer.inlineCallbacks
def _is_unknown_user(self, user_id):
user = UserID.from_string(user_id)
if not self.hs.is_mine(user):
# we don't know if they are unknown or not since it isn't one of our
# users. We can't poke ASes.
defer.returnValue(False)
return
user_info = yield self.store.get_user_by_id(user_id)
defer.returnValue(len(user_info) == 0)
def _generate_hs_token(self): def _generate_hs_token(self):
return stringutils.random_string(18) return stringutils.random_string(24)

View File

@ -46,6 +46,7 @@ class AppServiceHandlerTestCase(unittest.TestCase):
] ]
self.mock_store.get_app_services = Mock(return_value=services) self.mock_store.get_app_services = Mock(return_value=services)
self.mock_store.get_user_by_id = Mock(return_value=[])
event = Mock( event = Mock(
sender="@someone:anywhere", sender="@someone:anywhere",