mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-24 10:35:46 +03:00
Add unit tests
This commit is contained in:
parent
2df75cec69
commit
212d4abeab
2 changed files with 40 additions and 6 deletions
|
@ -99,12 +99,12 @@ class ApplicationServicesHandler(object):
|
|||
ev_domain = get_domain_from_id(event.sender)
|
||||
if any(srv_re.match(ev_domain) is not None
|
||||
for srv_re in self.server_blacklist):
|
||||
logger.info(
|
||||
"Ignoring %s from %s, matches server blacklist",
|
||||
event.sender,
|
||||
ev_domain
|
||||
)
|
||||
return
|
||||
logger.info(
|
||||
"Ignoring %s from %s, matches server blacklist",
|
||||
event.sender,
|
||||
ev_domain
|
||||
)
|
||||
return
|
||||
# Gather interested services
|
||||
services = yield self._get_services_for_event(event)
|
||||
if len(services) == 0:
|
||||
|
|
|
@ -20,6 +20,7 @@ from tests.utils import MockClock
|
|||
from synapse.handlers.appservice import ApplicationServicesHandler
|
||||
|
||||
from mock import Mock
|
||||
import re
|
||||
|
||||
|
||||
class AppServiceHandlerTestCase(unittest.TestCase):
|
||||
|
@ -32,9 +33,14 @@ class AppServiceHandlerTestCase(unittest.TestCase):
|
|||
hs = Mock()
|
||||
hs.get_datastore = Mock(return_value=self.mock_store)
|
||||
self.mock_store.get_received_ts.return_value = 0
|
||||
self.mock_store.app_service_server_blacklist = []
|
||||
hs.get_application_service_api = Mock(return_value=self.mock_as_api)
|
||||
hs.get_application_service_scheduler = Mock(return_value=self.mock_scheduler)
|
||||
hs.get_clock.return_value = MockClock()
|
||||
hs.config.app_service_server_blacklist = [
|
||||
re.compile("evilplaceofevil"),
|
||||
re.compile("bad.placeof..*")
|
||||
]
|
||||
self.handler = ApplicationServicesHandler(hs)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
|
@ -64,6 +70,34 @@ class AppServiceHandlerTestCase(unittest.TestCase):
|
|||
interested_service, event
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_ignore_blacklisted_services(self):
|
||||
interested_service = self._mkservice(is_interested=True)
|
||||
services = [
|
||||
interested_service,
|
||||
]
|
||||
|
||||
self.mock_store.get_app_services = Mock(return_value=services)
|
||||
self.mock_store.get_user_by_id = Mock(return_value=[])
|
||||
|
||||
eventLiteral = Mock(
|
||||
sender="@someone:evilplaceofevil",
|
||||
type="m.room.message",
|
||||
room_id="!foo:bar"
|
||||
)
|
||||
eventMatched = Mock(
|
||||
sender="@someone:bad.placeof.bad",
|
||||
type="m.room.message",
|
||||
room_id="!foo:bar"
|
||||
)
|
||||
self.mock_store.get_new_events_for_appservice.side_effect = [
|
||||
(0, [eventLiteral]),
|
||||
(0, [eventMatched])
|
||||
]
|
||||
self.mock_as_api.push = Mock()
|
||||
yield self.handler.notify_interested_services(0)
|
||||
assert self.mock_scheduler.submit_event_for_as.called is False
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_query_user_exists_unknown_user(self):
|
||||
user_id = "@someone:anywhere"
|
||||
|
|
Loading…
Reference in a new issue